Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 910e4a4

Browse files
afshin-paydarashkanxoskar-binary4p00rvmustofa-binary
authored
Refactor circleci config (#1526)
* Revert "V20191104_0" * Revert "Revert "V20191104_0"" * move build to circleci (#1505) * move build to circleci * fix circleci config * change base image to node * try node 12.13.0 image * try circleci node image * update build command * update docker image name * rm travi * edit: disabled docker build and k8s deploy * edit: testing artifact storing configuration * edit: edited project build command * edit: edited artifact path * using artifact path as compressed static content * edit: added artifact compression step * edit: added artifact moving step * edit: edited artifact name and desitnation configuration * add: added artifact upload to s3 step * edit: added circle ci project name in s3 upload url * test: testing environment variable integration * testing circle ci variable * edit: edited orb alias and removed unwanted artifact configuration * add: added commit-id/checksum as an added information regarding artficat * edit: testing circle ci config with singel step artifact upload * fix: fix s3 copy error in pipeline script * disabled checksum calculation and enabled commit id as artifact id * edit: enabled commit id upload as a jobs step * edit: uploading checksum instead of commit id * add: add cron script for deployment * changed access settings in aws * edit: enabled all job steps to execute * remove: removed unnecesary deployment script * edit: using circle ci context variable instead of project based envvariables * test: testing s3 upload with metadata integration * test: testing s3 orb metadata * test: testing circleci orb metadata integration * test: testing circleci orb metadata integration * test: testing bash variable integration with s3 orb metadata * test: using BASH_ENV to retrieve bash environment value in pipeline * test: using to retrieve bash environment value in pipeline * test: testing with commit id as artifact id * add: tagging commit id as artifact identifier * edit: edited context name * Added .gitlab-ci.yml to exception in gh-pages clean script * Add docker image to release with latest tag * revert: Gitlab CI config exception in `clean` * multi cluster release (#1520) Co-authored-by: Mahboobeh <mahboobeh@Mahboobehs-MacBook-Pro.local> * add missing context (#1523) * refactor_circleci_config * refactor_circleci_config * refactor_circleci_config * fix build error * refactor_circleci_config * refactor_circleci_config * refactor_circleci_config * refactor_circleci_config#1 * refactor_circleci_config#2 * refactor_circleci_config#3 * refactor_circleci_config#4 * refactor_circleci_config#5 * refactor_circleci_config#6 * refactor_circleci_config#7 * refactor_circleci_config#8 * refactor_circleci_config * refactor_circleci_config * dynamic nginx location * remove test workflow * change npm install to watch package-lock.json * change cache key checksum * fix mistakenly k8s deployment Co-authored-by: Ashkan <ashkanx@users.noreply.github.com> Co-authored-by: oskar-binary <53067656+oskar-binary@users.noreply.github.com> Co-authored-by: Apoorv Joshi <apoorv@binary.com> Co-authored-by: mustofa binary <mustofa@regentmarkets.com> Co-authored-by: shudarshon <shudarshon@binary.com> Co-authored-by: Mahdi <m.pourziaei@gmail.com> Co-authored-by: Mahdi Pourziaei <mahdi.pourziaei@regentmarkets.com> Co-authored-by: mahboobeh <mahboob_mohamadi@hotmail.com> Co-authored-by: Mahboobeh <mahboobeh@Mahboobehs-MacBook-Pro.local>
1 parent 9dbfb89 commit 910e4a4

File tree

2 files changed

+121
-28
lines changed

2 files changed

+121
-28
lines changed

.circleci/config.yml

Lines changed: 118 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: 2.1
22
orbs:
33
k8s: circleci/kubernetes@0.7.0
4+
s3: circleci/aws-s3@1.0.13
45
commands:
56
git_checkout_from_cache:
67
description: "Git checkout and save cache"
@@ -11,8 +12,8 @@ commands:
1112
- source-v1-{{ .Branch }}-{{ .Revision }}
1213
- source-v1-{{ .Branch }}-
1314
- source-v1-
14-
- run:
15-
name: Fetch git tags
15+
- run:
16+
name: Fetch git tags
1617
command: |
1718
mkdir -p ~/.ssh
1819
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== ' >> ~/.ssh/known_hosts
@@ -23,7 +24,7 @@ commands:
2324
fi
2425
- checkout
2526
- run:
26-
name: Compress git objects
27+
name: Compress git objects
2728
command: git gc
2829
- save_cache:
2930
name: Git save cache
@@ -37,64 +38,154 @@ commands:
3738
- restore_cache:
3839
name: Restore npm cache
3940
keys:
40-
- npm-v1-{{ checksum "package.json" }}
41+
- npm-v1-{{ checksum "package-lock.json" }}
4142
- npm-v1-
4243
- run:
4344
name: Install npm modules
44-
command: npm install
45+
command: npm ci
4546
- save_cache:
4647
name: Save NPM cache
47-
key: npm-v1-{{ checksum "package.json" }}
48+
key: npm-v1-{{ checksum "package-lock.json" }}
4849
paths:
4950
- "node_modules"
5051

5152
build:
5253
description: "Build"
5354
steps:
5455
- run:
55-
name: "Grunt deploy"
56-
command: npm run deploy-ci
56+
name: "Compile project"
57+
command: npm run build
5758

58-
docker:
59+
compress:
60+
description: "Compress"
61+
steps:
62+
- run:
63+
name: "Compress"
64+
command: |
65+
pushd dist/compressed/
66+
tar -cvf artifact.tar *
67+
mv artifact.tar ${OLDPWD}/
68+
- run:
69+
name: "Tag commit id as artifact identifer"
70+
command: echo "${CIRCLE_SHA1}" > artifact-info.txt
71+
72+
upload_artifact:
73+
description: "upload build artifact to s3 bucket"
74+
steps:
75+
- s3/copy:
76+
from: artifact.tar
77+
to: 's3://${CONTEXT_ARTIFACT_S3_BUCKET}/${CIRCLE_PROJECT_REPONAME}/'
78+
aws-access-key-id: env_CONTEXT_ARTIFACT_S3_AWS_ACCESS_KEY_ID
79+
aws-secret-access-key: env_CONTEXT_ARTIFACT_S3_AWS_SECRET_ACCESS_KEY
80+
aws-region: env_CONTEXT_ARTIFACT_S3_AWS_REGION
81+
arguments: '--metadata "{\"x-amz-artifact-id\": \"${CIRCLE_SHA1}\" }"'
82+
83+
upload_checksum:
84+
description: "upload artifact checksum to s3"
85+
steps:
86+
- s3/copy:
87+
from: artifact-info.txt
88+
to: 's3://${CONTEXT_ARTIFACT_S3_BUCKET}/${CIRCLE_PROJECT_REPONAME}/'
89+
aws-access-key-id: env_CONTEXT_ARTIFACT_S3_AWS_ACCESS_KEY_ID
90+
aws-secret-access-key: env_CONTEXT_ARTIFACT_S3_AWS_SECRET_ACCESS_KEY
91+
aws-region: env_CONTEXT_ARTIFACT_S3_AWS_REGION
92+
93+
docker_build_push:
5994
description: "Build and Push image to docker hub"
95+
parameters:
96+
docker_tag:
97+
type: string
98+
default: "beta-${CIRCLE_SHA1}"
99+
docker_latest_tag:
100+
type: string
101+
default: "beta-latest"
102+
nginx_location:
103+
type: string
104+
default: "/usr/share/nginx/html/beta"
60105
steps:
61106
- setup_remote_docker
62-
- run:
107+
- run:
63108
name: Building docker image
64109
command: |
65-
docker build -t ${DOCKHUB_ORGANISATION}/binary-static-webtrader:beta-${CIRCLE_SHA1} .
66-
- run:
110+
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 >> .
111+
- run:
67112
name: Pushing Image to docker hub
68113
command: |
69114
echo $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_USERNAME --password-stdin
70-
docker push ${DOCKHUB_ORGANISATION}/binary-static-webtrader:beta-${CIRCLE_SHA1}
71-
115+
docker push ${DOCKHUB_ORGANISATION}/binary-static-webtrader
72116
k8s_deploy:
73117
description: "Deploy to k8s cluster"
118+
parameters:
119+
k8s_svc_name:
120+
type: string
121+
default: "webtrader-beta-binary-com"
122+
docker_tag:
123+
type: string
124+
default: "beta-${CIRCLE_SHA1}"
125+
k8s-deployment:
126+
type: string
127+
default: "webtrader-beta-binary-com"
74128
steps:
75129
- k8s/install-kubectl
76-
- run:
77-
name: Deploying to k8s cluster for service binary-webtrader
130+
- run:
131+
name: Deploying to k8s cluster for service << parameters.k8s_svc_name >>
78132
command: |
79-
echo $CA_CRT | base64 --decode > ca.crt
80-
kubectl --server=${KUBE_SERVER} --certificate-authority=ca.crt --token=$SERVICEACCOUNT_TOKEN set image deployment/webtrader-beta-binary-com webtrader-beta-binary-com=${DOCKHUB_ORGANISATION}/binary-static-webtrader:beta-${CIRCLE_SHA1}
81-
133+
for SERVER_ID in {1..5}
134+
do
135+
KUBE_SERVER_REF="KUBE_SERVER_$SERVER_ID"
136+
SERVICEACCOUNT_TOKEN_REF="SERVICEACCOUNT_TOKEN_$SERVER_ID"
137+
CA_CRT_REF="CA_CRT_$SERVER_ID"
138+
if [ ! -z "${!KUBE_SERVER_REF}" ]
139+
then
140+
echo "Deploying to cluster $SERVER_ID"
141+
CA_CRT="${!CA_CRT_REF}"
142+
KUBE_SERVER="${!KUBE_SERVER_REF}"
143+
SERVICEACCOUNT_TOKEN="${!SERVICEACCOUNT_TOKEN_REF}"
144+
echo $CA_CRT | base64 --decode > ca.crt
145+
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 >>
146+
fi
147+
done
82148
jobs:
83-
release:
149+
release_development:
84150
docker:
85151
- image: circleci/node:12.13.0-stretch
86152
steps:
87153
- git_checkout_from_cache
88154
- npm_install
89155
- build
90-
- docker
156+
- docker_build_push
91157
- k8s_deploy
92-
158+
release_production:
159+
docker:
160+
- image: circleci/node:12.13.0-stretch
161+
steps:
162+
- git_checkout_from_cache
163+
- npm_install
164+
- build
165+
- compress
166+
- upload_artifact # uploading the built code to s3 to create a backup of key services separate from Kubernetes deployment
167+
- upload_checksum # uploading compressed artifact checksum to cross match artifact fingerprint before actual deployment
168+
- docker_build_push:
169+
docker_latest_tag: "latest"
170+
docker_tag: "${CIRCLE_SHA1}"
171+
nginx_location: "/usr/share/nginx/html"
172+
- k8s_deploy:
173+
k8s_svc_name: "webtrader-binary-com"
174+
docker_tag: "${CIRCLE_SHA1}"
175+
k8s-deployment: "webtrader-binary-com"
176+
93177
workflows:
94-
release:
95-
jobs:
96-
- release:
178+
release_development:
179+
jobs:
180+
- release_development:
97181
filters:
98182
branches:
99-
only: /^development$/
100-
183+
only: /^development$/
184+
context: binary-frontend-artifact-upload
185+
release_production:
186+
jobs:
187+
- release_production:
188+
filters:
189+
branches:
190+
only: /^master$/
191+
context: binary-frontend-artifact-upload

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
ARG NGINX_LOCATION=/usr/share/nginx/html/beta
12
FROM nginx:alpine
2-
COPY ./dist/compressed /usr/share/nginx/html/beta
3+
ARG NGINX_LOCATION
4+
COPY ./dist/compressed $NGINX_LOCATION
35
COPY ./default.conf /etc/nginx/conf.d/default.conf

0 commit comments

Comments
 (0)