-
Notifications
You must be signed in to change notification settings - Fork 0
/
reference.yml
425 lines (393 loc) · 12.6 KB
/
reference.yml
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
version: 2.1
executors:
gg-node:
working_directory: ~/repo
docker:
-
image: goodwaygroup/circleci-build-images:node-12
auth:
username: $DOCKER_USER
password: $DOCKER_PASS
gg-eks:
working_directory: ~/repo
docker:
-
image: goodwaygroup/circleci-build-images:eks-1.0.0
auth:
username: $DOCKER_USER
password: $DOCKER_PASS
orbs:
docker: circleci/[email protected]
aws-cli: circleci/[email protected]
aws-ecr: circleci/[email protected]
my-orb:
orbs:
docker: circleci/[email protected]
commands:
build-with-dynamic-tag:
description: |
Build and tag a Docker image
parameters:
debug:
default: false
description: |
Extra output for orb developers
type: boolean
dockerfile:
default: Dockerfile
description: Name of dockerfile to use, defaults to Dockerfile
type: string
extra_build_args:
default: ""
description: |
Extra flags to pass to docker build. For examples, see https://docs.docker.com/engine/reference/commandline/build
type: string
image:
description: Name of image to build
type: string
lint-dockerfile:
default: false
description: |
Lint Dockerfile before building?
type: boolean
path:
default: .
description: |
Path to the directory containing your Dockerfile and build context, defaults to . (working directory)
type: string
registry:
default: docker.io
description: |
Name of registry to use, defaults to docker.io
type: string
step-name:
default: Docker build
description: Specify a custom step name for this command, if desired
type: string
tag-env:
default: CIRCLE_SHA1
description: Image tag environment variable name, defaults to CIRCLE_SHA1
type: env_var_name
treat-warnings-as-errors:
default: false
description: |
If linting Dockerfile, treat linting warnings as errors (would trigger an exist code and fail the CircleCI job)?
type: boolean
steps:
- when:
condition: <<parameters.lint-dockerfile>>
steps:
- docker/dockerlint:
debug: <<parameters.debug>>
dockerfile: <<parameters.path>>/<<parameters.dockerfile>>
treat-warnings-as-errors: <<parameters.treat-warnings-as-errors>>
- run:
command: |
docker build \
<<#parameters.extra_build_args>><<parameters.extra_build_args>><</parameters.extra_build_args>> \
-f <<parameters.path>>/<<parameters.dockerfile>> -t \
<<parameters.registry>>/<< parameters.image>>:${<<parameters.tag-env>>} \
<<parameters.path>>
name: <<parameters.step-name>>
push-with-dynamic-tag:
description: Push a Docker image to a registry
parameters:
image:
description: Name of image to push
type: string
registry:
default: docker.io
description: |
Name of registry to use, defaults to docker.io
type: string
step-name:
default: Docker push
description: 'Specify a custom step name for this command, if desired'
type: string
tag-env:
default: CIRCLE_SHA1
description: 'Image tag environment variable, defaults to CIRCLE_SHA1'
type: env_var_name
steps:
- deploy:
command: >
docker push <<parameters.registry>>/<<
parameters.image>>:${<<parameters.tag-env>>}
name: <<parameters.step-name>>
determine-docker-tag:
parameters:
variable:
default: DOCKER_TAG
description: 'Variable to export to BASH_ENV'
type: env_var_name
steps:
-
run:
name: 'Determine Docker Tag'
command: |
SHORT_SHA1=$(git rev-parse --short ${CIRCLE_SHA1})
DOCKER_TAG=$([[ ! -z "${CIRCLE_TAG}" ]] && echo ${CIRCLE_TAG//\//-}.${SHORT_SHA1} || ([[ ! -z "${CIRCLE_BRANCH}" ]] && echo ${CIRCLE_BRANCH//\//-}.${SHORT_SHA1} || echo ${SHORT_SHA1}))
echo "export <<parameters.variable>>=${DOCKER_TAG}" >> ${BASH_ENV}
cat ${BASH_ENV}
codecov-upload:
description: Upload test results to codecov.io
parameters:
token:
type: string
steps:
- run:
name: Upload to codecov.io
command: bash <(curl -s https://codecov.io/bash) -t << parameters.token >>
monitor-deployment:
description: Checks the status of a kubernetes deployment and waits for all new pods to start and to report as healthy
parameters:
maxAttempts:
type: integer
default: 30
kubernetesNamespace:
type: string
kubernetesDeployment:
type: string
steps:
-
run:
name: Monitor Rollout
command: |
ATTEMPTS=0
ROLLOUT_STATUS_CMD="kubectl rollout status deployment/<< parameters.kubernetesDeployment >> -n << parameters.kubernetesNamespace >>"
until $ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq << parameters.maxAttempts >> ]; do
$ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
jobs:
test:
executor: gg-node
parameters:
codecovToken:
type: string
default: ""
steps:
- checkout
- setup_remote_docker
# Download and cache dependencies
-
restore_cache:
keys:
- v0-dependencies-{{ checksum "package-lock.json" }}
-
run:
name: Dependency Install
command: npm install
-
save_cache:
paths:
- node_modules
key: v0-dependencies-{{ checksum "package-lock.json" }}
# Run Tests!
- run: npm test
- when:
condition: << parameters.codecovToken >>
steps:
- my-orb/codecov-upload:
token: << parameters.codecovToken >>
- unless:
condition: << parameters.codecovToken >>
steps:
- run: echo "Codecov disabled"
- store_artifacts:
path: ./coverage
manual-build:
executor: gg-node
steps:
- checkout
- setup_remote_docker
-
aws-cli/setup:
aws-region: AWS_REGION
- aws-ecr/ecr-login
- my-orb/determine-docker-tag
-
docker/check:
docker-password: DOCKER_PASS
docker-username: DOCKER_USER
-
my-orb/build-with-dynamic-tag:
image: $DOCKER_NAMESPACE/$CIRCLE_PROJECT_REPONAME
tag-env: DOCKER_TAG
extra_build_args: '--build-arg ssh_prv_key="$(cat ~/.ssh/id_rsa)"'
registry: $DOCKER_REGISTRY
-
my-orb/push-with-dynamic-tag:
image: $DOCKER_NAMESPACE/$CIRCLE_PROJECT_REPONAME
tag-env: DOCKER_TAG
registry: $DOCKER_REGISTRY
deploy-eks:
executor: gg-eks
parameters:
environment:
type: string
notificationChannel:
type: string
appName:
type: string
waitForRollout:
type: boolean
default: false
steps:
- checkout
- my-orb/determine-docker-tag
# load in workspace
-
restore_cache:
keys:
- v0-workspace-{{ .Branch }}-{{ .Revision }}
# Deploy
-
deploy:
command: ${HOME}/kube-apply.sh .kube/eks-<< parameters.environment >> << parameters.appName >>-<< parameters.environment >>
# Conditionally wait for rollout to complete
- when:
condition: << parameters.waitForRollout >>
steps:
- my-orb/monitor-deployment:
maxAttempts: 30
kubernetesNamespace: << parameters.appName >>-<< parameters.environment >>
kubernetesDeployment: << parameters.appName >>-<< parameters.environment >>
# Notify deploy
- run:
name: Deploy Success
when: on_success
command: |
if [ "$CIRCLE_NODE_INDEX" == 0 ]; then
${HOME}/slack.sh -t success -e << parameters.environment >> -c << parameters.notificationChannel >> -d ${DOCKER_TAG}
fi
- run:
name: Deploy Failed
when: on_fail
command: |
if [ "$CIRCLE_NODE_INDEX" == 0 ]; then
${HOME}/slack.sh -t failure -e << parameters.environment >> -c << parameters.notificationChannel >> -d ${DOCKER_TAG}
fi
# Push to Apollo Graph Manager
deploy-schema:
description: Uploads the GraphQL Schema to Apollo Engine
parameters:
environment:
type: string
machine:
image: ubuntu-1604:201903-01
steps:
- checkout
- run:
name: Install Node Version Manager
command: |
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install v12.13.0
nvm alias default v12.13.0
echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV
echo "[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"" >> $BASH_ENV
-
run:
name: Dependency Install
command: npm install
-
run:
name: Install apollo CLI
command: npm install --global apollo
- run:
name: Start Prisma server
command: docker-compose up -d
- run:
sleep 5
- run:
name: Prisma deploy local
command: |
NODE_ENV=development PRISMA_SERVER_URL=http://localhost:4466 npm run prisma:deploy:dev
- run:
name: start local service-monitor
command: PRISMA_SERVER_URL=http://localhost:4466 npm start
background: true
- run:
sleep 5
-
run:
name: Upload Schema
command: |
ENGINE_API_KEY=$ENGINE_API_KEY apollo service:push --endpoint=http://localhost:3021/service-monitor/graphql --tag=<<parameters.environment>>
workflows:
build_workflow:
jobs:
-
test:
### Once the project has been saved to github the Repo Token can be
### found at: https://codecov.io/gh/GoodwayGroup/service-monitor
codecovToken: d1b7b886-f0ec-4990-a966-b20f66f43d70
filters:
tags:
only: /.*/
-
manual-build:
requires:
- test
filters:
tags:
only: /.*/
# Deploy EKS Staging
-
deploy-eks:
name: deploy-eks-staging
context: aws-eks-goodway-staging
environment: staging
notificationChannel: bi-deployments
appName: service-monitor
waitForRollout: false
requires:
- manual-build
filters:
branches:
only:
/^(release|hotfix|master|staging).*/
-
deploy-schema:
name: deploy-schema-staging
environment: staging
requires:
- deploy-eks-staging
filters:
tags:
only: /^v.*/
branches:
only:
/^(release|hotfix|master|staging).*/
# Deploy EKS Production
-
deploy-eks:
name: deploy-eks-production
context: aws-eks-goodway-production
environment: production
notificationChannel: bi-development
appName: service-monitor
waitForRollout: false
requires:
- manual-build
filters:
tags:
only: /^v.*/
branches:
only:
/^(shipit).*/
-
deploy-schema:
name: deploy-schema-production
environment: production
requires:
- deploy-eks-production
filters:
tags:
only: /^v.*/
branches:
only:
/^(shipit).*/