Skip to content

Commit 2f4b039

Browse files
committed
Merge remote-tracking branch 'origin/master' into keithduncan/ssm-with-ssh
2 parents e4255d2 + 4c26d00 commit 2f4b039

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1062
-688
lines changed

.buildkite/pipeline.yml

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ steps:
2727
- "lint"
2828
- "bats-tests"
2929

30-
- id: "windows-launch"
30+
- id: "launch-windows"
3131
name: ":cloudformation: :windows: Launch"
3232
command: .buildkite/steps/launch.sh windows
3333
agents:
3434
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE}"
3535
artifact_paths: "build/aws-stack.yml"
3636
depends_on: "packer-windows"
3737

38-
- id: "windows-test"
38+
- id: "test-windows"
3939
name: ":cloudformation: :windows: Test"
4040
command: "docker info"
4141
timeout_in_minutes: 5
4242
agents:
43-
stack: "buildkite-aws-stack-test-windows-${BUILDKITE_BUILD_NUMBER}"
44-
queue: "testqueue-windows-${BUILDKITE_BUILD_NUMBER}"
45-
depends_on: "windows-launch"
43+
stack: "buildkite-aws-stack-test-windows-amd64-${BUILDKITE_BUILD_NUMBER}"
44+
queue: "testqueue-windows-amd64-${BUILDKITE_BUILD_NUMBER}"
45+
depends_on: "launch-windows"
4646

47-
- id: "packer-linux"
48-
name: ":packer: :linux:"
47+
- id: "packer-linux-amd64"
48+
name: ":packer: :linux: AMD64"
4949
command: .buildkite/steps/packer.sh linux
5050
timeout_in_minutes: 60
5151
retry: { automatic: { limit: 3 } }
@@ -55,22 +55,50 @@ steps:
5555
- "lint"
5656
- "bats-tests"
5757

58-
- id: "linux-launch"
59-
name: ":cloudformation: :linux: Launch"
58+
- id: "launch-linux-amd64"
59+
name: ":cloudformation: :linux: AMD64 Launch"
6060
command: .buildkite/steps/launch.sh linux
6161
agents:
6262
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE}"
6363
artifact_paths: "build/aws-stack.yml"
64-
depends_on: "packer-linux"
64+
depends_on: "packer-linux-amd64"
6565

66-
- id: "linux-test"
67-
name: ":cloudformation: :linux: Test"
66+
- id: "test-linux-amd64"
67+
name: ":cloudformation: :linux: AMD64 Test"
6868
command: "goss validate --format documentation"
6969
timeout_in_minutes: 5
7070
agents:
71-
stack: "buildkite-aws-stack-test-linux-${BUILDKITE_BUILD_NUMBER}"
72-
queue: "testqueue-linux-${BUILDKITE_BUILD_NUMBER}"
73-
depends_on: "linux-launch"
71+
stack: "buildkite-aws-stack-test-linux-amd64-${BUILDKITE_BUILD_NUMBER}"
72+
queue: "testqueue-linux-amd64-${BUILDKITE_BUILD_NUMBER}"
73+
depends_on: "launch-linux-amd64"
74+
75+
- id: "packer-linux-arm64"
76+
name: ":packer: :linux: ARM64"
77+
command: .buildkite/steps/packer.sh linux arm64
78+
timeout_in_minutes: 60
79+
retry: { automatic: { limit: 3 } }
80+
agents:
81+
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE}"
82+
depends_on:
83+
- "lint"
84+
- "bats-tests"
85+
86+
- id: "launch-linux-arm64"
87+
name: ":cloudformation: :linux: ARM64 Launch"
88+
command: .buildkite/steps/launch.sh linux arm64
89+
agents:
90+
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE}"
91+
artifact_paths: "build/aws-stack.yml"
92+
depends_on: "packer-linux-arm64"
93+
94+
- id: "test-linux-arm64"
95+
name: ":cloudformation: :linux: ARM64 Test"
96+
command: "goss validate --format documentation"
97+
timeout_in_minutes: 5
98+
agents:
99+
stack: "buildkite-aws-stack-test-linux-arm64-${BUILDKITE_BUILD_NUMBER}"
100+
queue: "testqueue-linux-arm64-${BUILDKITE_BUILD_NUMBER}"
101+
depends_on: "launch-linux-arm64"
74102

75103
- id: "copy-ami"
76104
name: ":cloudformation: 🚚 🌎"
@@ -79,8 +107,9 @@ steps:
79107
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE}"
80108
artifact_paths: "build/mappings.yml"
81109
depends_on:
82-
- "linux-test"
83-
- "windows-test"
110+
- "test-linux-amd64"
111+
- "test-linux-arm64"
112+
- "test-windows"
84113

85114
- id: "publish"
86115
name: ":cloudformation: :rocket:"

.buildkite/steps/cleanup.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ delete_test_stack() {
2525
}
2626

2727
if [[ -n "${BUILDKITE_BUILD_NUMBER:-}" ]] ; then
28-
delete_test_stack "windows"
29-
delete_test_stack "linux"
28+
delete_test_stack "windows-amd64"
29+
delete_test_stack "linux-amd64"
30+
delete_test_stack "linux-arm64"
3031
fi
3132

3233
if [[ $OSTYPE =~ ^darwin ]] ; then
@@ -44,15 +45,15 @@ aws s3api list-buckets \
4445
--output text \
4546
--query "$(printf 'Buckets[?CreationDate<`%s`].[Name]' "$cutoff_date" )" \
4647
| xargs -n1 \
47-
| grep -E 'buildkite-aws-stack-test-(\d+-)?managedsecrets' \
48+
| grep -E 'buildkite-aws-stack-test-.*-managedsecretsbucket' \
4849
| xargs -n1 -t -I% aws s3 rb s3://% --force
4950

5051
echo "--- Deleting old cloudformation stacks"
5152
aws cloudformation describe-stacks \
5253
--output text \
5354
--query "$(printf 'Stacks[?CreationTime<`%s`].[StackName]' "$cutoff_date" )" \
5455
| xargs -n1 \
55-
| grep -E 'buildkite-aws-stack-test-\d+' \
56+
| grep -E 'buildkite-aws-stack-test-(linux|windows)-(amd64|arm64)-[[:digit:]]+' \
5657
| xargs -n1 -t -I% aws cloudformation delete-stack --stack-name "%"
5758

5859
echo "--- Deleting old packer builders"

.buildkite/steps/copy.sh

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,18 @@ IMAGES=(
9191
)
9292

9393
# Configuration
94-
linux_source_image_id="${1:-}"
95-
windows_source_image_id="${2:-}"
94+
linux_amd64_source_image_id="${1:-}"
95+
linux_arm64_source_image_id="${1:-}"
96+
windows_amd64_source_image_id="${2:-}"
9697

9798
source_region="${AWS_REGION}"
9899
mapping_file="build/mappings.yml"
99100

100101
# Read the source images from meta-data if no arguments are provided
101102
if [ $# -eq 0 ] ; then
102-
linux_source_image_id=$(buildkite-agent meta-data get "linux_image_id")
103-
windows_source_image_id=$(buildkite-agent meta-data get "windows_image_id")
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")
104106
fi
105107

106108
# If we're not on the master branch or a tag build skip the copy
@@ -110,15 +112,16 @@ if [[ $BUILDKITE_BRANCH != "master" ]] && [[ "$BUILDKITE_TAG" != "$BUILDKITE_BRA
110112
cat << EOF > "$mapping_file"
111113
Mappings:
112114
AWSRegion2AMI:
113-
${AWS_REGION} : { linux: $linux_source_image_id, windows: $windows_source_image_id }
115+
${AWS_REGION} : { linuxamd64: $linux_amd64_source_image_id, linuxarm64: $linux_arm64_source_image_id, windows: $windows_amd64_source_image_id }
114116
EOF
115117
exit 0
116118
fi
117119

118-
s3_mappings_cache=$(printf "s3://%s/mappings-%s-%s-%s.yml" \
120+
s3_mappings_cache=$(printf "s3://%s/mappings-%s-%s-%s-%s.yml" \
119121
"${BUILDKITE_AWS_STACK_BUCKET}" \
120-
"${linux_source_image_id}" \
121-
"${windows_source_image_id}" \
122+
"${linux_amd64_source_image_id}" \
123+
"${linux_arm64_source_image_id}" \
124+
"${windows_amd64_source_image_id}" \
122125
"${BUILDKITE_BRANCH}")
123126

124127
# Check if there is a previously copy in the cache bucket
@@ -128,19 +131,24 @@ if aws s3 cp "${s3_mappings_cache}" "$mapping_file" ; then
128131
fi
129132

130133
# Get the image names to copy to other regions
131-
linux_source_image_name=$(get_image_name "$linux_source_image_id" "$source_region")
132-
windows_source_image_name=$(get_image_name "$windows_source_image_id" "$source_region")
134+
linux_amd64_source_image_name=$(get_image_name "$linux_amd64_source_image_id" "$source_region")
135+
linux_arm64_source_image_name=$(get_image_name "$linux_arm64_source_image_id" "$source_region")
136+
windows_amd64_source_image_name=$(get_image_name "$windows_amd64_source_image_id" "$source_region")
133137

134138
# Copy to all other regions
139+
# shellcheck disable=SC2048
135140
for region in ${ALL_REGIONS[*]}; do
136141
if [[ $region != "$source_region" ]] ; then
137-
echo "--- Copying :linux: $linux_source_image_id to $region" >&2
138-
IMAGES+=("$(copy_ami_to_region "$linux_source_image_id" "$source_region" "$region" "${linux_source_image_name}-${region}")")
142+
echo "--- :linux: Copying Linux AMD64 $linux_amd64_source_image_id to $region" >&2
143+
IMAGES+=("$(copy_ami_to_region "$linux_amd64_source_image_id" "$source_region" "$region" "${linux_amd64_source_image_name}-${region}")")
139144

140-
echo "--- Copying :windows: $windows_source_image_id to $region" >&2
141-
IMAGES+=("$(copy_ami_to_region "$windows_source_image_id" "$source_region" "$region" "${windows_source_image_name}-${region}")")
145+
echo "--- :linux: Copying Linux ARM64 $linux_arm64_source_image_id to $region" >&2
146+
IMAGES+=("$(copy_ami_to_region "$linux_arm64_source_image_id" "$source_region" "$region" "${linux_arm64_source_image_name}-${region}")")
147+
148+
echo "--- :windows: Copying Windows AMD64 $windows_amd64_source_image_id to $region" >&2
149+
IMAGES+=("$(copy_ami_to_region "$windows_amd64_source_image_id" "$source_region" "$region" "${windows_amd64_source_image_name}-${region}")")
142150
else
143-
IMAGES+=("$linux_source_image_id" "$windows_source_image_id")
151+
IMAGES+=("$linux_amd64_source_image_id" "$linux_arm64_source_image_id" "$windows_amd64_source_image_id")
144152
fi
145153
done
146154

@@ -152,32 +160,41 @@ Mappings:
152160
EOF
153161

154162
echo "--- Waiting for AMIs to become available" >&2
155-
163+
# shellcheck disable=SC2048
156164
for region in ${ALL_REGIONS[*]}; do
157-
linux_image_id="${IMAGES[0]}"
158-
windows_image_id="${IMAGES[1]}"
165+
linux_amd64_image_id="${IMAGES[0]}"
166+
linux_arm64_image_id="${IMAGES[1]}"
167+
windows_amd64_image_id="${IMAGES[2]}"
159168

160-
wait_for_ami_to_be_available "$linux_image_id" "$region" >&2
169+
wait_for_ami_to_be_available "$linux_amd64_image_id" "$region" >&2
161170

162171
# Make the linux AMI public if it's not the source image
163-
if [[ $linux_image_id != "$linux_source_image_id" ]] ; then
164-
echo "Making :linux: ${linux_image_id} public" >&2
165-
make_ami_public "$linux_image_id" "$region"
172+
if [[ $linux_amd64_image_id != "$linux_amd64_source_image_id" ]] ; then
173+
echo ":linux: Making Linux AMD64 ${linux_amd64_image_id} public" >&2
174+
make_ami_public "$linux_amd64_image_id" "$region"
175+
fi
176+
177+
wait_for_ami_to_be_available "$linux_arm64_image_id" "$region" >&2
178+
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
181+
echo ":linux: Making Linux ARM64 ${linux_arm64_image_id} public" >&2
182+
make_ami_public "$linux_arm64_image_id" "$region"
166183
fi
167184

168-
wait_for_ami_to_be_available "$windows_image_id" "$region" >&2
185+
wait_for_ami_to_be_available "$windows_amd64_image_id" "$region" >&2
169186

170187
# Make the windows AMI public if it's not the source image
171-
if [[ $windows_image_id != "$windows_source_image_id" ]] ; then
172-
echo "Making :windows: ${windows_image_id} public" >&2
173-
make_ami_public "$windows_image_id" "$region"
188+
if [[ $windows_amd64_image_id != "$windows_amd64_source_image_id" ]] ; then
189+
echo ":windows: Making Windows AMD64 ${windows_amd64_image_id} public" >&2
190+
make_ami_public "$windows_amd64_image_id" "$region"
174191
fi
175192

176193
# Write yaml to file
177-
echo " $region : { linux: $linux_image_id, windows: $windows_image_id }" >> "$mapping_file"
194+
echo " $region : { linuxamd64: $linux_amd64_image_id, linuxarm64: $linux_arm64_image_id, windows: $windows_amd64_image_id }" >> "$mapping_file"
178195

179196
# Shift off the processed images
180-
IMAGES=("${IMAGES[@]:2}")
197+
IMAGES=("${IMAGES[@]:3}")
181198
done
182199

183200
echo "--- Uploading mapping to s3 cache"

.buildkite/steps/launch.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
set -eu
33

44
os="${1:-linux}"
5-
stack_name="buildkite-aws-stack-test-${os}-${BUILDKITE_BUILD_NUMBER}"
6-
stack_queue_name="testqueue-${os}-${BUILDKITE_BUILD_NUMBER}"
5+
arch="${2:-amd64}"
6+
stack_name="buildkite-aws-stack-test-${os}-${arch}-${BUILDKITE_BUILD_NUMBER}"
7+
stack_queue_name="testqueue-${os}-${arch}-${BUILDKITE_BUILD_NUMBER}"
78

89
# download parfait binary
910
wget -N https://github.com/lox/parfait/releases/download/v1.1.3/parfait_linux_amd64
@@ -15,8 +16,8 @@ subnets=$(aws ec2 describe-subnets --filters "Name=vpc-id,Values=$vpc_id" --quer
1516
subnet_ids=$(awk '{print $1}' <<< "$subnets" | tr ' ' ',' | tr '\n' ',' | sed 's/,$//')
1617
az_ids=$(awk '{print $2}' <<< "$subnets" | tr ' ' ',' | tr '\n' ',' | sed 's/,$//')
1718

18-
image_id=$(buildkite-agent meta-data get "${os}_image_id")
19-
echo "Using AMI $image_id for $os"
19+
image_id=$(buildkite-agent meta-data get "${os}_${arch}_image_id")
20+
echo "Using AMI $image_id for $os/$arch"
2021

2122
instance_type="t3.nano"
2223
instance_disk="10"
@@ -26,6 +27,10 @@ if [[ "$os" == "windows" ]] ; then
2627
instance_disk="100"
2728
fi
2829

30+
if [[ "$arch" == "arm64" ]] ; then
31+
instance_type="m6g.large"
32+
fi
33+
2934
cat << EOF > config.json
3035
[
3136
{
@@ -88,7 +93,7 @@ cat << EOF > config.json
8893
EOF
8994

9095
echo "--- Building templates"
91-
make "mappings-for-${os}-image" build/aws-stack.yml "IMAGE_ID=$image_id"
96+
make "mappings-for-${os}-${arch}-image" build/aws-stack.yml "IMAGE_ID=$image_id"
9297

9398
echo "--- Validating templates"
9499
make validate

.buildkite/steps/packer.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ if [[ -z "${BUILDKITE_AWS_STACK_BUCKET}" ]] ; then
77
fi
88

99
os="${1:-linux}"
10-
agent_binary="buildkite-agent-${os}-amd64"
10+
arch="${2:-amd64}"
11+
agent_binary="buildkite-agent-${os}-${arch}"
1112

1213
if [[ "$os" == "windows" ]] ; then
1314
agent_binary+=".exe"
@@ -19,16 +20,16 @@ mkdir -p "build/"
1920
packer_files_sha=$(find Makefile "packer/${os}" plugins/ -type f -print0 | xargs -0 sha1sum | awk '{print $1}' | sort | sha1sum | awk '{print $1}')
2021
stable_agent_sha=$(curl -Lfs "https://download.buildkite.com/agent/stable/latest/${agent_binary}.sha256")
2122
unstable_agent_sha=$(curl -Lfs "https://download.buildkite.com/agent/unstable/latest/${agent_binary}.sha256")
22-
packer_hash=$(echo "$packer_files_sha" "$stable_agent_sha" "$unstable_agent_sha" | sha1sum | awk '{print $1}')
23+
packer_hash=$(echo "$packer_files_sha" "$arch" "$stable_agent_sha" "$unstable_agent_sha" | sha1sum | awk '{print $1}')
2324

24-
echo "Packer image hash for ${os} is ${packer_hash}"
25-
packer_file="packer-${packer_hash}-${os}.output"
25+
echo "Packer image hash for ${os}/${arch} is ${packer_hash}"
26+
packer_file="packer-${packer_hash}-${os}-${arch}.output"
2627

2728
# Only build packer image if one with the same hash doesn't exist, and we're not being forced
2829
if [[ -n "${PACKER_REBUILD:-}" ]] || ! aws s3 cp "s3://${BUILDKITE_AWS_STACK_BUCKET}/${packer_file}" . ; then
29-
make "packer-${os}.output"
30-
aws s3 cp "packer-${os}.output" "s3://${BUILDKITE_AWS_STACK_BUCKET}/${packer_file}"
31-
mv "packer-${os}.output" "${packer_file}"
30+
make "packer-${os}-${arch}.output"
31+
aws s3 cp "packer-${os}-${arch}.output" "s3://${BUILDKITE_AWS_STACK_BUCKET}/${packer_file}"
32+
mv "packer-${os}-${arch}.output" "${packer_file}"
3233
else
3334
echo "Skipping packer build, no changes"
3435
fi
@@ -37,4 +38,4 @@ fi
3738
image_id=$(grep -Eo "${AWS_REGION}: (ami-.+)$" "$packer_file" | awk '{print $2}')
3839
echo "AMI for ${AWS_REGION} is $image_id"
3940

40-
buildkite-agent meta-data set "${os}_image_id" "$image_id"
41+
buildkite-agent meta-data set "${os}_${arch}_image_id" "$image_id"

0 commit comments

Comments
 (0)