-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle.yml
More file actions
127 lines (120 loc) · 4.55 KB
/
circle.yml
File metadata and controls
127 lines (120 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# This configuration was automatically generated from a CircleCI 1.0 config.
# It should include any build commands you had along with commands that CircleCI
# inferred from your project structure. We strongly recommend you read all the
# comments in this file to understand the structure of CircleCI 2.0, as the idiom
# for configuration has changed substantially in 2.0 to allow arbitrary jobs rather
# than the prescribed lifecycle of 1.0. In general, we recommend using this generated
# configuration as a reference rather than using it in production, though in most
# cases it should duplicate the execution of your original 1.0 config.
version: 2.1
workflows:
build_deploy:
jobs:
- build
- deploy:
requires:
- build
context:
- gcloud-<< pipeline.git.branch >>
filters:
branches:
only:
- master
- staging
- dev
orbs:
node: circleci/node@5.0.0
jq: circleci/jq@2.2.0
jobs:
build:
working_directory: ~/API-market/crypto-service/src
parallelism: 1
shell: /bin/bash --login -e
environment:
MONGO_URL: mongodb://localhost:27017/data
GCLOUD_PROJECT: cryptoservice
SERVICE_VERSION: 1
# In CircleCI 2.0 you can now specify your own image, or use one of our pre-configured images.
# To see the list of pre-built images that CircleCI provides for most common languages see
# https://circleci.com/docs/2.0/circleci-images/
docker:
- image: cimg/base:stable-18.04
- image: circleci/mongo:4.2.8
steps:
# Machine Setup
- checkout:
path: ".."
- node/install:
node-version: '12.12.0'
# install npm dependencies and run build script
- node/install-packages:
override-ci-command: npm install
# Linter
- run: npm run lint
# Unit Tests
- run: npm test
- persist_to_workspace:
root: ~/API-market
paths:
- crypto-service
deploy:
working_directory: ~/API-market/crypto-service/src
parallelism: 1
shell: /bin/bash --login -e
docker:
- image: google/cloud-sdk:363.0.0
steps:
- attach_workspace:
at: ~/API-market
- node/install:
node-version: '12.12.0'
- jq/install
# install gcloud and login to it
- run:
working_directory: ~/
command: |
echo $GCLOUD_SERVICE_ACCT_KEY | base64 --decode > ${HOME}/gcloud-service-key.json
gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json
gcloud config set project $GOOGLE_PROJECT_ID
gcloud config set app/cloud_build_timeout 2100
- run:
command: |
# use new variable to map master -> prod
DEPLOY_ENV=$CIRCLE_BRANCH
if [ "$CIRCLE_BRANCH" == "master" ]; then
DEPLOY_ENV=prod
fi
cp -rf ../scripts/config/${DEPLOY_ENV}.app.yaml ./app.yaml
# process env_version.json
SECRET_VERSION=`cat env_version.json | jq -r ".${DEPLOY_ENV}.version"`
ENV_VERSION=`cat env_version.json | jq -r '.envVersion'`
# pull this from GCP
gcloud secrets versions access ${SECRET_VERSION} \
--secret="$SECRET_NAME_CRYPTO_SERVICE" \
--format='get(payload.data)' | tr '_-' '/+' | base64 -d > .env
echo "Pulled down secret into .env"
# disable fail on error to output meaningful message
set +e
# grep ENV_VERSION is in env. This will fail if the incorrect version is not in the .env file
CHECK_ENV=`grep $ENV_VERSION .env`
if [ "$?" == "1" ]; then
echo ".env SCHEMA does not match: ${ENV_VERSION} not found in version: ${SECRET_VERSION}";
exit 1;
fi
# create deploy_version file
- run:
command: |
ENV_HASH=$(sha1sum ./.env | awk '{print $1}')
echo ENV_HASH = "\"$ENV_HASH\"" >> ./deploy-version
echo BUILD_VERSION = "\"$CIRCLE_BUILD_NUM\"" >> ./deploy-version
CURRENTDATE=`date +"%A, %b %d, %Y %I:%M %p"`
echo DEPLOY_DATE = "\"$CURRENTDATE\"" >> ./deploy-version
# build
- run: npm run build
# deploy to Google Cloud
- run:
no_output_timeout: 15m # timeout the build if the deploy hangs for longer than 15 minutes
command: |
rm -rf ./node_modules
# deploy to AppEngine
../scripts/deploy.sh