1+ {{- $e2e_region := " us-west-2" -}}
2+
13stages:
24 - build
35 - test
46 - sign
57 - publish
8+ - e2e
69
710.python -before-script: &python-before-script
811 - pip install virtualenv
@@ -56,11 +59,11 @@ check-layer-size ({{ $runtime.name }}-{{ $runtime.arch }}):
5659 stage: test
5760 tags: [" arch:amd64" ]
5861 image: registry.ddbuild.io /images/docker:20.10
59- needs:
62+ needs:
6063 - build-layer ({{ $runtime .name }}-{{ $runtime .arch }})
6164 dependencies:
6265 - build-layer ({{ $runtime .name }}-{{ $runtime .arch }})
63- script:
66+ script:
6467 - PYTHON_VERSION= {{ $runtime .python_version }} ARCH= {{ $runtime .arch }} . /scripts/check_layer_size.sh
6568
6669lint python:
@@ -69,7 +72,7 @@ lint python:
6972 image: registry.ddbuild.io /images/mirror/python:{{ $runtime .image }}
7073 cache: &{{ $runtime .name }}-{{ $runtime .arch }}-cache
7174 before_script: *python-before-script
72- script:
75+ script:
7376 - source venv/bin/activate
7477 - . /scripts/check_format.sh
7578
@@ -79,15 +82,15 @@ unit-test ({{ $runtime.name }}-{{ $runtime.arch }}):
7982 image: registry.ddbuild.io /images/mirror/python:{{ $runtime .image }}
8083 cache: &{{ $runtime .name }}-{{ $runtime .arch }}-cache
8184 before_script: *python-before-script
82- script:
85+ script:
8386 - source venv/bin/activate
8487 - pytest -vv
8588
8689integration-test ({{ $runtime .name }}-{{ $runtime .arch }}):
8790 stage: test
8891 tags: [" arch:amd64" ]
8992 image: registry.ddbuild.io /images/docker:20.10 -py3
90- needs:
93+ needs:
9194 - build-layer ({{ $runtime .name }}-{{ $runtime .arch }})
9295 dependencies:
9396 - build-layer ({{ $runtime .name }}-{{ $runtime .arch }})
@@ -132,16 +135,22 @@ sign-layer ({{ $runtime.name }}-{{ $runtime.arch }}):
132135 - LAYER_FILE= datadog_lambda_py-{{ $runtime .arch }}-{{ $runtime .python_version }}.zip . /scripts/sign_layers.sh prod
133136
134137{{ range $environment_name , $environment := (ds " environments" ).environments }}
138+ {{ $dotenv := print $runtime .name " _" $runtime .arch " _" $environment_name " .env" }}
135139
136140publish-layer-{{ $environment_name }} ({{ $runtime .name }}-{{ $runtime .arch }}):
137141 stage: publish
138142 tags: [" arch:amd64" ]
139143 image: registry.ddbuild.io /images/docker:20.10 -py3
140144 rules:
145+ - if : '" {{ $environment_name }}" == " sandbox" && $REGION == " {{ $e2e_region }}" && " {{ $runtime.arch }}" == " amd64" '
146+ when: on_success
141147 - if : '" {{ $environment_name }}" == " sandbox" '
142148 when: manual
143149 allow_failure: true
144150 - if : '$CI_COMMIT_TAG = ~ /^v. */'
151+ artifacts:
152+ reports:
153+ dotenv: {{ $dotenv }}
145154 needs:
146155{{ if or (eq $environment_name " prod" ) }}
147156 - sign-layer ({{ $runtime .name }}-{{ $runtime .arch }})
@@ -166,7 +175,7 @@ publish-layer-{{ $environment_name }} ({{ $runtime.name }}-{{ $runtime.arch }}):
166175 before_script:
167176 - EXTERNAL_ID_NAME= {{ $environment .external_id }} ROLE_TO_ASSUME= {{ $environment .role_to_assume }} AWS_ACCOUNT= {{ $environment .account }} source . /ci/get_secrets.sh
168177 script:
169- - STAGE= {{ $environment_name }} PYTHON_VERSION= {{ $runtime .python_version }} ARCH= {{ $runtime .arch }} . /ci/publish_layers.sh
178+ - STAGE= {{ $environment_name }} PYTHON_VERSION= {{ $runtime .python_version }} ARCH= {{ $runtime .arch }} DOTENV = {{ $dotenv }} . /ci/publish_layers.sh
170179
171180{{- end }}
172181
@@ -232,3 +241,56 @@ signed layer bundle:
232241 - rm -rf datadog_lambda_py-signed-bundle-$ {CI_JOB_ID}
233242 - mkdir -p datadog_lambda_py-signed-bundle-$ {CI_JOB_ID}
234243 - cp .layers /datadog_lambda_py-*.zip datadog_lambda_py-signed-bundle-$ {CI_JOB_ID}
244+
245+ e2e-test:
246+ stage: e2e
247+ trigger:
248+ project: DataDog/serverless-e2e-tests
249+ strategy: depend
250+ variables:
251+ LANGUAGES_SUBSET: python
252+ # These env vars are inherited from the dotenv reports of the publish-layer jobs
253+ {{- range (ds " runtimes" ).runtimes }}
254+ {{- if eq .arch " amd64" }}
255+ {{- $version := print (.name | strings.Trim " python" ) }}
256+ PYTHON_{{ $version }}_VERSION: $PYTHON_ {{ $version }}_VERSION
257+ {{- end }}
258+ {{- end }}
259+ needs: {{ range (ds " runtimes" ).runtimes }}
260+ {{- if eq .arch " amd64" }}
261+ - " publish-layer-sandbox ({{ .name }}-{{ .arch }}): [{{ $e2e_region }}]"
262+ {{- end }}
263+ {{- end }}
264+
265+ e2e-test-status:
266+ stage: e2e
267+ image: registry.ddbuild.io /images/docker:20.10 -py3
268+ tags: [" arch:amd64" ]
269+ timeout: 3h
270+ script: |
271+ GITLAB_API_TOKEN= $ (aws ssm get-parameter --region us-east-1 --name " ci.${CI_PROJECT_NAME}.serverless-e2e-gitlab-token" --with -decryption --query " Parameter.Value" --out text)
272+ URL= " ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/bridges"
273+ echo " Fetching E2E job status from: $URL"
274+ while true; do
275+ RESPONSE= $ (curl -s --header " PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" " $URL" )
276+ E2E_JOB_STATUS= $ (echo " $RESPONSE" | jq -r '. [] | select(.name == " e2e-test" ) | .downstream_pipeline.status ')
277+ echo -n " E2E job status: $E2E_JOB_STATUS, "
278+ if [ " $E2E_JOB_STATUS" == " success" ]; then
279+ echo " ✅ E2E tests completed successfully"
280+ exit 0
281+ elif [ " $E2E_JOB_STATUS" == " failed" ]; then
282+ echo " ❌ E2E tests failed"
283+ exit 1
284+ elif [ " $E2E_JOB_STATUS" == " running" ]; then
285+ echo " ⏳ E2E tests are still running, retrying in 1 minute..."
286+ elif [ " $E2E_JOB_STATUS" == " canceled" ]; then
287+ echo " 🚫 E2E tests were canceled"
288+ exit 1
289+ elif [ " $E2E_JOB_STATUS" == " skipped" ]; then
290+ echo " ⏭️ E2E tests were skipped"
291+ exit 0
292+ else
293+ echo " ❓ Unknown E2E test status: $E2E_JOB_STATUS, retrying in 1 minute..."
294+ fi
295+ sleep 60
296+ done
0 commit comments