@@ -25,7 +25,7 @@ wait_for_ami_to_be_available() {
25
25
local image_state
26
26
27
27
while true ; do
28
- image_state=$( aws ec2 describe-images --region " $region " --image-ids " $image_id " --output text --query ' Images[*].State' ) ;
28
+ image_state=$( aws ec2 describe-images --region " $region " --image-ids " $image_id " --output text --query ' Images[*].State' )
29
29
echo " $image_id ($region ) is $image_state "
30
30
31
31
if [[ " $image_state " == " available" ]]; then
@@ -43,10 +43,10 @@ get_image_name() {
43
43
local region=" $2 "
44
44
45
45
aws ec2 describe-images \
46
- --image-ids " $image_id " \
47
- --output text \
48
- --region " $region " \
49
- --query ' Images[*].Name'
46
+ --image-ids " $image_id " \
47
+ --output text \
48
+ --region " $region " \
49
+ --query ' Images[*].Name'
50
50
}
51
51
52
52
make_ami_public () {
@@ -59,7 +59,7 @@ make_ami_public() {
59
59
--launch-permission " {\" Add\" : [{\" Group\" :\" all\" }]}"
60
60
}
61
61
62
- if [[ -z " ${BUILDKITE_AWS_STACK_BUCKET} " ]] ; then
62
+ if [[ -z " ${BUILDKITE_AWS_STACK_BUCKET} " ]]; then
63
63
echo " Must set an s3 bucket in BUILDKITE_AWS_STACK_BUCKET for temporary files"
64
64
exit 1
65
65
fi
@@ -99,17 +99,17 @@ source_region="${AWS_REGION}"
99
99
mapping_file=" build/mappings.yml"
100
100
101
101
# Read the source images from meta-data if no arguments are provided
102
- if [ $# -eq 0 ] ; then
103
- linux_amd64_source_image_id=$( buildkite-agent meta-data get " linux_amd64_image_id" )
104
- linux_arm64_source_image_id=$( buildkite-agent meta-data get " linux_arm64_image_id" )
105
- windows_amd64_source_image_id=$( buildkite-agent meta-data get " windows_amd64_image_id" )
102
+ if [ $# -eq 0 ]; then
103
+ linux_amd64_source_image_id=$( buildkite-agent meta-data get " linux_amd64_image_id" )
104
+ linux_arm64_source_image_id=$( buildkite-agent meta-data get " linux_arm64_image_id" )
105
+ windows_amd64_source_image_id=$( buildkite-agent meta-data get " windows_amd64_image_id" )
106
106
fi
107
107
108
108
# If we're not on the main branch or a tag build skip the copy
109
109
if [[ $BUILDKITE_BRANCH != main ]] && [[ $BUILDKITE_TAG != " $BUILDKITE_BRANCH " ]] && [[ ${COPY_TO_ALL_REGIONS:- " false" } != " true" ]]; then
110
110
echo " --- Skipping AMI copy on non-main/tag branch " >&2
111
111
mkdir -p " $( dirname " $mapping_file " ) "
112
- cat << EOF > "$mapping_file "
112
+ cat << EOF >"$mapping_file "
113
113
Mappings:
114
114
AWSRegion2AMI:
115
115
${AWS_REGION} : { linuxamd64: $linux_amd64_source_image_id , linuxarm64: $linux_arm64_source_image_id , windows: $windows_amd64_source_image_id }
@@ -125,7 +125,7 @@ s3_mappings_cache=$(printf "s3://%s/mappings-%s-%s-%s-%s.yml" \
125
125
" ${BUILDKITE_BRANCH} " )
126
126
127
127
# Check if there is a previously copy in the cache bucket
128
- if aws s3 cp " ${s3_mappings_cache} " " $mapping_file " ; then
128
+ if aws s3 cp " ${s3_mappings_cache} " " $mapping_file " ; then
129
129
echo " --- Skipping AMI copy, was previously copied"
130
130
exit 0
131
131
fi
@@ -138,7 +138,7 @@ windows_amd64_source_image_name=$(get_image_name "$windows_amd64_source_image_id
138
138
# Copy to all other regions
139
139
# shellcheck disable=SC2048
140
140
for region in ${ALL_REGIONS[*]} ; do
141
- if [[ $region != " $source_region " ]] ; then
141
+ if [[ $region != " $source_region " ]]; then
142
142
echo " --- :linux: Copying Linux AMD64 $linux_amd64_source_image_id to $region " >&2
143
143
IMAGES+=(" $( copy_ami_to_region " $linux_amd64_source_image_id " " $source_region " " $region " " ${linux_amd64_source_image_name} -${region} " ) " )
144
144
@@ -154,12 +154,12 @@ done
154
154
155
155
# Write yaml preamble
156
156
mkdir -p " $( dirname " $mapping_file " ) "
157
- cat << EOF > "$mapping_file "
157
+ cat << EOF >"$mapping_file "
158
158
Mappings:
159
159
AWSRegion2AMI:
160
160
EOF
161
161
162
- echo " --- Waiting for AMIs to become available" >&2
162
+ echo " --- Waiting for AMIs to become available" >&2
163
163
# shellcheck disable=SC2048
164
164
for region in ${ALL_REGIONS[*]} ; do
165
165
linux_amd64_image_id=" ${IMAGES[0]} "
@@ -169,29 +169,29 @@ for region in ${ALL_REGIONS[*]}; do
169
169
wait_for_ami_to_be_available " $linux_amd64_image_id " " $region " >&2
170
170
171
171
# Make the linux AMI public if it's not the source image
172
- if [[ $linux_amd64_image_id != " $linux_amd64_source_image_id " ]] ; then
172
+ if [[ $linux_amd64_image_id != " $linux_amd64_source_image_id " ]]; then
173
173
echo " :linux: Making Linux AMD64 ${linux_amd64_image_id} public" >&2
174
174
make_ami_public " $linux_amd64_image_id " " $region "
175
175
fi
176
176
177
177
wait_for_ami_to_be_available " $linux_arm64_image_id " " $region " >&2
178
178
179
179
# Make the linux ARM AMI public if it's not the source image
180
- if [[ $linux_arm64_image_id != " $linux_arm64_source_image_id " ]] ; then
180
+ if [[ $linux_arm64_image_id != " $linux_arm64_source_image_id " ]]; then
181
181
echo " :linux: Making Linux ARM64 ${linux_arm64_image_id} public" >&2
182
182
make_ami_public " $linux_arm64_image_id " " $region "
183
183
fi
184
184
185
185
wait_for_ami_to_be_available " $windows_amd64_image_id " " $region " >&2
186
186
187
187
# Make the windows AMI public if it's not the source image
188
- if [[ $windows_amd64_image_id != " $windows_amd64_source_image_id " ]] ; then
188
+ if [[ $windows_amd64_image_id != " $windows_amd64_source_image_id " ]]; then
189
189
echo " :windows: Making Windows AMD64 ${windows_amd64_image_id} public" >&2
190
190
make_ami_public " $windows_amd64_image_id " " $region "
191
191
fi
192
192
193
193
# Write yaml to file
194
- echo " $region : { linuxamd64: $linux_amd64_image_id , linuxarm64: $linux_arm64_image_id , windows: $windows_amd64_image_id }" >> " $mapping_file "
194
+ echo " $region : { linuxamd64: $linux_amd64_image_id , linuxarm64: $linux_arm64_image_id , windows: $windows_amd64_image_id }" >> " $mapping_file "
195
195
196
196
# Shift off the processed images
197
197
IMAGES=(" ${IMAGES[@]: 3} " )
0 commit comments