77
88set -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} "
1115EXTENSION_DIR=" .layers"
1216IMAGE_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.
2121LAYER_NAME=" Datadog-Extension"
2222if [ -z " $PIPELINE_LAYER_SUFFIX " ]; then
2323 printf " Building container images tagged without suffix\n"
2626 LAYER_NAME=" ${LAYER_NAME} -${PIPELINE_LAYER_SUFFIX} "
2727fi
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`' )
3134VERSION=$(( $latest_version + 1 ))
3235printf " 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"
0 commit comments