Skip to content

Commit d8e7165

Browse files
committed
Publish private extension images to serverless-testing account
Update build_private_image.sh to push to 093468662994 (serverless-testing) instead of 425362996713 (sandbox). The self-monitoring container runtimes (LOD, LMI) run in 093468662994, so co-locating the extension images there removes the need for cross-account ECR pulls during CDK Docker builds.
1 parent bb761fb commit d8e7165

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

.gitlab/datasources/environments.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ 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: lambda-extension-image-publisher
11+
account: 093468662994
812
prod:
913
external_id: prod-publish-externalid
1014
role_to_assume: dd-serverless-layer-deployer-role

.gitlab/scripts/build_private_image.sh

Lines changed: 13 additions & 10 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"
@@ -26,8 +26,11 @@ else
2626
LAYER_NAME="${LAYER_NAME}-${PIPELINE_LAYER_SUFFIX}"
2727
fi
2828

29-
# Increment last version
30-
latest_version=$(aws lambda list-layer-versions --region us-east-1 --layer-name $LAYER_NAME --query 'LayerVersions[0].Version || `0`')
29+
# Get the latest published layer version to derive the image tag.
30+
# Layers are published in the sandbox account (425362996713), so query there
31+
# regardless of which account we're pushing images to.
32+
SANDBOX_ACCOUNT="425362996713"
33+
latest_version=$(aws lambda list-layer-versions --region us-east-1 --layer-name "arn:aws:lambda:us-east-1:${SANDBOX_ACCOUNT}:layer:${LAYER_NAME}" --query 'LayerVersions[0].Version || `0`')
3134
VERSION=$(($latest_version + 1))
3235
printf "Tagging container image with version: $VERSION and latest\n"
3336

@@ -39,4 +42,4 @@ docker buildx build \
3942
--tag "$DOCKER_TARGET_IMAGE:${VERSION}${SUFFIX}" \
4043
--push .
4144

42-
printf "Image built and pushed to $DOCKER_TARGET_IMAGE:${IMAGE_TAG}${SUFFIX} for ${PLATFORM}\n"
45+
printf "Image built and pushed to $DOCKER_TARGET_IMAGE:${IMAGE_TAG}${SUFFIX}\n"

.gitlab/templates/pipeline.yaml.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ publish private images ({{ $multi_arch_image_flavor.name }}):
235235
variables:
236236
SUFFIX: {{ $multi_arch_image_flavor.suffix }}
237237
before_script:
238-
{{ with $environment := (ds "environments").environments.sandbox }}
238+
{{ with $environment := (ds "environments").environments.serverless_testing }}
239239
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
240240
{{ end }}
241241
script:

0 commit comments

Comments
 (0)