|
| 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-stagin-fed or us-fed] [WORKFLOW_LAYER_SUFFIX=optional-layer-suffix] [REGIONS=us-gov-west-1] ./scripts/publish_govcloud_layers.sh <layer-bundle.zip> |
| 13 | + |
| 14 | +set -e |
| 15 | + |
| 16 | +LAYER_PACKAGE=$1 |
| 17 | + |
| 18 | +if [ -z "$LAYER_PACKAGE" ]; then |
| 19 | + printf "[ERROR]: layer package not provided\n" |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +PACKAGE_NAME=$(basename "$LAYER_PACKAGE" .zip) |
| 24 | + |
| 25 | +if [ -z "$ENVIRONMENT" ]; then |
| 26 | + printf "[ERROR]: ENVIRONMENT not specified\n" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +if [ "$ENVIRONMENT" = "us1-staging-fed" ]; then |
| 31 | + AWS_VAULT_ROLE=sso-govcloud-us1-staging-fed-power-user |
| 32 | + |
| 33 | +# this role looks like this in ~/.aws/config: |
| 34 | +# [profile sso-govcloud-us1-staging-fed-power-user] |
| 35 | +# sso_start_url=https://start.us-gov-home.awsapps.com/directory/d-9867188aeb |
| 36 | +# sso_account_id=553727695824 |
| 37 | +# sso_role_name=power-user |
| 38 | +# sso_region=us-gov-west-1 |
| 39 | +# region=us-gov-west-1 |
| 40 | + |
| 41 | + export ADD_PERMISSIONS=0 |
| 42 | + export AUTOMATICALLY_BUMP_VERSION=1 |
| 43 | + |
| 44 | + if [[ ! "$PACKAGE_NAME" =~ ^datadog_extension-(signed-)?bundle-[0-9]+$ ]]; then |
| 45 | + echo "[ERROR]: Unexpected package name: $PACKAGE_NAME" |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + |
| 49 | +elif [ $ENVIRONMENT = "us1-fed" ]; then |
| 50 | + AWS_VAULT_ROLE=sso-govcloud-us1-fed-engineering |
| 51 | + |
| 52 | +# this role looks like this in ~/.aws/config: |
| 53 | +# [profile sso-govcloud-us1-fed-engineering] |
| 54 | +# sso_start_url=https://start.us-gov-west-1.us-gov-home.awsapps.com/directory/d-98671fdc8b |
| 55 | +# sso_account_id=002406178527 |
| 56 | +# sso_role_name=engineering |
| 57 | +# sso_region=us-gov-west-1 |
| 58 | +# region=us-gov-west-1 |
| 59 | + |
| 60 | + export ADD_PERMISSIONS=1 |
| 61 | + export AUTOMATICALLY_BUMP_VERSION=0 |
| 62 | + |
| 63 | + if [[ ! "$PACKAGE_NAME" =~ ^datadog_extension-signed-bundle-[0-9]+$ ]]; then |
| 64 | + echo "[ERROR]: Unexpected package name: $PACKAGE_NAME" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | + |
| 68 | +else |
| 69 | + printf "[ERROR]: ENVIRONMENT not supported, must be us1-staging-fed or us1-fed.\n" |
| 70 | + exit 1 |
| 71 | +fi |
| 72 | + |
| 73 | +TEMP_DIR=$(mktemp -d) |
| 74 | +unzip $LAYER_PACKAGE -d $TEMP_DIR |
| 75 | +cp -v $TEMP_DIR/$PACKAGE_NAME/*.zip .layers/ |
| 76 | + |
| 77 | + |
| 78 | +AWS_VAULT_PREFIX="aws-vault exec $AWS_VAULT_ROLE --" |
| 79 | + |
| 80 | +echo "Checking that you have access to the GovCloud AWS account" |
| 81 | +$AWS_VAULT_PREFIX aws sts get-caller-identity |
| 82 | + |
| 83 | + |
| 84 | +AVAILABLE_REGIONS=$($AWS_VAULT_PREFIX aws ec2 describe-regions | jq -r '.[] | .[] | .RegionName') |
| 85 | + |
| 86 | +# Determine the target regions |
| 87 | +if [ -z "$REGIONS" ]; then |
| 88 | + echo "Region not specified, running for all available regions." |
| 89 | + REGIONS=$AVAILABLE_REGIONS |
| 90 | +else |
| 91 | + echo "Region specified: $REGIONS" |
| 92 | + if [[ ! "$AVAILABLE_REGIONS" == *"$REGIONS"* ]]; then |
| 93 | + echo "Could not find $REGIONS in available regions: $AVAILABLE_REGIONS" |
| 94 | + echo "" |
| 95 | + echo "EXITING SCRIPT." |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | +fi |
| 99 | + |
| 100 | +declare -A flavors |
| 101 | + |
| 102 | +flavors["amd64"]="arch=amd64 suffix=amd64 layer_name_base_suffix=" |
| 103 | +flavors["arm64"]="arch=arm64 suffix=arm64 layer_name_base_suffix=-ARM" |
| 104 | +flavors["amd64-fips"]="arch=amd64 suffix=amd64-fips layer_name_base_suffix=-FIPS" |
| 105 | +flavors["arm64-fips"]="arch=arm64 suffix=arm64-fips layer_name_base_suffix=-FIPS-ARM" |
| 106 | +echo "$flavors" |
| 107 | + |
| 108 | + |
| 109 | +for region in $REGIONS |
| 110 | +do |
| 111 | + echo "Starting publishing layers for region $region..." |
| 112 | + |
| 113 | + export REGION=$region |
| 114 | + |
| 115 | + for flavor in "${!flavors[@]}"; do |
| 116 | + echo "Publishing $flavor" |
| 117 | + |
| 118 | + IFS=' ' read -r -a values <<< "${flavors[$flavor]}" |
| 119 | + for value in "${values[@]}"; do |
| 120 | + case $value in |
| 121 | + arch=*) export ARCHITECTURE="${value#arch=}" ;; |
| 122 | + suffix=*) SUFFIX="${value#suffix=}" ;; |
| 123 | + layer_name_base_suffix=*) export LAYER_NAME_BASE_SUFFIX="${value#layer_name_base_suffix=}" ;; |
| 124 | + esac |
| 125 | + done |
| 126 | + |
| 127 | + export LAYER_FILE="datadog_extension-$SUFFIX.zip" |
| 128 | + |
| 129 | + $AWS_VAULT_PREFIX .gitlab/scripts/publish_layer.sh |
| 130 | + done |
| 131 | + |
| 132 | +done |
| 133 | + |
| 134 | +echo "Done !" |
0 commit comments