From cd298e4a27b97f5a13d3cc739300f5a4fdcf48bc Mon Sep 17 00:00:00 2001 From: kleph Date: Mon, 2 Mar 2020 23:08:26 +0100 Subject: [PATCH 1/3] [ci] refacto --- .drone.yml | 55 ++++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/.drone.yml b/.drone.yml index 617882e..375bd5c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -58,11 +58,26 @@ depends_on: - unit tests --- +deploy_commands_alias: +- &deploy_commands + commands: + - echo "== pre deploy ($${LEVEL}) status:" + - kubectl get pods --namespace=beer + - kubectl get deployments --namespace=beer + - sed "s/__LEVEL__/$${LEVEL}/g" kube/beer-deployment.yaml > kube/beer-deployment-$${LEVEL}.yaml + - sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-deployment-$${LEVEL}.yaml > kube/beer-deployment-$${NAMESPACE}-$${LEVEL}.yaml + - sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment-$${NAMESPACE}-$${LEVEL}.yaml > kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml + - echo "applying" + - kubectl apply -f kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml --namespace=beer + - echo "== post deploy ($${LEVEL}) status:" + - kubectl get deployments --namespace=beer + - kubectl get pods --namespace=beer + kind: pipeline -name: staging +name: deploy steps: -- name: deploy +- name: deploy staging image: sinlead/drone-kubectl settings: kubernetes_server: @@ -75,32 +90,13 @@ steps: IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} NAMESPACE: beer LEVEL: staging - commands: - - echo "== pre deploy ($${LEVEL}) status:" - - kubectl get pods --namespace=beer - - kubectl get deployments --namespace=beer - - sed "s/__LEVEL__/$${LEVEL}/g" kube/beer-deployment.yaml > kube/beer-deployment-$${LEVEL}.yaml - - sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-deployment-$${LEVEL}.yaml > kube/beer-deployment-$${NAMESPACE}-$${LEVEL}.yaml - - sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment-$${NAMESPACE}-$${LEVEL}.yaml > kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml - - echo "applying" - - kubectl apply -f kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml --namespace=beer - - echo "== post deploy ($${LEVEL}) status:" - - kubectl get deployments --namespace=beer - - kubectl get pods --namespace=beer + <<: *deploy_commands when: branch: exclude: - master -depends_on: -- build - ---- -kind: pipeline -name: deploy - -steps: -- name: deploy +- name: deploy live image: sinlead/drone-kubectl settings: kubernetes_server: @@ -113,18 +109,7 @@ steps: IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} NAMESPACE: beer LEVEL: prod - commands: - - echo "== pre deploy ($${LEVEL}) status:" - - kubectl get pods --namespace=beer - - kubectl get deployments --namespace=beer - - sed "s/__LEVEL__/$${LEVEL}/g" kube/beer-deployment.yaml > kube/beer-deployment-$${LEVEL}.yaml - - sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-deployment-$${LEVEL}.yaml > kube/beer-deployment-$${NAMESPACE}-$${LEVEL}.yaml - - sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment-$${NAMESPACE}-$${LEVEL}.yaml > kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml - - echo "applying" - - kubectl apply -f kube/beer-deployment-$${NAMESPACE}-$${LEVEL}2.yaml --namespace=beer - - echo "== post deploy ($${LEVEL}) status:" - - kubectl get deployments --namespace=beer - - kubectl get pods --namespace=beer + <<: *deploy_commands when: branch: include: From 2b31bce170d19d738620397a032418b86960f75e Mon Sep 17 00:00:00 2001 From: kleph Date: Mon, 2 Mar 2020 23:28:42 +0100 Subject: [PATCH 2/3] cleanup --- .drone.yml | 2 +- kube/kubeconfig_template.yaml | 20 -------------------- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 kube/kubeconfig_template.yaml diff --git a/.drone.yml b/.drone.yml index 375bd5c..70944ea 100644 --- a/.drone.yml +++ b/.drone.yml @@ -108,7 +108,7 @@ steps: environment: IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} NAMESPACE: beer - LEVEL: prod + LEVEL: live <<: *deploy_commands when: branch: diff --git a/kube/kubeconfig_template.yaml b/kube/kubeconfig_template.yaml deleted file mode 100644 index 0832edf..0000000 --- a/kube/kubeconfig_template.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -apiVersion: v1 -clusters: -- cluster: - certificate-authority-data: ${KUBE_CA} - server: ${KUBE_URI} - name: default -contexts: -- context: - cluster: default - user: default - name: default -current-context: default -kind: Config -preferences: {} -users: -- name: default - user: - password: ${KUBE_PASSWORD} - username: ${KUBE_USERNAME} From a5fbeea615e4103206eab8a5b83b88ad4e6c0c13 Mon Sep 17 00:00:00 2001 From: kleph Date: Tue, 3 Mar 2020 00:07:47 +0100 Subject: [PATCH 3/3] [CI] Add sample staging tests --- .drone.yml | 7 +++++++ staging_tests.sh | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 staging_tests.sh diff --git a/.drone.yml b/.drone.yml index 70944ea..d7a1972 100644 --- a/.drone.yml +++ b/.drone.yml @@ -96,6 +96,13 @@ steps: exclude: - master +- name: test staging + image: ellerbrock/alpine-bash-curl-ssl + environment: + BRANCH: ${DRONE_COMMIT_BRANCH} + commands: + - bash staging_tests.sh + - name: deploy live image: sinlead/drone-kubectl settings: diff --git a/staging_tests.sh b/staging_tests.sh new file mode 100644 index 0000000..7bc1707 --- /dev/null +++ b/staging_tests.sh @@ -0,0 +1,23 @@ +if [ ${BRANCH} == 'master' ]; then + TEST_URL='http://beer.k3s.kleph.eu' +else + TEST_URL='http://staging.beer.k3s.kleph.eu' +fi +echo "testing URL: ${TEST_URL}" +CURL_OPTS='-s' +# default +curl ${CURL_OPTS} ${TEST_URL} | grep -q 'setHours( 17, 0);' +[ $? -ne 0 ] && exit 1 + +# set 1 parameter +hours=18 +curl ${CURL_OPTS} ${TEST_URL}/${hours} | grep -q "setHours( ${hours}, 0);" +[ $? -ne 0 ] && exit 1 + +# set 2 parameters +minutes=30 +curl ${CURL_OPTS} ${TEST_URL}/${hours}/${minutes} | grep -q "setHours( ${hours}, ${minutes});" +[ $? -ne 0 ] && exit 1 + +echo "OK" +exit 0