From 44d97fe91df01a8a8bf217f5f2092d7a9c60d8d4 Mon Sep 17 00:00:00 2001 From: Afshin Paydar Date: Thu, 24 Jun 2021 08:15:37 +0800 Subject: [PATCH] Remove old release and use Blue/Green as default Switch to blue/green deployment as a default release strategy Use same Dockerfile pattern for staging and production Signed-off-by: Afshin Paydar --- .circleci/config.yml | 58 ++++++++++++++++---------------------------- Dockerfile | 5 ++-- 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index df1eedeb97..bc57e0c0ae 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -80,21 +80,18 @@ commands: docker_build_push: description: "Build and Push image to docker hub" parameters: - docker_tag: + docker_image_latest_tag: type: string - default: "beta-${CIRCLE_SHA1}" - docker_latest_tag: + default: "latest-staging" + docker_image_tag: type: string - default: "beta-latest" - nginx_location: - type: string - default: "/usr/share/nginx/html/beta" + default: ${CIRCLE_SHA1} steps: - setup_remote_docker - run: name: Building docker image command: | - docker build --build-arg NGINX_LOCATION=<< parameters.nginx_location >> -t ${DOCKHUB_ORGANISATION}/binary-static-webtrader:<< parameters.docker_tag >> -t ${DOCKHUB_ORGANISATION}/binary-static-webtrader:<< parameters.docker_latest_tag >> . + docker build -t ${DOCKHUB_ORGANISATION}/binary-static-webtrader:<< parameters.docker_image_tag >> -t ${DOCKHUB_ORGANISATION}/binary-static-webtrader:<< parameters.docker_image_latest_tag >> . - run: name: Pushing Image to docker hub command: | @@ -103,35 +100,22 @@ commands: k8s_deploy: description: "Deploy to k8s cluster" parameters: - k8s_svc_name: - type: string - default: "webtrader-beta-binary-com" - docker_tag: + k8s_version: type: string - default: "beta-${CIRCLE_SHA1}" - k8s-deployment: + default: ${CIRCLE_SHA1} + k8s_namespace: type: string - default: "webtrader-beta-binary-com" + default: "webtrader-binary-com-staging" steps: - k8s/install-kubectl - run: - name: Deploying to k8s cluster for service << parameters.k8s_svc_name >> + name: Deploying to k8s cluster for service << parameters.k8s_namespace >> command: | - for SERVER_ID in {1..5} - do - KUBE_SERVER_REF="KUBE_SERVER_$SERVER_ID" - SERVICEACCOUNT_TOKEN_REF="SERVICEACCOUNT_TOKEN_$SERVER_ID" - CA_CRT_REF="CA_CRT_$SERVER_ID" - if [ ! -z "${!KUBE_SERVER_REF}" ] - then - echo "Deploying to cluster $SERVER_ID" - CA_CRT="${!CA_CRT_REF}" - KUBE_SERVER="${!KUBE_SERVER_REF}" - SERVICEACCOUNT_TOKEN="${!SERVICEACCOUNT_TOKEN_REF}" - echo $CA_CRT | base64 --decode > ca.crt - kubectl --server=${KUBE_SERVER} --certificate-authority=ca.crt --token=$SERVICEACCOUNT_TOKEN set image deployment/<< parameters.k8s-deployment >> << parameters.k8s-deployment >>=${DOCKHUB_ORGANISATION}/binary-static-webtrader:<< parameters.docker_tag >> - fi - done + export NAMESPACE=<< parameters.k8s_namespace >> + git clone https://github.com/binary-com/devops-ci-scripts + cd devops-ci-scripts/k8s-build_tools + echo $CA_CRT | base64 --decode > ca.crt + ./release.sh binary-static-webtrader << parameters.k8s_version >> notify_slack: description: "Notify slack" steps: @@ -157,6 +141,8 @@ jobs: - build - deploy: target_branch: "staging" + - docker_build_push + - k8s_deploy - notify_slack release_production: docker: @@ -176,13 +162,11 @@ jobs: - npm_install - build - docker_build_push: - docker_latest_tag: "latest" - docker_tag: "${CIRCLE_SHA1}" - nginx_location: "/usr/share/nginx/html" + docker_image_latest_tag: "latest" + docker_image_tag: ${CIRCLE_TAG} - k8s_deploy: - k8s_svc_name: "webtrader-binary-com" - docker_tag: "${CIRCLE_SHA1}" - k8s-deployment: "webtrader-binary-com" + k8s_namespace: "webtrader-binary-com-production" + k8s_version: ${CIRCLE_TAG} workflows: build: diff --git a/Dockerfile b/Dockerfile index 6d049c4c4f..e1f1f94e37 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -ARG NGINX_LOCATION=/usr/share/nginx/html/beta FROM nginx:alpine -ARG NGINX_LOCATION -COPY ./dist/compressed $NGINX_LOCATION +COPY ./dist/compressed /usr/share/nginx/html COPY ./default.conf /etc/nginx/conf.d/default.conf +RUN chown -R nginx:nginx /usr/share/nginx/html