Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f7bf07c
Always publish to us-east-1.
purple4reina Apr 10, 2025
d8ccc3d
WIP
purple4reina Apr 24, 2025
b8a4c8c
Publishes to us-west-2.
purple4reina Jun 13, 2025
ff461f9
Fix needs and update things.
purple4reina Jun 16, 2025
38cefad
Use underscore.
purple4reina Jun 17, 2025
d9c3601
No dot.
purple4reina Jun 17, 2025
9782ab0
Correct replace.
purple4reina Jun 17, 2025
ff9372d
Use variables.
purple4reina Jun 17, 2025
7896e48
Properly get arn.
purple4reina Jun 17, 2025
7c9476d
Just Trim.
purple4reina Jun 17, 2025
9daf17b
Multiline string.
purple4reina Jun 17, 2025
85d6083
Change to template comment.
purple4reina Jun 17, 2025
1d35ac3
No more multiline.
purple4reina Jun 17, 2025
61fb775
Remove comment?
purple4reina Jun 17, 2025
ab9e2df
Combine lines again.
purple4reina Jun 17, 2025
a3819c0
Move comment.
purple4reina Jun 17, 2025
f4a0311
Another multiline.
purple4reina Jun 17, 2025
bbb5512
Exit if not found.
purple4reina Jun 17, 2025
7813992
Set -x.
purple4reina Jun 17, 2025
f5acbac
More debugging.
purple4reina Jun 17, 2025
fba2869
Even more debugging.
purple4reina Jun 17, 2025
82b3ee1
Broaden regex.
purple4reina Jun 17, 2025
e7781e9
Subscript.
purple4reina Jun 17, 2025
5505b6c
No more subscript.
purple4reina Jun 17, 2025
b536706
Artifacts true.
purple4reina Jun 17, 2025
91a8afa
Inherit dependencies and variables.
purple4reina Jun 17, 2025
f60afb2
Add testing downstream branch.
purple4reina Jun 17, 2025
612e63b
Remove dependencies use variables.
purple4reina Jun 17, 2025
02c4578
Use loop and main.
purple4reina Jun 17, 2025
3f5bc43
Uncomment other tests.
purple4reina Jun 17, 2025
fe77f31
Cleanup version env vars.
purple4reina Jun 17, 2025
ba03172
Whitespace cleanups.
purple4reina Jun 18, 2025
0fb0007
Only deploy layers on success.
purple4reina Jun 18, 2025
1256e10
Add e2e-status check.
purple4reina Jun 18, 2025
27430d2
Improve output of job.
purple4reina Jun 20, 2025
b164380
Needing publish loads dotenv artifact.
purple4reina Jun 20, 2025
0497bf0
Have e2e-status job start right away then poll.
purple4reina Jun 20, 2025
5a879f7
Comment out tests for now.
purple4reina Jun 20, 2025
879eb75
Use apk.
purple4reina Jun 20, 2025
ab18312
Debugging.
purple4reina Jun 20, 2025
757a13b
Try JOB-TOKEN.
purple4reina Jun 20, 2025
bdce942
Print out URL.
purple4reina Jun 20, 2025
c1cfa8f
Try bridges api.
purple4reina Jun 20, 2025
efa4ff5
Try GITLAB_API_TOKEN.
purple4reina Jun 20, 2025
d1e8c55
Use CI_JOB_STATUS to determine pass/fail.
purple4reina Jun 20, 2025
a5571f1
Remove switch.
purple4reina Jun 21, 2025
e261dcd
Create dotenv file from publish script.
purple4reina Jun 30, 2025
19d2fc3
Use docker docker image.
purple4reina Jun 30, 2025
b34d4b2
This needs not needed.
purple4reina Jun 30, 2025
1374828
Push check status to file in e2e repo.
purple4reina Jun 30, 2025
c38abb1
Start status checking in test stage.
purple4reina Jun 30, 2025
7f29f71
Remove e2e-test-status job for now.
purple4reina Aug 12, 2025
eb787a1
Improve test status reporting.
purple4reina Aug 12, 2025
5cd891f
Use dependencies and remove apk.
purple4reina Aug 14, 2025
658ad5e
Handle all of the statuses.
purple4reina Aug 14, 2025
392c594
More modifications.
purple4reina Aug 14, 2025
4776625
Look at downstream not this pipeline status.
purple4reina Aug 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 68 additions & 6 deletions ci/input_files/build.yaml.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{{- $e2e_region := "us-west-2" -}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a variable declaration? If so, why not use an environment variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is just a variable declaration. I hadn't thought of just using an environment variable. I was thinking that this way, the value is just built into the final yaml file, instead of being resolved later, at ci execution time. What are your thoughts on that?

Ah, okay, so one of the places this variable is used is in a needs block. According to gitlab docs, variables are not available in needs blocks.


stages:
- build
- test
- sign
- publish
- e2e
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e2e needs publish which needs test


.python-before-script: &python-before-script
- pip install virtualenv
Expand Down Expand Up @@ -56,11 +59,11 @@ check-layer-size ({{ $runtime.name }}-{{ $runtime.arch }}):
stage: test
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/docker:20.10
needs:
needs:
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
dependencies:
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
script:
script:
- PYTHON_VERSION={{ $runtime.python_version }} ARCH={{ $runtime.arch }} ./scripts/check_layer_size.sh

lint python:
Expand All @@ -69,7 +72,7 @@ lint python:
image: registry.ddbuild.io/images/mirror/python:{{ $runtime.image }}
cache: &{{ $runtime.name }}-{{ $runtime.arch }}-cache
before_script: *python-before-script
script:
script:
- source venv/bin/activate
- ./scripts/check_format.sh

Expand All @@ -79,15 +82,15 @@ unit-test ({{ $runtime.name }}-{{ $runtime.arch }}):
image: registry.ddbuild.io/images/mirror/python:{{ $runtime.image }}
cache: &{{ $runtime.name }}-{{ $runtime.arch }}-cache
before_script: *python-before-script
script:
script:
- source venv/bin/activate
- pytest -vv

integration-test ({{ $runtime.name }}-{{ $runtime.arch }}):
stage: test
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/docker:20.10-py3
needs:
needs:
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
dependencies:
- build-layer ({{ $runtime.name }}-{{ $runtime.arch }})
Expand Down Expand Up @@ -132,16 +135,22 @@ sign-layer ({{ $runtime.name }}-{{ $runtime.arch }}):
- 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-py3
rules:
- if: '"{{ $environment_name }}" == "sandbox" && $REGION == "{{ $e2e_region }}" && "{{ $runtime.arch }}" == "amd64"'
when: on_success
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always be sure to publish to the sandbox account in us-west-2 for e2e testing.

- if: '"{{ $environment_name }}" == "sandbox"'
when: manual
allow_failure: true
- if: '$CI_COMMIT_TAG =~ /^v.*/'
artifacts:
reports:
dotenv: {{ $dotenv }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When saved as a dotenv report, this file will get sourced for its env vars in every downstream job.

needs:
{{ if or (eq $environment_name "prod") }}
- sign-layer ({{ $runtime.name }}-{{ $runtime.arch}})
Expand All @@ -166,7 +175,7 @@ publish-layer-{{ $environment_name }} ({{ $runtime.name }}-{{ $runtime.arch }}):
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 }} ./ci/publish_layers.sh
- STAGE={{ $environment_name }} PYTHON_VERSION={{ $runtime.python_version }} ARCH={{ $runtime.arch }} DOTENV={{ $dotenv }} ./ci/publish_layers.sh

{{- end }}

Expand Down Expand Up @@ -232,3 +241,56 @@ signed layer bundle:
- 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
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly pass environment variables from the sourced publish job dotenv file to the downstream job. These env vars are not passed downstream otherwise.

{{- end }}
{{- end }}
needs: {{ range (ds "runtimes").runtimes }}
{{- if eq .arch "amd64" }}
- "publish-layer-sandbox ({{ .name }}-{{ .arch }}): [{{ $e2e_region }}]"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run after all the publish jobs have completed.

{{- end }}
{{- end }}

e2e-test-status:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This e2e-test-status job will be overhauled in a later PR.

stage: e2e
image: registry.ddbuild.io/images/docker:20.10-py3
tags: ["arch:amd64"]
timeout: 3h
script: |
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)
URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/bridges"
echo "Fetching E2E job status from: $URL"
while true; do
RESPONSE=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" "$URL")
E2E_JOB_STATUS=$(echo "$RESPONSE" | jq -r '.[] | select(.name=="e2e-test") | .downstream_pipeline.status')
echo -n "E2E job status: $E2E_JOB_STATUS, "
if [ "$E2E_JOB_STATUS" == "success" ]; then
echo "✅ E2E tests completed successfully"
exit 0
elif [ "$E2E_JOB_STATUS" == "failed" ]; then
echo "❌ E2E tests failed"
exit 1
elif [ "$E2E_JOB_STATUS" == "running" ]; then
echo "⏳ E2E tests are still running, retrying in 1 minute..."
elif [ "$E2E_JOB_STATUS" == "canceled" ]; then
echo "🚫 E2E tests were canceled"
exit 1
elif [ "$E2E_JOB_STATUS" == "skipped" ]; then
echo "⏭️ E2E tests were skipped"
exit 0
else
echo "❓ Unknown E2E test status: $E2E_JOB_STATUS, retrying in 1 minute..."
fi
sleep 60
done
8 changes: 8 additions & 0 deletions ci/publish_layers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ fi
while [ $latest_version -lt $VERSION ]; do
latest_version=$(publish_layer $REGION $layer $aws_cli_python_version_key $layer_path)
printf "[$REGION] Published version $latest_version for layer $layer in region $REGION\n"
latest_arn=$(aws lambda get-layer-version --layer-name $layer --version-number $latest_version --region $REGION --query 'LayerVersionArn' --output text)
printf "[$REGION] Published arn $latest_arn\n"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sur to always print the arn to stdout when publishing layers. The publish gitlab jobs will do a regex search on this stdout to determine the arn for a newly published layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update, the publish gitlab job will not be doing a regex search. Instead we will write the layer versions to a dotenv file, as seen below.


# This shouldn't happen unless someone manually deleted the latest version, say 28, and
# then tries to republish 28 again. The published version would actually be 29, because
Expand All @@ -209,4 +211,10 @@ while [ $latest_version -lt $VERSION ]; do
fi
done

if [ -n "$DOTENV" ]; then
printf "[$REGION] Exporting layer version to $DOTENV file...\n"
echo "PYTHON_${PYTHON_VERSION/./}_VERSION=$latest_arn" >> "$DOTENV"
cat "$DOTENV"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is where we write the arn to the given dotenv file. This dotenv file will be saved as an artifact on the job.

fi

printf "[$REGION] Finished publishing layers...\n\n"
Loading