Skip to content

Commit 1167fcf

Browse files
scadupetetomasik
andauthored
Build and publish arm64 binary (#254)
* Build and publish arm64 binary * Add parameter to configure architecture * Ditch Architecture param Not needed since each Serverless Application is built for specific arch. --------- Co-authored-by: Pete Tomasik <senate6268@gmail.com>
1 parent 356eb9d commit 1167fcf

10 files changed

Lines changed: 86 additions & 17 deletions

File tree

.buildkite/pipeline-sar.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ steps:
2121
- .buildkite/steps/build-lambda.sh
2222
artifact_paths:
2323
- handler.zip
24+
- handler-arm64.zip
2425

2526
- label: ":lambda::arrow_right::package: Create SAR Package"
2627
key: package

.buildkite/pipeline.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ steps:
3232
- .buildkite/steps/build-lambda.sh
3333
artifact_paths:
3434
- handler.zip
35+
- handler-arm64.zip
3536

3637
- label: ":s3: Publish to S3 Branch Location"
3738
key: s3-branch

.buildkite/steps/build-lambda.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
set -eu
33

4-
make handler.zip
4+
# Build both architectures
5+
make build
56

67
if [[ -z "${BUILDKITE_TAG:-}" ]]; then
78
VERSION=$(git describe --tags)

.buildkite/steps/github-release.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ notes=$(sed -n "/^## \[${escaped_tag}\]/,/^## \[${escaped_last_tag}\]/p" CHANGEL
3838
echo "$notes"
3939

4040
echo --- :lambda: Downloading lambda from artifacts
41-
buildkite-agent artifact download handler.zip .
41+
buildkite-agent artifact download "handler*.zip" .
4242

4343
echo "--- 🚀 Releasing $version"
4444
if [[ "${GITHUB_RELEASE_ACCESS_TOKEN:-}" == "" ]]; then
@@ -51,4 +51,5 @@ GITHUB_TOKEN="$GITHUB_RELEASE_ACCESS_TOKEN" release_dry_run gh release create \
5151
--title "$tag" \
5252
--notes "$notes" \
5353
"$tag" \
54-
handler.zip
54+
handler.zip \
55+
handler-arm64.zip

.buildkite/steps/publish-package.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ source .buildkite/lib/release-dry-run.sh
66

77
VERSION=$(buildkite-agent meta-data get version)
88

9-
buildkite-agent artifact download packaged.yml .
9+
buildkite-agent artifact download "packaged*.yml" .
1010

11+
# Determine SAR application IDs based on release type
1112
if [[ -z "${BUILDKITE_TAG:-}" ]]; then
13+
# Edge builds
1214
APP_ID=arn:aws:serverlessrepo:us-east-1:172840064832:applications/buildkite-agent-scaler-edge
15+
APP_ID_ARM64=arn:aws:serverlessrepo:us-east-1:172840064832:applications/buildkite-agent-scaler-arm64-edge
1316
else
17+
# Release builds
1418
APP_ID=arn:aws:serverlessrepo:us-east-1:172840064832:applications/buildkite-agent-scaler
19+
APP_ID_ARM64=arn:aws:serverlessrepo:us-east-1:172840064832:applications/buildkite-agent-scaler-arm64
1520
fi
1621

1722
echo --- ":aws::lambda: Publishing version $VERSION to SAR"
@@ -20,3 +25,10 @@ release_dry_run aws serverlessrepo create-application-version \
2025
--template-body file://packaged.yml \
2126
--semantic-version "${VERSION#v}" \
2227
--source-code-url "https://github.com/buildkite/buildkite-agent-scaler/tree/$(git rev-parse HEAD)/"
28+
29+
echo --- ":aws::lambda: Publishing arm64 version $VERSION to SAR"
30+
release_dry_run aws serverlessrepo create-application-version \
31+
--application-id "$APP_ID_ARM64" \
32+
--template-body file://packaged-arm64.yml \
33+
--semantic-version "${VERSION#v}" \
34+
--source-code-url "https://github.com/buildkite/buildkite-agent-scaler/tree/$(git rev-parse HEAD)/"

.buildkite/steps/sar.sh

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,40 @@
22

33
set -euo pipefail
44

5-
echo --- Download handler.zip
6-
buildkite-agent artifact download handler.zip .
5+
echo --- Download handler zips
6+
buildkite-agent artifact download "handler*.zip" .
77

8-
echo --- Create template for Serverless Application Repository
9-
sam package --region us-east-1 --s3-bucket buildkite-serverless-apps-us-east-1 --s3-prefix elastic-ci/agent-scaler --output-template-file packaged.yml
8+
# Package x86_64 version (default - handler.zip is already x86_64)
9+
echo "--- Create x86_64 template for Serverless Application Repository"
10+
sam package \
11+
--template-file template.yaml \
12+
--region us-east-1 \
13+
--s3-bucket buildkite-serverless-apps-us-east-1 \
14+
--s3-prefix elastic-ci/agent-scaler \
15+
--output-template-file packaged.yml
1016
buildkite-agent artifact upload packaged.yml
1117

12-
echo --- Print template for Serverless Application Repository
18+
# Package arm64 version
19+
echo "--- Create arm64 template for Serverless Application Repository"
20+
# Temporarily rename files to avoid overwriting handler.zip
21+
mv handler.zip handler-x86_64-backup.zip
22+
mv handler-arm64.zip handler.zip
23+
sam package \
24+
--template-file template.yaml \
25+
--region us-east-1 \
26+
--s3-bucket buildkite-serverless-apps-us-east-1 \
27+
--s3-prefix elastic-ci/agent-scaler-arm64 \
28+
--output-template-file packaged-arm64.yml
29+
# Restore original filenames
30+
mv handler.zip handler-arm64.zip
31+
mv handler-x86_64-backup.zip handler.zip
32+
# Update the hardcoded architecture from x86_64 to arm64
33+
echo "Updating Lambda architecture to arm64..."
34+
sed -i.bak 's/- x86_64/- arm64/' packaged-arm64.yml && rm packaged-arm64.yml.bak
35+
buildkite-agent artifact upload packaged-arm64.yml
36+
37+
echo --- Print x86_64 template for Serverless Application Repository
1338
echo "$(< packaged.yml)"
39+
40+
echo --- Print arm64 template for Serverless Application Repository
41+
echo "$(< packaged-arm64.yml)"

.buildkite/steps/upload-to-s3.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ else
1515
fi
1616

1717
echo "~~~ :buildkite: Downloading artifacts"
18-
buildkite-agent artifact download handler.zip .
18+
buildkite-agent artifact download "handler*.zip" .
1919

2020
echo "~~~ :s3: Uploading lambda to ${BASE_BUCKET}/${BUCKET_PATH}/ in ${AWS_DEFAULT_REGION}"
21+
# Upload both versions:
22+
# - handler.zip: x86_64 (default/existing architecture)
23+
# - handler-arm64.zip: arm64 (new architecture)
2124
aws s3 cp handler.zip "s3://${BASE_BUCKET}/${BUCKET_PATH}/handler.zip"
25+
aws s3 cp handler-arm64.zip "s3://${BASE_BUCKET}/${BUCKET_PATH}/handler-arm64.zip"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/lambda/handler
22
/*.zip
3-
/packaged.yml
3+
/bootstrap*
4+
/packaged*.yml
45
buildkite-agent-scaler

Makefile

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,51 @@
1-
.PHONY: all clean build
1+
.PHONY: all clean build build-arm64
22

33
all: build
44

5+
build: handler.zip handler-arm64.zip
6+
57
clean:
6-
-rm -f handler.zip bootstrap
8+
-rm -f handler.zip handler-arm64.zip bootstrap bootstrap-arm64
79

810
export CGO_ENABLED := 0
11+
export GOOS := linux
912

1013
ifdef BUILDKITE_BUILD_NUMBER
1114
LD_FLAGS := -s -w -X version.Build=$(BUILDKITE_BUILD_NUMBER)
12-
BUILDVSC_FLAG := false
15+
BUILDVCS_FLAG := false
1316
USER := 0:0
1417
else
1518
LD_FLAGS := -s -w
16-
BUILDVSC_FLAG := true
19+
BUILDVCS_FLAG := true
1720
USER := "$(shell id -u):$(shell id -g)"
1821
endif
1922

20-
build: handler.zip
23+
build-arm64: handler-arm64.zip
2124

25+
# handler.zip is x86_64 (default/existing architecture)
2226
handler.zip: bootstrap
2327
zip -9 -v -j $@ "$<"
2428

29+
handler-arm64.zip: bootstrap-arm64
30+
@rm -f bootstrap
31+
@cp bootstrap-arm64 bootstrap
32+
@zip -9 -v -j $@ bootstrap
33+
@rm -f bootstrap
34+
2535
bootstrap: lambda/main.go
2636
./bin/mise install
27-
./bin/mise exec -- go build \
37+
GOARCH=amd64 ./bin/mise exec -- go build \
2838
-ldflags="$(LD_FLAGS)" \
2939
-buildvcs="$(BUILDVCS_FLAG)" \
3040
-tags lambda.norpc \
3141
-o bootstrap \
3242
./lambda
43+
44+
bootstrap-arm64: lambda/main.go
45+
./bin/mise install
46+
GOARCH=arm64 ./bin/mise exec -- go build \
47+
-ldflags="$(LD_FLAGS)" \
48+
-buildvcs="$(BUILDVCS_FLAG)" \
49+
-tags lambda.norpc \
50+
-o bootstrap-arm64 \
51+
./lambda

template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Parameters:
138138
- "false"
139139
Default: "false"
140140

141+
141142
Conditions:
142143
CreateRole:
143144
!Equals [ !Ref AutoscalingLambdaExecutionRole, '' ]

0 commit comments

Comments
 (0)