Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 178 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
version: 2.1
orbs:
k8s: circleci/kubernetes@0.7.0
commands:
git_checkout_from_cache:
description: "Git checkout and save cache"
steps:
- restore_cache:
name: Git restore cache
keys:
- source-v1-{{ .Branch }}-{{ .Revision }}
- source-v1-{{ .Branch }}-
- source-v1-
- run:
name: Fetch git tags
command: |
mkdir -p ~/.ssh
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== ' >> ~/.ssh/known_hosts
# Fetch tags if git cache is present
if [ -e /home/circleci/project/.git ]
then
git fetch origin --tags
fi
- checkout
- run:
name: Compress git objects
command: git gc
- save_cache:
name: Git save cache
key: source-v1-{{ .Branch }}-{{ .Revision }}
paths:
- ".git"
npm_install:
description: "Install npm modules"
steps:
- restore_cache:
name: Restore npm cache
keys:
- npm-v1-{{ checksum "package.json" }}
- npm-v1-
- run:
name: Install npm modules
command: npm install && ./node_modules/.bin/bower install
- save_cache:
name: Save NPM cache
key: npm-v1-{{ checksum "package.json" }}
paths:
- "node_modules"
build:
description: "Build"
steps:
- run:
name: "gulp build"
command: npx gulp build
deploy:
description: "Deploy to static branches"
parameters:
target_branch:
type: string
steps:
- checkout
- attach_workspace:
at: www
- run:
name: Tag build
command: echo "<< parameters.target_branch >> $(date)" > www/version
- run:
name: Install and configure dependencies
command: |
sudo npm install -g gh-pages@2.0.1
git config user.email "mahboub.meng@gmail.com"
git config user.name "mahboobeh-binary"
- add_ssh_keys:
fingerprints:
- "c1:1d:89:74:e5:aa:8f:1b:19:43:e3:b5:2d:48:78:94"
- run:
name: Deploy docs to gh-pages branch
command: gh-pages -d www --branch << parameters.target_branch >>
docker_build_push:
description: "Build and Push image to docker hub"
steps:
- setup_remote_docker
- run:
name: Building docker image for production
command: |
docker build -t ${DOCKHUB_ORGANISATION}/ticktrade-mobile:${CIRCLE_SHA1} -t ${DOCKHUB_ORGANISATION}/ticktrade-mobile:latest .
- run:
name: Pushing Image to docker hub
command: |
echo $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_USERNAME --password-stdin
docker push ${DOCKHUB_ORGANISATION}/ticktrade-mobile
k8s_deploy:
description: "Deploy to k8s cluster"
steps:
- k8s/install-kubectl
- run:
name: Deploying to k8s cluster for service ticktrade-binary-com
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/ticktrade-binary-com ticktrade-binary-com=${DOCKHUB_ORGANISATION}/ticktrade-mobile:${CIRCLE_SHA1}
fi
done

jobs:
test:
docker:
- image: circleci/node:11.15.0
steps:
- git_checkout_from_cache
- npm_install
- build
release_beta:
docker:
- image: circleci/node:8.10.0-stretch
steps:
- git_checkout_from_cache
- npm_install
- build
- deploy:
target_branch: "staging"

release_production:
docker:
- image: circleci/node:8.10.0-stretch
steps:
- git_checkout_from_cache
- npm_install
- build
- deploy:
target_branch: "production"

release_aws_production:
docker:
- image: circleci/nide:11.15.0
steps:
- git_checkout_from_cache
- npm_install
- build
- docker_build_push
- k8s_deploy

workflows:
test:
jobs:
- test:
filters:
branches:
ignore: /^master$/
release:
jobs:
- release_beta:
filters:
branches:
only: /^master$/
- release_production:
filters:
branches:
ignore: /.*/
tags:
only: /^production.*/
- release_aws_production:
filters:
branches:
ignore: /.*/
tags:
only: /^aws\-production.*/
context: binary-frontend-artifact-upload