Skip to content

Commit 1cbae34

Browse files
authored
Move self-monitoring layers and private images to serverless-testing (093468662994) (#1183)
## Overview Move both self-monitoring **layers** and **container images** from the sandbox account (`425362996713`) to the serverless-testing account (`093468662994`), where the LOD/LMI self-monitoring runtimes live. Eliminates cross-account ECR pulls during CDK Docker builds *and* the cross-account Lambda layer query in the image build script. After this PR, the self-monitoring test artifacts are entirely self-contained in `093468662994`. The regular `publish layer sandbox` and `publish layer prod` jobs are untouched. ### Changes - **`environments.yaml`**: add `serverless_testing` environment for `093468662994` (assumes role `layer-deployer`, externalId `serverless-testing-publish-externalid`, mirrors `automatically_bump_version: 1` / `add_layer_version_permissions: 0` from sandbox) - **`pipeline.yaml.tpl`** — two job changes: - `publish private images`: switch from `sandbox` env → `serverless_testing` env (push to new ECR) - `publish layer [self-monitoring]`: switch from `sandbox` env → `serverless_testing` env (publish Datadog-Extension layer to `093468662994` in us-east-1 + us-west-2) - **`build_private_image.sh`**: - Push to `093468662994.dkr.ecr.us-east-1.amazonaws.com/datadog-lambda-extension` (parameterizable via `PRIVATE_IMAGE_ECR_ACCOUNT` / `PRIVATE_IMAGE_ECR_REPO`) - Drop the cross-account `arn:aws:lambda:us-east-1:425362996713:layer:…` lookup. Query the same account we publish to — works because `publish layer [self-monitoring]` now lives in that account too. ### Prerequisites - ECR repo `datadog-lambda-extension` in `093468662994` — created by [`serverless-self-monitoring#637`](DataDog/serverless-self-monitoring#637) (LVU CDK), already deployed manually - IAM role `layer-deployer` in `093468662994` with Lambda layer publish + ECR push perms — created by [`cloud-inventory#59058`](DataDog/cloud-inventory#59058), already merged - Vault key `serverless-testing-publish-externalid` at `kv/k8s/gitlab-runner/datadog-lambda-extension/secrets` — created manually ### Knock-on for serverless-self-monitoring Layer-version-updater (`latest-dev.json`) currently pins `Datadog-Extension` to `arn:aws:lambda:us-east-1:425362996713:layer:Datadog-Extension:…`. After this PR's first run, the next "self-monitoring" extension layer is published to `093468662994` instead — LVU will need to learn to query `093468662994` for the Datadog-Extension dev layer. Tracked as a follow-up; safe because the existing `425362996713` layers don't disappear, they just stop receiving new versions from the `[self-monitoring]` job. ## Testing - [ ] Generated pipeline YAML has `serverless_testing` environment for both `publish private images` and `publish layer [self-monitoring]` - [ ] Trigger manual `publish layer [self-monitoring]` on a test pipeline → confirm Datadog-Extension layer published in `093468662994` (us-east-1, us-west-2) - [ ] Trigger manual `publish private images` on the same pipeline → confirm image pushed to `093468662994/datadog-lambda-extension:<VERSION>` with version matching the layer just published - [ ] Verify LOD/LMI can pull from `093468662994` ECR during CDK deploy
1 parent 2bea5ba commit 1cbae34

4 files changed

Lines changed: 44 additions & 17 deletions

File tree

.gitlab/datasources/environments.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ environments:
55
account: 425362996713
66
add_layer_version_permissions: 0
77
automatically_bump_version: 1
8+
serverless_testing:
9+
external_id: serverless-testing-publish-externalid
10+
role_to_assume: layer-deployer
11+
# Quoted: account starts with leading zero. Without quotes the YAML/gomplate
12+
# pipeline parses it as a float and substitutes "9.3468662994e+10", which
13+
# then forms an invalid role ARN in get_secrets.sh.
14+
account: "093468662994"
15+
add_layer_version_permissions: 0
16+
automatically_bump_version: 1
817
prod:
918
external_id: prod-publish-externalid
1019
role_to_assume: dd-serverless-layer-deployer-role

.gitlab/scripts/build_private_image.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
set -e
99

10-
DOCKER_TARGET_IMAGE="425362996713.dkr.ecr.us-east-1.amazonaws.com/self-monitoring-lambda-extension"
10+
# ECR target for private extension images, used by self-monitoring container runtimes.
11+
# Defaults to the serverless-testing account's datadog-lambda-extension repo.
12+
PRIVATE_IMAGE_ECR_ACCOUNT="${PRIVATE_IMAGE_ECR_ACCOUNT:-093468662994}"
13+
PRIVATE_IMAGE_ECR_REPO="${PRIVATE_IMAGE_ECR_REPO:-datadog-lambda-extension}"
14+
DOCKER_TARGET_IMAGE="${PRIVATE_IMAGE_ECR_ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/${PRIVATE_IMAGE_ECR_REPO}"
1115
EXTENSION_DIR=".layers"
1216
IMAGE_TAG="latest"
1317

14-
printf "Authenticating Docker to ECR...\n"
15-
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 425362996713.dkr.ecr.us-east-1.amazonaws.com
18+
printf "Authenticating Docker to ECR (%s)...\n" "$PRIVATE_IMAGE_ECR_ACCOUNT"
19+
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin "${PRIVATE_IMAGE_ECR_ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com"
1620

17-
# NOTE: this probably does not work the way that we expect it to, especially
18-
# when suffixes are involved. This is a known bug but we don't really check
19-
# anything other than the basic `self-monitoring-lambda-extension:latest` image
20-
# in our self-monitoring, so it's not a thing we're going to fix right now.
2121
LAYER_NAME="Datadog-Extension"
2222
if [ -z "$PIPELINE_LAYER_SUFFIX" ]; then
2323
printf "Building container images tagged without suffix\n"
@@ -27,7 +27,7 @@ else
2727
fi
2828

2929
# Increment last version
30-
latest_version=$(aws lambda list-layer-versions --region us-east-1 --layer-name $LAYER_NAME --query 'LayerVersions[0].Version || `0`')
30+
latest_version=$(aws lambda list-layer-versions --region us-east-1 --layer-name "$LAYER_NAME" --query 'LayerVersions[0].Version || `0`')
3131
VERSION=$(($latest_version + 1))
3232
printf "Tagging container image with version: $VERSION and latest\n"
3333

.gitlab/scripts/get_secrets.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ export DD_APP_KEY=$(vault kv get -field=dd-app-key kv/k8s/gitlab-runner/datadog-
3333

3434
printf "Assuming role...\n"
3535

36+
# Use --external-id= (with =) so the value is one argument and not parsed as
37+
# a separate option. Matters when the externalId starts with '-' (which the
38+
# layer-deployer role's externalId does).
3639
export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \
3740
$(aws sts assume-role \
3841
--role-arn "arn:aws:iam::$AWS_ACCOUNT:role/$ROLE_TO_ASSUME" \
3942
--role-session-name "ci.datadog-lambda-extension-$CI_JOB_ID-$CI_JOB_STAGE" \
4043
--query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \
41-
--external-id $EXTERNAL_ID \
44+
--external-id="$EXTERNAL_ID" \
4245
--output text))

.gitlab/templates/pipeline.yaml.tpl

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ publish layer {{ $environment_name }} ({{ $flavor.name }}):
198198

199199
{{ end }} # end environments
200200

201+
# Self-monitoring layer publishing — split by region/account inside one matrix:
202+
# us-east-1 → serverless-testing account (093468662994), used by LOD/LMI
203+
# us-west-2 → sandbox account (425362996713), used by E2E tests
204+
# Region-specific env values are injected per matrix row so the parallel jobs
205+
# still collapse into a single group in the GitLab UI.
201206
publish layer [self-monitoring] ({{ $flavor.name }}):
202207
stage: self-monitoring
203208
tags: ["arch:amd64"]
@@ -207,22 +212,32 @@ publish layer [self-monitoring] ({{ $flavor.name }}):
207212
allow_failure: true
208213
parallel:
209214
matrix:
210-
- REGION: us-east-1 # Self Monitoring
211-
- REGION: us-west-2 # E2E Testing
215+
{{ with $environment := (ds "environments").environments.serverless_testing }}
216+
- REGION: us-east-1
217+
EXTERNAL_ID_NAME: {{ $environment.external_id }}
218+
ROLE_TO_ASSUME: {{ $environment.role_to_assume }}
219+
AWS_ACCOUNT: "{{ $environment.account }}"
220+
{{ end }}
221+
{{ with $environment := (ds "environments").environments.sandbox }}
222+
- REGION: us-west-2
223+
EXTERNAL_ID_NAME: {{ $environment.external_id }}
224+
ROLE_TO_ASSUME: {{ $environment.role_to_assume }}
225+
AWS_ACCOUNT: "{{ $environment.account }}"
226+
{{ end }}
212227
needs:
213228
- layer ({{ $flavor.name }})
214229
dependencies:
215230
- layer ({{ $flavor.name }})
216-
{{ with $environment := (ds "environments").environments.sandbox }}
217231
variables:
218232
LAYER_NAME_BASE_SUFFIX: {{ $flavor.layer_name_base_suffix }}
219233
ARCHITECTURE: {{ $flavor.arch }}
220234
LAYER_FILE: datadog_extension-{{ $flavor.suffix }}.zip
221-
ADD_LAYER_VERSION_PERMISSIONS: {{ $environment.add_layer_version_permissions }}
222-
AUTOMATICALLY_BUMP_VERSION: {{ $environment.automatically_bump_version }}
235+
# Both target environments agree on these flags; if they ever diverge,
236+
# move them into the matrix above alongside the account/role.
237+
ADD_LAYER_VERSION_PERMISSIONS: 0
238+
AUTOMATICALLY_BUMP_VERSION: 1
223239
before_script:
224-
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
225-
{{ end }}
240+
- source .gitlab/scripts/get_secrets.sh
226241
script:
227242
- .gitlab/scripts/publish_layers.sh
228243

@@ -322,7 +337,7 @@ publish private images ({{ $multi_arch_image_flavor.name }}):
322337
variables:
323338
SUFFIX: {{ $multi_arch_image_flavor.suffix }}
324339
before_script:
325-
{{ with $environment := (ds "environments").environments.sandbox }}
340+
{{ with $environment := (ds "environments").environments.serverless_testing }}
326341
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
327342
{{ end }}
328343
script:

0 commit comments

Comments
 (0)