Skip to content

Commit 994bd7d

Browse files
authored
Merge branch 'main' into joey/enhance-build-scripts
2 parents a5d3960 + b8f40e9 commit 994bd7d

53 files changed

Lines changed: 1194 additions & 288 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
1515

1616
- name: Set up Node 18.12
17-
uses: actions/setup-node@v3
17+
uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3.9.1
1818
with:
1919
node-version: 18.12
2020

@@ -24,7 +24,7 @@ jobs:
2424

2525
- name: Restore node modules from cache
2626
id: cache-node-modules
27-
uses: actions/cache@v3
27+
uses: actions/cache@6f8efc29b200d32929f49075959781ed54ec270c # v3.5.0
2828
with:
2929
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
3030
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
@@ -47,10 +47,10 @@ jobs:
4747
node-version: [18.12, 20.19, 22.11, 24.11]
4848
steps:
4949
- name: Checkout
50-
uses: actions/checkout@v3
50+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
5151

5252
- name: Set up Node ${{ matrix.node-version }}
53-
uses: actions/setup-node@v3
53+
uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3.9.1
5454
with:
5555
node-version: ${{ matrix.node-version }}
5656

@@ -60,7 +60,7 @@ jobs:
6060

6161
- name: Restore node modules from cache
6262
id: cache-node-modules
63-
uses: actions/cache@v3
63+
uses: actions/cache@6f8efc29b200d32929f49075959781ed54ec270c # v3.5.0
6464
with:
6565
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
6666
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

.github/workflows/build_layer.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build Layers for System Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "main"
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
node_version: ["18.12", "20.19", "22.11", "24.11"]
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
21+
22+
- name: Build layer for Node ${{ matrix.node_version }}
23+
run: |
24+
NODE_MAJOR=$(echo "${{ matrix.node_version }}" | cut -d '.' -f 1)
25+
temp_dir=$(mktemp -d)
26+
docker buildx build -t datadog-lambda-layer-node:${{ matrix.node_version }} . --no-cache \
27+
--build-arg image=node:${NODE_MAJOR}-bullseye --progress=plain -o $temp_dir/nodejs
28+
mkdir -p .layers
29+
(cd $temp_dir && zip -q -r $GITHUB_WORKSPACE/.layers/datadog_lambda_node${{ matrix.node_version }}.zip ./)
30+
rm -rf $temp_dir
31+
32+
- name: Upload layer artifact
33+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
34+
with:
35+
path: .layers/datadog_lambda_node${{ matrix.node_version }}.zip
36+
name: datadog_lambda_node${{ matrix.node_version }}

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ jobs:
3838

3939
steps:
4040
- name: Checkout repository
41-
uses: actions/checkout@v3
41+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
4242

4343
# Initializes the CodeQL tools for scanning.
4444
- name: Initialize CodeQL
45-
uses: github/codeql-action/init@v2
45+
uses: github/codeql-action/init@b8d3b6e8af63cde30bdc382c0bc28114f4346c88 # v2.28.1
4646
with:
4747
languages: ${{ matrix.language }}
4848
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -53,7 +53,7 @@ jobs:
5353
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5454
# If this step fails, then you should remove it and run the build manually (see below)
5555
- name: Autobuild
56-
uses: github/codeql-action/autobuild@v2
56+
uses: github/codeql-action/autobuild@b8d3b6e8af63cde30bdc382c0bc28114f4346c88 # v2.28.1
5757

5858
# ℹ️ Command-line programs to run using the OS shell.
5959
# 📚 https://git.io/JvXDl
@@ -67,4 +67,4 @@ jobs:
6767
# make release
6868

6969
- name: Perform CodeQL Analysis
70-
uses: github/codeql-action/analyze@v2
70+
uses: github/codeql-action/analyze@b8d3b6e8af63cde30bdc382c0bc28114f4346c88 # v2.28.1

.github/workflows/update-deps.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ jobs:
1818
app-id: ${{ secrets.GH_APP_ID }}
1919
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
2020

21-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
2222
with:
2323
token: ${{ steps.generate_token.outputs.token }}
2424

25-
- uses: actions/setup-node@v3
25+
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3.9.1
2626
with:
2727
node-version: "20.x"
2828

@@ -32,7 +32,7 @@ jobs:
3232
yarn upgrade
3333
3434
- name: Create Pull Request
35-
uses: peter-evans/create-pull-request@v3
35+
uses: peter-evans/create-pull-request@18f7dc018cc2cd597073088f7c7591b9d1c02672 # v3.14.0
3636
with:
3737
token: ${{ steps.generate_token.outputs.token }}
3838
commit-message: update dependencies

.github/workflows/update-snapshots.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout
11-
uses: actions/checkout@v3
11+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
1212

1313
- name: Set up Node 14
14-
uses: actions/setup-node@v3
14+
uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3.9.1
1515
with:
1616
node-version: 14
1717

1818
- name: Set up Docker Buildx
1919
id: buildx
20-
uses: docker/setup-buildx-action@v2
20+
uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2.10.0
2121

2222
- name: Complete Buildx Setup
2323
run: docker run --privileged --rm tonistiigi/binfmt --install all
@@ -28,7 +28,7 @@ jobs:
2828

2929
- name: Restore node modules from cache
3030
id: cache-node-modules
31-
uses: actions/cache@v3
31+
uses: actions/cache@6f8efc29b200d32929f49075959781ed54ec270c # v3.5.0
3232
with:
3333
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
3434
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
@@ -52,7 +52,7 @@ jobs:
5252
run: ./scripts/run_integration_tests.sh
5353

5454
- name: Create Pull Request
55-
uses: peter-evans/create-pull-request@v3
55+
uses: peter-evans/create-pull-request@18f7dc018cc2cd597073088f7c7591b9d1c02672 # v3.14.0
5656
with:
5757
commit-message: update snapshots
5858
title: Update Snapshots

.gitlab-ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ ci image:
1010
stage: build
1111
image: registry.ddbuild.io/images/docker:20.10
1212
tags: ["arch:arm64"]
13+
id_tokens:
14+
DDSIGN_ID_TOKEN:
15+
aud: image-integrity
1316
needs: []
1417
rules:
1518
- if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"'
@@ -19,7 +22,9 @@ ci image:
1922
variables:
2023
DOCKER_TARGET: ${DOCKER_TARGET_IMAGE}:${DOCKER_TARGET_VERSION}
2124
script:
22-
- docker buildx build --platform linux/amd64,linux/arm64 --no-cache --pull --push --tag ${DOCKER_TARGET} -f .gitlab/Dockerfile .
25+
- METADATA_FILE=$(mktemp)
26+
- docker buildx build --platform linux/amd64,linux/arm64 --no-cache --pull ---tag ${DOCKER_TARGET} -f .gitlab/Dockerfile -push --metadata-file ${METADATA_FILE} .
27+
- ddsign sign ${DOCKER_TARGET} --docker-metadata-file ${METADATA_FILE}
2328

2429
.go-cache: &go-cache
2530
key: datadog-lambda-js-go-cache

.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)