|
| 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