Skip to content

Commit 0fb7584

Browse files
committed
update versions
1 parent eeb7284 commit 0fb7584

File tree

2 files changed

+87
-22
lines changed

2 files changed

+87
-22
lines changed

.gitlab/scripts/publish_layers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ publish_layer() {
4343
compatible_architectures=$4
4444

4545
version_nbr=$(aws lambda publish-layer-version --layer-name $layer \
46-
--description "Datadog Lambda Extension" \
46+
--description "${LAYER_DESCRIPTION:-Datadog Lambda Extension}" \
4747
--compatible-architectures $compatible_architectures \
4848
--zip-file "fileb://${file}" \
4949
--region $region \

.gitlab/templates/pipeline.yaml.tpl

Lines changed: 86 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,48 @@ publish integration layer (arm64):
424424
{{ with $environment := (ds "environments").environments.sandbox }}
425425
before_script:
426426
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
427-
- export PIPELINE_LAYER_SUFFIX="ARM-${CI_COMMIT_SHORT_SHA}"
428-
- echo "Publishing layer with suffix - ${PIPELINE_LAYER_SUFFIX}"
427+
# Use fixed layer suffix for integration tests
428+
- export PIPELINE_LAYER_SUFFIX="IntegTests-ARM"
429+
# Set description to just the commit SHA
430+
- export LAYER_DESCRIPTION="${CI_COMMIT_SHORT_SHA}"
431+
- echo "Publishing to layer Datadog-Extension-IntegTests-ARM with commit SHA ${LAYER_DESCRIPTION}"
429432
script:
430433
- .gitlab/scripts/publish_layers.sh
431-
- LAYER_ARN=$(aws lambda list-layer-versions --layer-name "Datadog-Extension-ARM-${CI_COMMIT_SHORT_SHA}" --query 'LayerVersions[0].LayerVersionArn' --output text --region us-east-1)
432-
- echo "Published layer ARN - ${LAYER_ARN}"
434+
# Find the version we just published by matching commit SHA in description
435+
- |
436+
LAYER_NAME="Datadog-Extension-IntegTests-ARM"
437+
COMMIT_SHA="${CI_COMMIT_SHORT_SHA}"
438+
439+
echo "Searching for layer version with commit SHA: ${COMMIT_SHA}"
440+
441+
# List all versions and find the one with our commit SHA as the description
442+
LAYER_INFO=$(aws lambda list-layer-versions \
443+
--layer-name "${LAYER_NAME}" \
444+
--region us-east-1 \
445+
--query "LayerVersions[?Description=='${COMMIT_SHA}'].[Version, LayerVersionArn, Description] | [0]" \
446+
--output json)
447+
448+
if [ "$LAYER_INFO" = "null" ] || [ -z "$LAYER_INFO" ]; then
449+
echo "ERROR: Could not find layer version with commit SHA ${COMMIT_SHA}"
450+
echo "Available versions:"
451+
aws lambda list-layer-versions --layer-name "${LAYER_NAME}" --region us-east-1 --query 'LayerVersions[*].[Version, Description]' --output table
452+
exit 1
453+
fi
454+
455+
LAYER_VERSION=$(echo "$LAYER_INFO" | jq -r '.[0]')
456+
LAYER_ARN=$(echo "$LAYER_INFO" | jq -r '.[1]')
457+
LAYER_DESC=$(echo "$LAYER_INFO" | jq -r '.[2]')
458+
459+
echo "Found layer version ${LAYER_VERSION} with ARN ${LAYER_ARN}"
460+
echo "Description: ${LAYER_DESC}"
461+
462+
# Export for use by integration tests via dotenv artifact
463+
echo "EXTENSION_LAYER_ARN=${LAYER_ARN}" >> layer.env
464+
echo "LAYER_VERSION=${LAYER_VERSION}" >> layer.env
465+
echo "COMMIT_SHA=${COMMIT_SHA}" >> layer.env
466+
artifacts:
467+
reports:
468+
dotenv: layer.env
433469
{{ end }}
434470

435471
# Integration Tests - Deploy, test, and cleanup each suite independently (parallel by test suite)
@@ -443,7 +479,8 @@ integration-suite:
443479
rules:
444480
- when: on_success
445481
needs:
446-
- publish integration layer (arm64)
482+
- job: publish integration layer (arm64)
483+
artifacts: true
447484
- build java lambdas
448485
- build dotnet lambdas
449486
- build python lambdas
@@ -468,8 +505,16 @@ integration-suite:
468505
script:
469506
# Deploy
470507
- echo "Deploying ${TEST_SUITE} CDK stack with identifier ${IDENTIFIER}..."
471-
- export EXTENSION_LAYER_ARN=$(aws lambda list-layer-versions --layer-name "Datadog-Extension-ARM-${CI_COMMIT_SHORT_SHA}" --query 'LayerVersions[0].LayerVersionArn' --output text --region us-east-1)
472-
- echo "Using integration test layer - ${EXTENSION_LAYER_ARN}"
508+
# EXTENSION_LAYER_ARN is available from the dotenv artifact (passed from publish job)
509+
- echo "Using integration test layer - ${EXTENSION_LAYER_ARN} (version ${LAYER_VERSION}, commit ${COMMIT_SHA})"
510+
# Validate the layer ARN is set
511+
- |
512+
if [ -z "$EXTENSION_LAYER_ARN" ]; then
513+
echo "ERROR: EXTENSION_LAYER_ARN not set from publish job dotenv artifact"
514+
echo "This indicates the publish job failed to export the layer ARN"
515+
exit 1
516+
fi
517+
echo "✓ Layer ARN inherited from publish job"
473518
- export CDK_DEFAULT_ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
474519
- export CDK_DEFAULT_REGION=us-east-1
475520
- npm run build
@@ -514,7 +559,7 @@ integration-suite:
514559
junit: integration-tests/test-results/junit-*.xml
515560
expire_in: 30 days
516561

517-
# Integration Tests - Cleanup layer
562+
# Integration Tests - Cleanup old layer versions
518563
integration-cleanup-layer:
519564
stage: integration-tests
520565
tags: ["arch:amd64"]
@@ -524,28 +569,48 @@ integration-cleanup-layer:
524569
needs:
525570
- job: integration-suite
526571
variables:
527-
IDENTIFIER: ${CI_COMMIT_SHORT_SHA}
572+
LAYER_NAME: "Datadog-Extension-IntegTests-ARM"
573+
KEEP_VERSIONS: 500
528574
{{ with $environment := (ds "environments").environments.sandbox }}
529575
before_script:
530576
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
531577
{{ end }}
532578
script:
533-
- echo "Deleting integration test layer with identifier ${IDENTIFIER}..."
579+
- echo "Cleaning up old versions of ${LAYER_NAME}..."
534580
- |
535-
LAYER_NAME="Datadog-Extension-ARM-${IDENTIFIER}"
536-
echo "Looking for layer: ${LAYER_NAME}"
581+
# Get all layer versions sorted by version number (newest first)
582+
ALL_VERSIONS=$(aws lambda list-layer-versions \
583+
--layer-name "${LAYER_NAME}" \
584+
--query 'LayerVersions[*].Version' \
585+
--output text \
586+
--region us-east-1 2>/dev/null || echo "")
587+
588+
if [ -z "$ALL_VERSIONS" ]; then
589+
echo "No versions found for layer ${LAYER_NAME}"
590+
exit 0
591+
fi
537592

538-
# Get all versions of the layer
539-
VERSIONS=$(aws lambda list-layer-versions --layer-name "${LAYER_NAME}" --query 'LayerVersions[*].Version' --output text --region us-east-1 2>/dev/null || echo "")
593+
# Convert to array
594+
VERSION_ARRAY=($ALL_VERSIONS)
595+
TOTAL_VERSIONS=${#VERSION_ARRAY[@]}
540596

541-
if [ -z "$VERSIONS" ]; then
542-
echo "No versions found for layer ${LAYER_NAME}"
543-
else
544-
echo "Found versions: ${VERSIONS}"
545-
for VERSION in $VERSIONS; do
597+
echo "Found ${TOTAL_VERSIONS} versions of ${LAYER_NAME}"
598+
echo "Keeping the ${KEEP_VERSIONS} most recent versions"
599+
600+
# Delete old versions (keep only the most recent KEEP_VERSIONS)
601+
if [ $TOTAL_VERSIONS -gt $KEEP_VERSIONS ]; then
602+
VERSIONS_TO_DELETE=${VERSION_ARRAY[@]:$KEEP_VERSIONS}
603+
604+
for VERSION in $VERSIONS_TO_DELETE; do
546605
echo "Deleting ${LAYER_NAME} version ${VERSION}..."
547-
aws lambda delete-layer-version --layer-name "${LAYER_NAME}" --version-number "${VERSION}" --region us-east-1 || echo "Failed to delete version ${VERSION}, continuing..."
606+
aws lambda delete-layer-version \
607+
--layer-name "${LAYER_NAME}" \
608+
--version-number "${VERSION}" \
609+
--region us-east-1 || echo "Failed to delete version ${VERSION}, continuing..."
548610
done
549-
echo "Successfully deleted all versions of ${LAYER_NAME}"
611+
612+
echo "Successfully cleaned up old versions"
613+
else
614+
echo "Total versions (${TOTAL_VERSIONS}) <= keep versions (${KEEP_VERSIONS}), no cleanup needed"
550615
fi
551616

0 commit comments

Comments
 (0)