Skip to content

Commit 9534c00

Browse files
authored
feat: use multiple processes to publish layers (#438)
* feat: use multiple processes to publish layers * feat: Remove region arg
1 parent fbe67f7 commit 9534c00

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

scripts/publish_layers.sh

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ NODE_VERSIONS_FOR_AWS_CLI=("nodejs14.x" "nodejs16.x" "nodejs18.x")
1414
LAYER_PATHS=(".layers/datadog_lambda_node14.15.zip" ".layers/datadog_lambda_node16.14.zip" ".layers/datadog_lambda_node18.12.zip")
1515
AVAILABLE_LAYERS=("Datadog-Node14-x" "Datadog-Node16-x" "Datadog-Node18-x")
1616
AVAILABLE_REGIONS=$(aws ec2 describe-regions | jq -r '.[] | .[] | .RegionName')
17+
BATCH_SIZE=60
18+
PIDS=()
19+
20+
# Makes sure any subprocesses will be terminated with this process
21+
trap "pkill -P $$; exit 1;" INT
1722

1823
# Check that the layer files exist
1924
for layer_file in "${LAYER_PATHS[@]}"
@@ -99,6 +104,34 @@ publish_layer() {
99104
echo $version_nbr
100105
}
101106

107+
wait_for_processes() {
108+
for pid in "${PIDS[@]}"; do
109+
wait $pid
110+
done
111+
PIDS=()
112+
}
113+
114+
backfill_layers() {
115+
latest_version=$1
116+
region=$2
117+
layer_name=$3
118+
aws_version_key=$4
119+
layer_path=$5
120+
while [ $latest_version -lt $VERSION ]; do
121+
latest_version=$(publish_layer $region $layer_name $aws_version_key $layer_path)
122+
echo "Published version $latest_version for layer $layer_name in region $region"
123+
124+
# This shouldn't happen unless someone manually deleted the latest version, say 28, and
125+
# then tries to republish 28 again. The published version would actually be 29, because
126+
# Lambda layers are immutable and AWS will skip deleted version and use the next number.
127+
if [ $latest_version -gt $VERSION ]; then
128+
echo "ERROR: Published version $latest_version is greater than the desired version $VERSION!"
129+
echo "Exiting"
130+
exit 1
131+
fi
132+
done
133+
}
134+
102135
for region in $REGIONS
103136
do
104137
echo "Starting publishing layer for region $region..."
@@ -109,31 +142,19 @@ do
109142
echo "Layer $layer_name version $VERSION already exists in region $region, skipping..."
110143
continue
111144
elif [ $latest_version -lt $((VERSION-1)) ]; then
112-
read -p "WARNING: The latest version of layer $layer_name in region $region is $latest_version, publish all the missing versions including $VERSION or EXIT the script (y/n)?" CONT
113-
if [ "$CONT" != "y" ]; then
114-
echo "Exiting"
115-
exit 1
116-
fi
145+
echo "WARNING: The latest version of layer $layer_name in region $region is $latest_version, this will publish all the missing versions including $VERSION"
117146
fi
118147

119148
index=$(index_of_layer $layer_name)
120149
aws_version_key="${NODE_VERSIONS_FOR_AWS_CLI[$index]}"
121150
layer_path="${LAYER_PATHS[$index]}"
122151

123-
while [ $latest_version -lt $VERSION ]; do
124-
latest_version=$(publish_layer $region $layer_name $aws_version_key $layer_path)
125-
echo "Published version $latest_version for layer $layer_name in region $region"
126-
127-
# This shouldn't happen unless someone manually deleted the latest version, say 28, and
128-
# then tries to republish 28 again. The published version would actually be 29, because
129-
# Lambda layers are immutable and AWS will skip deleted version and use the next number.
130-
if [ $latest_version -gt $VERSION ]; then
131-
echo "ERROR: Published version $latest_version is greater than the desired version $VERSION!"
132-
echo "Exiting"
133-
exit 1
134-
fi
135-
done
152+
backfill_layers $latest_version $region $layer_name $aws_version_key $layer_path &
153+
PIDS+=($!)
154+
if [ ${#PIDS[@]} -eq $BATCH_SIZE ]; then
155+
wait_for_processes
156+
fi
136157
done
137158
done
138-
159+
wait_for_processes
139160
echo "Done !"

scripts/publish_sandbox.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if [ -z "$VERSION" ]; then
1010
fi
1111

1212
./scripts/build_layers.sh
13-
VERSION=$VERSION REGIONS=sa-east-1 ./scripts/publish_layers.sh
13+
VERSION=$VERSION ./scripts/publish_layers.sh
1414

1515
# Automatically create PR against github.com/DataDog/documentation
1616
# If you'd like to test, please uncomment the below line

0 commit comments

Comments
 (0)