Skip to content

Commit 02f3a00

Browse files
rithikanarayanjchrostek-ddjoeyzhao2018
authored
Adding e2e test trigger (#718)
* Adding e2e test trigger * typo * more typos * another typo * reformat * typo * remove var * remove arch * remove status check * python test * indent * fix version * status * fix gitlab api token * trying new image for polling job * trying to add auth anywhere * auth anywhere install? * more auth * no ddtool? * no brew * remove authanywhere flag * debugging string indexing * No auth? * new audience * mimic code-gen * try using staging * try getting datadog-lambda-js token * move script into separate file * chmod * /bin/authanywhere * space * Removing debug prints * find printed token * layer version * dotenv * typo * fixing version * substitution * getting layer arn * more typo * update polling time * [SVLS-8538] add durable function tags (#730) * [SVLS-8538] add durable function tags * format * add a tiny comment to re-trigger the pipeline --------- Co-authored-by: Joey Zhao <5253430+joeyzhao2018@users.noreply.github.com> --------- Co-authored-by: jchrostek-dd <john.chrostek@datadoghq.com> Co-authored-by: Joey Zhao <5253430+joeyzhao2018@users.noreply.github.com>
1 parent 50f8f6f commit 02f3a00

3 files changed

Lines changed: 82 additions & 1 deletion

File tree

.gitlab/input_files/build.yaml.tpl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{- $e2e_region := "us-west-2" -}}
2+
13
variables:
24
CI_DOCKER_TARGET_IMAGE: registry.ddbuild.io/ci/datadog-lambda-js
35
CI_DOCKER_TARGET_VERSION: latest
@@ -7,6 +9,7 @@ stages:
79
- test
810
- sign
911
- publish
12+
- e2e
1013

1114
default:
1215
retry:
@@ -94,6 +97,7 @@ integration test ({{ $runtime.name }}):
9497
- RUNTIME_PARAM={{ $runtime.node_major_version }} ./scripts/run_integration_tests.sh
9598

9699
{{ range $environment := (ds "environments").environments }}
100+
{{ $dotenv := print $runtime.name "_" $environment.name ".env" }}
97101

98102
{{ if or (eq $environment.name "prod") }}
99103
sign layer ({{ $runtime.name }}):
@@ -126,10 +130,15 @@ publish layer {{ $environment.name }} ({{ $runtime.name }}):
126130
tags: ["arch:amd64"]
127131
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
128132
rules:
133+
- if: '"{{ $environment.name }}" == "sandbox" && $REGION == "{{ $e2e_region }}"'
134+
when: on_success
129135
- if: '"{{ $environment.name }}" =~ /^(sandbox|staging)/'
130136
when: manual
131137
allow_failure: true
132138
- if: '$CI_COMMIT_TAG =~ /^v.*/'
139+
artifacts:
140+
reports:
141+
dotenv: {{ $dotenv }}
133142
needs:
134143
{{ if or (eq $environment.name "prod") }}
135144
- sign layer ({{ $runtime.name }})
@@ -154,7 +163,7 @@ publish layer {{ $environment.name }} ({{ $runtime.name }}):
154163
before_script:
155164
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
156165
script:
157-
- STAGE={{ $environment.name }} NODE_VERSION={{ $runtime.node_version }} .gitlab/scripts/publish_layers.sh
166+
- STAGE={{ $environment.name }} NODE_VERSION={{ $runtime.node_version }} DOTENV={{ $dotenv }} .gitlab/scripts/publish_layers.sh
158167

159168
{{- end }}
160169

@@ -203,3 +212,27 @@ publish npm package:
203212
- mkdir -p datadog_lambda_js-{{ if eq $environment.name "prod"}}signed-{{ end }}bundle-${CI_JOB_ID}
204213
- cp .layers/datadog_lambda_node*.zip datadog_lambda_js-{{ if eq $environment.name "prod"}}signed-{{ end }}bundle-${CI_JOB_ID}
205214
{{ end }}
215+
216+
e2e-test:
217+
stage: e2e
218+
trigger:
219+
project: DataDog/serverless-e2e-tests
220+
strategy: depend
221+
variables:
222+
LANGUAGES_SUBSET: node
223+
{{- range (ds "runtimes").runtimes }}
224+
{{- $version := print (.name | strings.Trim "node") }}
225+
NODEJS_{{ $version }}_VERSION: $NODE_{{ $version }}_VERSION
226+
{{- end }}
227+
needs: {{ range (ds "runtimes").runtimes }}
228+
- "publish layer sandbox ({{ .name }}): [{{ $e2e_region }}]"
229+
{{- end }}
230+
231+
232+
e2e-test-status:
233+
stage: e2e
234+
image: registry.ddbuild.io/images/docker:20.10-py3
235+
tags: ["arch:amd64"]
236+
timeout: 3h
237+
script:
238+
- .gitlab/scripts/poll_e2e.sh

.gitlab/scripts/poll_e2e.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
curl -OL "binaries.ddbuild.io/dd-source/authanywhere/LATEST/authanywhere-linux-amd64" && mv "authanywhere-linux-amd64" /bin/authanywhere && chmod +x /bin/authanywhere
2+
3+
BTI_CI_API_TOKEN=$(authanywhere --audience rapid-devex-ci)
4+
5+
BTI_RESPONSE=$(curl --silent --request GET \
6+
--header "$BTI_CI_API_TOKEN" \
7+
--header "Content-Type: application/vnd.api+json" \
8+
"https://bti-ci-api.us1.ddbuild.io/internal/ci/gitlab/token?owner=DataDog&repository=datadog-lambda-js")
9+
10+
GITLAB_TOKEN=$(echo "$BTI_RESPONSE" | jq -r '.token // empty')
11+
12+
URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/bridges"
13+
14+
echo "Fetching E2E job status from: $URL"
15+
16+
while true; do
17+
RESPONSE=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" "$URL")
18+
E2E_JOB_STATUS=$(echo "$RESPONSE" | jq -r '.[] | select(.name=="e2e-test") | .downstream_pipeline.status')
19+
echo -n "E2E job status: $E2E_JOB_STATUS, "
20+
if [ "$E2E_JOB_STATUS" == "success" ]; then
21+
echo "✅ E2E tests completed successfully"
22+
exit 0
23+
elif [ "$E2E_JOB_STATUS" == "failed" ]; then
24+
echo "❌ E2E tests failed"
25+
exit 1
26+
elif [ "$E2E_JOB_STATUS" == "running" ]; then
27+
echo "⏳ E2E tests are still running, retrying in 2 minutes..."
28+
elif [ "$E2E_JOB_STATUS" == "canceled" ]; then
29+
echo "🚫 E2E tests were canceled"
30+
exit 1
31+
elif [ "$E2E_JOB_STATUS" == "skipped" ]; then
32+
echo "⏭️ E2E tests were skipped"
33+
exit 0
34+
else
35+
echo "❓ Unknown E2E test status: $E2E_JOB_STATUS, retrying in 2 minutes..."
36+
fi
37+
sleep 120
38+
done

.gitlab/scripts/publish_layers.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ fi
146146
while [ $latest_version -lt $VERSION ]; do
147147
latest_version=$(publish_layer $REGION $layer $aws_cli_node_version_key $layer_path)
148148
printf "[$REGION] Published version $latest_version for layer $layer in region $REGION\n"
149+
latest_arn=$(aws lambda get-layer-version --layer-name $layer --version-number $latest_version --region $REGION --query 'LayerVersionArn' --output text)
150+
printf "[$REGION] Published arn $latest_arn\n"
149151

150152
# This shouldn't happen unless someone manually deleted the latest version, say 28, and
151153
# then tries to republish 28 again. The published version would actually be 29, because
@@ -156,4 +158,12 @@ while [ $latest_version -lt $VERSION ]; do
156158
fi
157159
done
158160

161+
if [ -n "$DOTENV" ]; then
162+
printf "[$REGION] Exporting layer version to $DOTENV file...\n"
163+
node_version=$NODE_VERSION
164+
major_version="${node_version:0:2}"
165+
echo "NODE_${major_version}_VERSION=$latest_arn" >> "$DOTENV"
166+
cat "$DOTENV"
167+
fi
168+
159169
printf "[$REGION] Finished publishing layers...\n\n"

0 commit comments

Comments
 (0)