-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathbuild.yaml.tpl
More file actions
289 lines (268 loc) · 9.5 KB
/
build.yaml.tpl
File metadata and controls
289 lines (268 loc) · 9.5 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
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
{{- $e2e_region := "us-west-2" -}}
stages:
- build
- test
- sign
- publish
- e2e
.python-before-script: &python-before-script
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- pip install .[dev]
- pip install poetry
default:
retry:
max: 1
when:
# Retry when the runner fails to start
- runner_system_failure
# This is for serverless framework
.install-node: &install-node
- apt-get update
- apt-get install -y ca-certificates curl gnupg xxd
- mkdir -p /etc/apt/keyrings
- curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
# We are explicitly setting the node_20.x version for the installation
- echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
- apt-get update
- apt-get install nodejs -y
- npm install --global yarn
{{ range $runtime := (ds "runtimes").runtimes }}
# TODO(astuyve) - figure out python build cache
.{{ $runtime.name }}-{{ $runtime.arch }}-cache: &{{ $runtime.name }}-{{ $runtime.arch }}-cache
key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
paths:
- $CI_PROJECT_DIR/.yarn-cache
policy: pull
build-layer ({{ $runtime.name }}-{{ $runtime.arch }}):
stage: build
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/docker:20.10.13-jammy
artifacts:
expire_in: 1 hr # Unsigned zips expire in 1 hour
paths:
- .layers/datadog_lambda_py-{{ $runtime.arch }}-{{ $runtime.python_version }}.zip
variables:
CI_ENABLE_CONTAINER_IMAGE_BUILDS: "true"
script:
- PYTHON_VERSION={{ $runtime.python_version }} ARCH={{ $runtime.arch }} ./scripts/build_layers.sh
timeout: 15m
retry: 2
check-layer-size ({{ $runtime.name }}-{{ $runtime.arch }}):
stage: test
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/docker:20.10.13-jammy
needs:
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
dependencies:
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
script:
- PYTHON_VERSION={{ $runtime.python_version }} ARCH={{ $runtime.arch }} ./scripts/check_layer_size.sh
lint python:
stage: test
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/mirror/python:{{ $runtime.image }}
cache: &{{ $runtime.name }}-{{ $runtime.arch }}-cache
before_script: *python-before-script
script:
- source venv/bin/activate
- ./scripts/check_format.sh
unit-test ({{ $runtime.name }}-{{ $runtime.arch }}):
stage: test
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/mirror/python:{{ $runtime.image }}
cache: &{{ $runtime.name }}-{{ $runtime.arch }}-cache
before_script: *python-before-script
script:
- source venv/bin/activate
- pytest -vv
retry: 2
integration-test ({{ $runtime.name }}-{{ $runtime.arch }}):
stage: test
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/docker:20.10.13-jammy
rules:
- if: '$SKIP_E2E_TESTS == "true"'
when: never
- when: on_success
needs:
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
dependencies:
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
cache: &{{ $runtime.name }}-{{ $runtime.arch }}-cache
variables:
CI_ENABLE_CONTAINER_IMAGE_BUILDS: "true"
before_script:
- *install-node
- EXTERNAL_ID_NAME=integration-test-externalid ROLE_TO_ASSUME=sandbox-integration-test-deployer AWS_ACCOUNT=425362996713 source ./ci/get_secrets.sh
- yarn global add serverless@^3.38.0 --prefix /usr/local
- yarn global add serverless-python-requirements@^6.1.1 --prefix /usr/local
- cd integration_tests && yarn install && cd ..
script:
- RUNTIME_PARAM={{ $runtime.python_version }} ARCH={{ $runtime.arch }} ./scripts/run_integration_tests.sh
retry: 2
sign-layer ({{ $runtime.name }}-{{ $runtime.arch }}):
stage: sign
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/docker:20.10.13-jammy
rules:
- if: '$CI_COMMIT_TAG =~ /^v.*/'
when: manual
needs:
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
- check-layer-size ({{ $runtime.name }}-{{ $runtime.arch }})
- lint python
- unit-test ({{ $runtime.name }}-{{ $runtime.arch }})
- integration-test ({{ $runtime.name }}-{{ $runtime.arch }})
dependencies:
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
artifacts: # Re specify artifacts so the modified signed file is passed
expire_in: 1 day # Signed layers should expire after 1 day
paths:
- .layers/datadog_lambda_py-{{ $runtime.arch }}-{{ $runtime.python_version }}.zip
before_script:
- apt-get update
- apt-get install -y uuid-runtime
{{ with $environment := (ds "environments").environments.prod }}
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source ./ci/get_secrets.sh
{{ end }}
script:
- LAYER_FILE=datadog_lambda_py-{{ $runtime.arch}}-{{ $runtime.python_version }}.zip ./scripts/sign_layers.sh prod
{{ range $environment_name, $environment := (ds "environments").environments }}
{{ $dotenv := print $runtime.name "_" $runtime.arch "_" $environment_name ".env" }}
publish-layer-{{ $environment_name }} ({{ $runtime.name }}-{{ $runtime.arch }}):
stage: publish
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/docker:20.10.13-jammy
rules:
- if: '$SKIP_E2E_TESTS == "true"'
when: never
- if: '"{{ $environment_name }}" == "sandbox" && $REGION == "{{ $e2e_region }}" && "{{ $runtime.arch }}" == "amd64"'
when: on_success
- if: '"{{ $environment_name }}" == "sandbox"'
when: manual
allow_failure: true
- if: '$CI_COMMIT_TAG =~ /^v.*/'
artifacts:
reports:
dotenv: {{ $dotenv }}
needs:
{{ if or (eq $environment_name "prod") }}
- sign-layer ({{ $runtime.name }}-{{ $runtime.arch}})
{{ else }}
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
- check-layer-size ({{ $runtime.name }}-{{ $runtime.arch }})
- lint python
- unit-test ({{ $runtime.name }}-{{ $runtime.arch }})
- integration-test ({{ $runtime.name }}-{{ $runtime.arch }})
{{ end }}
dependencies:
{{ if or (eq $environment_name "prod") }}
- sign-layer ({{ $runtime.name }}-{{ $runtime.arch}})
{{ else }}
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
{{ end }}
parallel:
matrix:
- REGION: {{ range (ds "regions").regions }}
- {{ .code }}
{{- end}}
before_script:
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source ./ci/get_secrets.sh
script:
- STAGE={{ $environment_name }} PYTHON_VERSION={{ $runtime.python_version }} ARCH={{ $runtime.arch }} DOTENV={{ $dotenv }} ./ci/publish_layers.sh
{{- end }}
{{- end }}
publish-pypi-package:
stage: publish
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/docker:20.10.13-jammy
before_script: *python-before-script
cache: []
rules:
- if: '$CI_COMMIT_TAG =~ /^v.*/'
when: manual
needs: {{ range $runtime := (ds "runtimes").runtimes }}
- sign-layer ({{ $runtime.name }}-{{ $runtime.arch}})
{{- end }}
script:
- ./ci/publish_pypi.sh
layer bundle:
stage: build
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/docker:20.10.13-jammy
needs:
{{ range (ds "runtimes").runtimes }}
- build-layer ({{ .name }}-{{ .arch }})
{{ end }}
dependencies:
{{ range (ds "runtimes").runtimes }}
- build-layer ({{ .name }}-{{ .arch }})
{{ end }}
artifacts:
expire_in: 1 hr
paths:
- datadog_lambda_py-bundle-${CI_JOB_ID}/
name: datadog_lambda_py-bundle-${CI_JOB_ID}
script:
- rm -rf datadog_lambda_py-bundle-${CI_JOB_ID}
- mkdir -p datadog_lambda_py-bundle-${CI_JOB_ID}
- cp .layers/datadog_lambda_py-*.zip datadog_lambda_py-bundle-${CI_JOB_ID}
signed layer bundle:
stage: sign
image: registry.ddbuild.io/images/docker:20.10.13-jammy
tags: ["arch:amd64"]
rules:
- if: '$CI_COMMIT_TAG =~ /^v.*/'
needs:
{{ range (ds "runtimes").runtimes }}
- sign-layer ({{ .name }}-{{ .arch }})
{{ end }}
dependencies:
{{ range (ds "runtimes").runtimes }}
- sign-layer ({{ .name }}-{{ .arch }})
{{ end }}
artifacts:
expire_in: 1 day
paths:
- datadog_lambda_py-signed-bundle-${CI_JOB_ID}/
name: datadog_lambda_py-signed-bundle-${CI_JOB_ID}
script:
- rm -rf datadog_lambda_py-signed-bundle-${CI_JOB_ID}
- mkdir -p datadog_lambda_py-signed-bundle-${CI_JOB_ID}
- cp .layers/datadog_lambda_py-*.zip datadog_lambda_py-signed-bundle-${CI_JOB_ID}
e2e-test:
stage: e2e
trigger:
project: DataDog/serverless-e2e-tests
strategy: depend
rules:
- if: '$SKIP_E2E_TESTS == "true"'
when: never
- when: on_success
variables:
LANGUAGES_SUBSET: python
# These env vars are inherited from the dotenv reports of the publish-layer jobs
{{- range (ds "runtimes").runtimes }}
{{- if eq .arch "amd64" }}
{{- $version := print (.name | strings.Trim "python") }}
PYTHON_{{ $version }}_VERSION: $PYTHON_{{ $version }}_VERSION
{{- end }}
{{- end }}
needs: {{ range (ds "runtimes").runtimes }}
{{- if eq .arch "amd64" }}
- "publish-layer-sandbox ({{ .name }}-{{ .arch }}): [{{ $e2e_region }}]"
{{- end }}
{{- end }}
e2e-test-status:
stage: e2e
image: registry.ddbuild.io/images/docker:20.10.13-jammy
tags: ["arch:amd64"]
timeout: 3h
rules:
- if: '$SKIP_E2E_TESTS == "true"'
when: never
- when: on_success
script:
- ci/poll_e2e.sh