-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconfig.yml
313 lines (294 loc) · 9.33 KB
/
config.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
version: 2.1
orbs:
slack: circleci/slack@5.1.1
workflows:
main-workflow:
jobs:
- lint
- test
- build
- db-schema:
context: org-global
- TODO-migrator-image:
context: org-global
- TODO-docker-image:
context: org-global
requires:
- lint
- test
- build
# TODO: Uncomment this job after setting a value for parameters.release-name and deploying the service.
# This job will need at least one deployed version of the service to compare the Helm chart diff during the dry run.
# - TODO-helm-package-dry-run:
# context: [org-global, github-comments]
# filters:
# branches:
# ignore:
# - main
- TODO-deploy:
context: [org-global, slack-notifications]
filters:
branches:
only:
- main
requires:
- lint
- test
- build
- TODO-migrator-image
- TODO-docker-image
- db-schema
executors:
default:
docker:
- image: &goimage cimg/go:1.24
ccc:
docker:
- image: circleci/command-convenience:0.1
auth:
username: $DOCKER_HUB_USER
password: $DOCKER_HUB_PASSWORD
environment:
NAME: << pipeline.parameters.release-name >>
DOCKERFILE_PATH: Dockerfile
CUSTOM_CHART: deploy
parameters:
release-name:
type: string
default: "" # TODO: Change me to run helm-package-dry-run and deploy
release-version:
type: string
default: "v1"
jobs:
lint:
docker:
- image: *goimage
resource_class: xlarge
steps:
- setup
- run:
name: generate
command: ./do generate
- run:
name: go tidy
command: go mod tidy -v
- run:
name: verify no changes
command: git diff --ignore-matching-lines='Generated on ' --exit-code
- run: ./do lint-report
- store_results
build:
docker:
- image: *goimage
resource_class: xlarge
steps:
- setup
- run: ./do generate
- run: ./do build
- persist_to_workspace:
root: .
paths:
- target
TODO-migrator-image:
executor: ccc
environment:
NAME: ex-service-template-migrator ## TODO replace by your-service-name-migrator
DOCKERFILE_PATH: ""
MIGRATIONS_SQL_PATH: "migrations/sql"
IMAGE_NAME: "circleci/ex-service-template-migrator" ## TODO replace by circleci/your-service-name-migrator
steps:
- when:
condition: << pipeline.parameters.release-name >>
steps:
- create_and_scan_docker_image
- run: mv docker_image.tag docker_image.migrator.tag
- persist_to_workspace:
root: .
paths:
- docker_image.migrator.tag
- unless:
condition: << pipeline.parameters.release-name >>
steps:
- run: echo add release-name to enable this job
TODO-docker-image:
executor: ccc
steps:
- when:
condition: << pipeline.parameters.release-name >>
steps:
- checkout
- attach_workspace:
at: .
- create_and_scan_docker_image
- persist_to_workspace:
root: .
paths:
- docker_image.tag
- unless:
condition: << pipeline.parameters.release-name >>
steps:
- run: echo add release-name to enable this job
test:
docker:
- image: *goimage
- image: cimg/postgres:17.4
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: dbname
resource_class: xlarge
steps:
- setup
- run: ./do create-stub-test-files
- run:
name: run tests
command: ./do test ./...
- store_results
db-schema:
machine:
image: ubuntu-2004:2023.10.1
steps:
- checkout
- run:
name: docker login
command: >
echo $DOCKER_HUB_PASSWORD |
docker login --username $DOCKER_HUB_USER --password-stdin
- run: ./do schema
- run:
name: Check that the DB schema dump matches migrations
command: |
# If the `diff` exit code is not zero, the migrations/schema.sql file is
# out-of date.
# Run ./do schema locally to update it
git diff --exit-code
TODO-deploy:
executor: ccc
# TODO - uncomment the code below once you've defined the release-name parameter
# environment:
# AWS_DEFAULT_REGION: us-east-1
# RELEASE_VERSION: << pipeline.parameters.release-version >>
steps:
- when:
condition: << pipeline.parameters.release-name >>
steps:
- checkout
- attach_workspace:
at: .
# TODO - uncomment this code to enable migrations, this will run before every deploy, replace ex-service-template-migrator with your-service-name-migrator
# - run:
# name: substitute migrator values
# command: |
# MIGRATOR_VERSION="$(< docker_image.migrator.tag)"
# sed -i.bak "s|\<<migrator_image_name>>|183081753049.dkr.ecr.us-east-1.amazonaws.com/circleci/ex-service-template-migrator:${MIGRATOR_VERSION}|g" deploy/values.yaml
- run: deploy
- notify_slack
- notify_honeycomb
- unless:
condition: << pipeline.parameters.release-name >>
steps:
- run: echo add release-name to enable this job
TODO-helm-package-dry-run:
executor: ccc
steps:
- when:
condition: << pipeline.parameters.release-name >>
steps:
- checkout
- run:
name: Override container version & dry run
command: |
IGNORE_VERSION=1 /deploy/dry-run
ls -la .helm.diff
- run:
name: Install GitHub CLI
command: |
curl -fsSL 'https://github.com/cli/cli/releases/download/v1.11.0/gh_1.11.0_linux_amd64.tar.gz' | tar -C /usr/local --strip-components=1 -xz
- run:
name: Comment on pull request
command: |
if [ ! -s ".helm.diff" ]
then
echo "No diff found"
exit 0
fi
if [ ! -n "$CI_PULL_REQUEST" ]
then
echo "No PR found"
exit 0
fi
echo "## Helm diff: <sup>[CI link]( $CIRCLE_BUILD_URL )</sup>" > comment.txt
echo '<details><summary>Details (click me)</summary>' >> comment.txt
echo '' >> comment.txt
echo '```diff' >> comment.txt
cat '.helm.diff' >> comment.txt
echo '```' >> comment.txt
echo '</details>' >> comment.txt
echo "Commenting on ${CI_PULL_REQUEST}"
gh pr comment "${CI_PULL_REQUEST}" --body-file comment.txt
- unless:
condition: << pipeline.parameters.release-name >>
steps:
- run: echo add release-name to enable this job
commands:
notify_slack:
steps:
- slack/notify:
channel: your-teams-deployment-channel #TODO: update this to your team's deployment channel.
branch_pattern: main
event: pass
template: success_tagged_deploy_1
notify_honeycomb:
steps:
- run:
name: Notify Honeycomb
command: |
cat \<< EOF | tee /tmp/honeycomb-marker
{
"message": "Deploying ex-service-template $(<docker_image.tag)",
"type":"deploy"
}
EOF
curl https://api.honeycomb.io/1/markers/execution \
-H "X-Honeycomb-Team: $HONEYCOMB_WRITEKEY" \
-d @/tmp/honeycomb-marker
setup:
steps:
- checkout
- run: go mod download
- run: ./do install-devtools
store_results:
steps:
- run:
name: Strip ANSI codes from xunit output
when: always
command: |
# The test output produces ANSI codes, which the XML writer converts into annoying
# \0xfffd characters - we'll strip these out to make the XML a bit more readable
sed -i 's/�\[[0-9;]*[a-zA-Z]//g' test-reports/*.xml || true
- store_artifacts:
path: test-reports
- store_test_results:
path: test-reports
remote_docker:
steps:
- setup_remote_docker
- run: docker version
create_and_scan_docker_image:
steps:
- remote_docker
- checkout
- attach_workspace:
at: .
- run:
name: create and scan docker image
command: |
set -x
if [[ "$CIRCLE_BRANCH" = "main" || "$CIRCLE_BRANCH" = "canary" ]]; then
# TODO change to all once dockerhub repo is ready
export DOCKER_REGISTRY=ecr
else
# this is how we tell CCC not to actually publish
export DOCKER_REGISTRY=none
fi
publish