Skip to content

Commit

Permalink
Merge pull request #72 from Mahboobeh-binary/new-release-infra
Browse files Browse the repository at this point in the history
add new release infra
  • Loading branch information
sysadmin-frontend-binary authored Jul 16, 2020
2 parents fb0defd + 1ede1ba commit 9e33040
Showing 1 changed file with 58 additions and 98 deletions.
156 changes: 58 additions & 98 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1
orbs:
k8s: circleci/[email protected]
s3: circleci/[email protected]
slack: circleci/[email protected]
commands:
git_checkout_from_cache:
description: "Git checkout and save cache"
Expand Down Expand Up @@ -29,7 +29,7 @@ commands:
key: source-v1-{{ .Branch }}-{{ .Revision }}
paths:
- ".git"
npm_install_from_cache:
npm_install:
description: "npm install and save cache"
steps:
- restore_cache:
Expand All @@ -43,13 +43,13 @@ commands:
key: node-{{ checksum "package-lock.json" }}
paths:
- "node_modules"
npm_test:
test:
description: "Run npm test"
steps:
- run:
name: "Run test"
command: npm test
grunt_release:
build:
description: "Build for release target"
parameters:
target:
Expand All @@ -59,38 +59,31 @@ commands:
- run:
name: Building dist for << parameters.target >>
command: node_modules/grunt/bin/grunt releaseci --<< parameters.target >>
compress:
description: "Compress"
deploy:
description: "Deploy to static branches"
parameters:
target_branch:
type: string
steps:
- checkout
- attach_workspace:
at: dist
- run:
name: Tag build
command: echo "<< parameters.target_branch >> $(date -u +'%Y-%m-%dT%H:%M:%SZ')" > dist/version
- run:
name: "Compress"
name: Install and configure dependencies
command: |
pushd dist/
tar -cvf artifact.tar *
mv artifact.tar ${OLDPWD}/
sudo npm install -g [email protected]
git config user.email "[email protected]"
git config user.name "ci-build"
- add_ssh_keys:
fingerprints:
- "01:67:4a:6d:26:9c:70:c4:1a:60:91:88:d9:dd:f0:83"
- run:
name: "Tag commit id as artifact identifer"
command: echo "${CIRCLE_TAG}" > artifact-info.txt
upload_artifact:
description: "upload build artifact to s3 bucket"
steps:
- s3/copy:
from: artifact.tar
to: 's3://${CONTEXT_ARTIFACT_S3_BUCKET}/deriv-${CIRCLE_PROJECT_REPONAME}/'
aws-access-key-id: env_CONTEXT_ARTIFACT_S3_AWS_ACCESS_KEY_ID
aws-secret-access-key: env_CONTEXT_ARTIFACT_S3_AWS_SECRET_ACCESS_KEY
aws-region: env_CONTEXT_ARTIFACT_S3_AWS_REGION
arguments: '--metadata "{\"x-amz-artifact-id\": \"${CIRCLE_TAG}\" }"'
upload_checksum:
description: "upload artifact checksum to s3"
steps:
- s3/copy:
from: artifact-info.txt
to: 's3://${CONTEXT_ARTIFACT_S3_BUCKET}/deriv-${CIRCLE_PROJECT_REPONAME}/'
aws-access-key-id: env_CONTEXT_ARTIFACT_S3_AWS_ACCESS_KEY_ID
aws-secret-access-key: env_CONTEXT_ARTIFACT_S3_AWS_SECRET_ACCESS_KEY
aws-region: env_CONTEXT_ARTIFACT_S3_AWS_REGION
docker_build:
name: Deploy docs to gh-pages branch
command: gh-pages -d dist --branch << parameters.target_branch >> --message '[skip ci]'
docker_build_push:
description: "Build Docker image"
steps:
- setup_remote_docker
Expand All @@ -99,9 +92,6 @@ commands:
command: |
TAG=${CIRCLE_TAG:-$CIRCLE_SHA1}
docker build -t ${DOCKHUB_ORGANISATION}/smarttrader-deriv-app:${TAG} -t ${DOCKHUB_ORGANISATION}/smarttrader-deriv-app:latest .
docker_push:
description: "Push image to docker hub"
steps:
- run:
name: Pushing Image to docker hub
command: |
Expand Down Expand Up @@ -133,96 +123,66 @@ commands:
kubectl --server=${KUBE_SERVER} --certificate-authority=ca.crt --token=$SERVICEACCOUNT_TOKEN set image deployment/<< parameters.k8s_svc_name >> << parameters.k8s_svc_name >>=${DOCKHUB_ORGANISATION}/smarttrader-deriv-app:${CIRCLE_TAG}
fi
done
notify_slack:
description: "Notify slack"
steps:
- slack/status:
include_project_field: false
failure_message: "Release failed for smarttrader.deriv.com with version *$(cat dist/version)*"
success_message: "Release succeeded for smarttrader.deriv.com with version *$(cat dist/version)*"
webhook: ${SLACK_WEBHOOK}
jobs:
test:
docker:
- image: circleci/node:9.8.0-stretch
steps:
- git_checkout_from_cache
- npm_install_from_cache
- npm_test

build_push_staging:
- npm_install
- test
release_beta:
docker:
- image: circleci/node:9.8.0-stretch
steps:
- git_checkout_from_cache
- npm_install_from_cache
- grunt_release:
- npm_install
- test
- build:
target: 'staging'
- grunt_release:
- build:
target: 'translations'
- docker_build
- docker_push

build_push_production:
- deploy:
target_branch: "staging"
- notify_slack
release_production:
docker:
- image: circleci/node:9.8.0-stretch
steps:
- git_checkout_from_cache
- npm_install_from_cache
- grunt_release:
- npm_install
- test
- build:
target: 'production'
- compress
- upload_artifact # uploading the built code to s3 to create a backup of key services separate from Kubernetes deployment
- upload_checksum # uploading compressed artifact checksum to cross match artifact fingerprint
- docker_build
- docker_push

deploy_staging:
docker:
- image: circleci/node:9.8.0-stretch
steps:
- k8s_deploy

deploy_production:
docker:
- image: circleci/node:9.8.0-stretch
steps:
- deploy:
target_branch: "production"
- docker_build_push
- k8s_deploy:
k8s_svc_name: "production-smarttrader-deriv-app"
- notify_slack

workflows:
build_and_push_master:
test:
jobs:
- test
- build_push_staging:
context: deriv-app-artifact-upload
- test:
filters:
branches:
only: /^master/
tagged_release_staging:
ignore: /^master$/
release:
jobs:
- build_push_staging:
context: deriv-app-artifact-upload
filters:
branches:
ignore: /.*/
tags:
only: /^staging.*/
- deploy_staging:
context: deriv-app-artifact-upload
requires:
- build_push_staging
- release_beta:
filters:
branches:
ignore: /.*/
tags:
only: /^staging.*/
tagged_release_production:
jobs:
- build_push_production:
context: deriv-app-artifact-upload
filters:
branches:
ignore: /.*/
tags:
only: /^production.*/
- deploy_production:
context: deriv-app-artifact-upload
requires:
- build_push_production
only: /^master$/
- release_production:
filters:
branches:
ignore: /.*/
Expand Down

0 comments on commit 9e33040

Please sign in to comment.