Skip to content

Commit 97cc029

Browse files
chore: new gov publish script
1 parent 94f4aa4 commit 97cc029

File tree

2 files changed

+135
-6
lines changed

2 files changed

+135
-6
lines changed

ci/publish_layers.sh

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,20 @@ AWS_CLI_PYTHON_VERSIONS=(
2424
"python3.13"
2525
"python3.13"
2626
)
27-
PYTHON_VERSIONS=("3.8-amd64" "3.8-arm64" "3.9-amd64" "3.9-arm64" "3.10-amd64" "3.10-arm64" "3.11-amd64" "3.11-arm64" "3.12-amd64" "3.12-arm64" "3.13-amd64" "3.13-arm64")
27+
PYTHON_VERSIONS=(
28+
"3.8-amd64"
29+
"3.8-arm64"
30+
"3.9-amd64"
31+
"3.9-arm64"
32+
"3.10-amd64"
33+
"3.10-arm64"
34+
"3.11-amd64"
35+
"3.11-arm64"
36+
"3.12-amd64"
37+
"3.12-arm64"
38+
"3.13-amd64"
39+
"3.13-arm64"
40+
)
2841
LAYER_PATHS=(
2942
".layers/datadog_lambda_py-amd64-3.8.zip"
3043
".layers/datadog_lambda_py-arm64-3.8.zip"
@@ -53,11 +66,16 @@ LAYERS=(
5366
"Datadog-Python313"
5467
"Datadog-Python313-ARM"
5568
)
56-
STAGES=('prod', 'sandbox', 'staging')
69+
STAGES=('prod', 'sandbox', 'staging', 'gov-staging', 'gov-prod')
5770

5871
printf "Starting script...\n\n"
59-
printf "Installing dependencies\n"
60-
pip install awscli
72+
73+
if [ -z "$SKIP_PIP_INSTALL" ]; then
74+
echo "Installing dependencies"
75+
pip install awscli
76+
else
77+
echo "Skipping pip install"
78+
fi
6179

6280
publish_layer() {
6381
region=$1
@@ -89,7 +107,7 @@ fi
89107

90108
printf "Python version specified: $PYTHON_VERSION\n"
91109
if [[ ! ${PYTHON_VERSIONS[@]} =~ $PYTHON_VERSION ]]; then
92-
printf "[Error] Unsupported PYTHON_VERSION found.\n"
110+
printf "[Error] Unsupported PYTHON_VERSION found: $PYTHON_VERSION.\n"
93111
exit 1
94112
fi
95113

@@ -133,8 +151,14 @@ if [[ ! ${STAGES[@]} =~ $STAGE ]]; then
133151
fi
134152

135153
layer="${LAYERS[$index]}"
154+
if [ -z "$LAYER_NAME_SUFFIX" ]; then
155+
echo "No layer name suffix"
156+
else
157+
layer="${layer}-${LAYER_NAME_SUFFIX}"
158+
fi
159+
echo "layer name: $layer"
136160

137-
if [[ "$STAGE" =~ ^(staging|sandbox)$ ]]; then
161+
if [[ "$STAGE" =~ ^(staging|sandbox|gov-staging)$ ]]; then
138162
# Deploy latest version
139163
latest_version=$(aws lambda list-layer-versions --region $REGION --layer-name $layer --query 'LayerVersions[0].Version || `0`')
140164
VERSION=$(($latest_version + 1))

scripts/publish_govcloud.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#! /usr/bin/env bash
2+
3+
# Unless explicitly stated otherwise all files in this repository are licensed
4+
# under the Apache License Version 2.0.
5+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
6+
# Copyright 2025 Datadog, Inc.
7+
#
8+
# USAGE: download the layer bundle from the build pipeline in gitlab. Use the
9+
# Download button on the `layer bundle` job. This will be a zip file containing
10+
# all of the required layers. Run this script as follows:
11+
#
12+
# ENVIRONMENT=[us1-staging-fed or us1-fed] [LAYER_NAME_SUFFIX=optional-layer-suffix] [REGIONS=us-gov-west-1] ./scripts/publish_govcloud.sh <layer-bundle.zip>
13+
#
14+
# protip: you can drag the zip file from finder into your terminal to insert
15+
# its path.
16+
17+
set -e
18+
19+
LAYER_PACKAGE=$1
20+
21+
if [ -z "$LAYER_PACKAGE" ]; then
22+
printf "[ERROR]: layer package not provided\n"
23+
exit 1
24+
fi
25+
26+
PACKAGE_NAME=$(basename "$LAYER_PACKAGE" .zip)
27+
28+
if [ -z "$ENVIRONMENT" ]; then
29+
printf "[ERROR]: ENVIRONMENT not specified\n"
30+
exit 1
31+
fi
32+
33+
if [ "$ENVIRONMENT" = "us1-staging-fed" ]; then
34+
AWS_VAULT_ROLE=sso-govcloud-us1-staging-fed-power-user
35+
36+
export STAGE=gov-staging
37+
38+
if [[ ! "$PACKAGE_NAME" =~ ^datadog_lambda_py-(signed-)?bundle-[0-9]+$ ]]; then
39+
echo "[ERROR]: Unexpected package name: $PACKAGE_NAME"
40+
exit 1
41+
fi
42+
43+
elif [ $ENVIRONMENT = "us1-fed" ]; then
44+
AWS_VAULT_ROLE=sso-govcloud-us1-fed-engineering
45+
46+
export STAGE=gov-prod
47+
48+
if [[ ! "$PACKAGE_NAME" =~ ^datadog_lambda_py-signed-bundle-[0-9]+$ ]]; then
49+
echo "[ERROR]: Unexpected package name: $PACKAGE_NAME"
50+
exit 1
51+
fi
52+
53+
else
54+
printf "[ERROR]: ENVIRONMENT not supported, must be us1-staging-fed or us1-fed.\n"
55+
exit 1
56+
fi
57+
58+
TEMP_DIR=$(mktemp -d)
59+
unzip $LAYER_PACKAGE -d $TEMP_DIR
60+
cp -v $TEMP_DIR/$PACKAGE_NAME/*.zip .layers/
61+
62+
63+
AWS_VAULT_PREFIX="aws-vault exec $AWS_VAULT_ROLE --"
64+
65+
echo "Checking that you have access to the GovCloud AWS account"
66+
$AWS_VAULT_PREFIX aws sts get-caller-identity
67+
68+
69+
AVAILABLE_REGIONS=$($AWS_VAULT_PREFIX aws ec2 describe-regions | jq -r '.[] | .[] | .RegionName')
70+
71+
# Determine the target regions
72+
if [ -z "$REGIONS" ]; then
73+
echo "Region not specified, running for all available regions."
74+
REGIONS=$AVAILABLE_REGIONS
75+
else
76+
echo "Region specified: $REGIONS"
77+
if [[ ! "$AVAILABLE_REGIONS" == *"$REGIONS"* ]]; then
78+
echo "Could not find $REGIONS in available regions: $AVAILABLE_REGIONS"
79+
echo ""
80+
echo "EXITING SCRIPT."
81+
exit 1
82+
fi
83+
fi
84+
85+
for region in $REGIONS
86+
do
87+
echo "Starting publishing layers for region $region..."
88+
89+
export REGION=$region
90+
91+
for python_version in "3.8" "3.9" "3.10" "3.11" "3.12" "3.13"; do
92+
for arch in "amd64" "arm64"; do
93+
export PYTHON_VERSION=$python_version
94+
export ARCH=$arch
95+
96+
export SKIP_PIP_INSTALL=true
97+
98+
echo "Publishing layer for $PYTHON_VERSION and $ARCH"
99+
100+
$AWS_VAULT_PREFIX ./ci/publish_layers.sh
101+
done
102+
done
103+
done
104+
105+
echo "Done !"

0 commit comments

Comments
 (0)