Skip to content

Commit bb36080

Browse files
authored
Adds multi-arch build support (#3761)
Enables ARM64 builds with dynamic image selection to enhance compatibility and streamline deployment workflows
1 parent 96ffa7f commit bb36080

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ build: $(binaries) $(statics)
2222

2323
builder:
2424
docker buildx build --platform linux/amd64 -t convox/build:$(VERSION) --no-cache --pull --push -f cmd/build/Dockerfile .
25+
docker buildx build --platform linux/arm64 -t convox/build:$(VERSION)-arm64 --no-cache --pull --push -f cmd/build/Dockerfile.arm .
2526

2627
clean: clean-package
2728
make -C cmd/convox clean
@@ -103,7 +104,7 @@ test-docker:
103104
docker run -it convox/rack:test make test
104105

105106
$(binaries): $(GOPATH)/bin/%: $(sources)
106-
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor -tags=hidraw -ldflags="-extldflags=-static" -o $@ ./cmd/$*
107+
env CGO_ENABLED=0 GOOS=linux go build -mod=vendor -tags=hidraw -ldflags="-extldflags=-static" -o $@ ./cmd/$*
107108

108109
$(statics): $(GOPATH)/bin/%: $(sources)
109110
env CGO_ENABLED=0 go install --ldflags '-extldflags "-static" -s -w' ./cmd/$*

cmd/build/Dockerfile.arm

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM golang:1.23-bookworm AS package
2+
3+
ARG DOCKER_ARCH=aarch64
4+
ENV PATH=$PATH:/go/bin
5+
6+
# Add backports to get upx-ucl in Bookworm
7+
RUN echo "deb http://deb.debian.org/debian bookworm-backports main" > /etc/apt/sources.list.d/backports.list && \
8+
apt-get update && apt-get install -y -t bookworm-backports upx-ucl
9+
10+
WORKDIR /go/src/github.com/convox/rack
11+
12+
COPY . /go/src/github.com/convox/rack
13+
RUN make build compress
14+
15+
# add crane (single static binary)
16+
ENV VERSION=v0.20.3
17+
ENV OS=Linux
18+
ENV ARCH=arm64
19+
ARG DOCKER_ARCH=aarch64
20+
21+
RUN curl -sL "https://github.com/google/go-containerregistry/releases/download/${VERSION}/go-containerregistry_${OS}_${ARCH}.tar.gz" > go-containerregistry.tar.gz && \
22+
mkdir -p /usr/local/bin/crane && \
23+
tar -zxvf go-containerregistry.tar.gz -C /usr/local/bin/ crane && \
24+
rm go-containerregistry.tar.gz
25+
26+
# Kaniko runtime
27+
FROM gcr.io/kaniko-project/executor:v1.23.2-debug
28+
29+
# Create /tmp so Kaniko can write
30+
RUN mkdir -p /tmp && chmod 1777 /tmp
31+
32+
# Copy crane
33+
COPY --from=package /usr/local/bin/crane /busybox
34+
35+
# Copy the build output
36+
COPY --from=package /go/bin/build /busybox/
37+
COPY --from=package /go/bin/convox-env /busybox/
38+
39+
ENTRYPOINT []
40+
CMD ["/busybox/build"]

provider/aws/formation/rack.json

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
{"Condition": "PrivateAndThirdAvailabilityZoneAndHighAvailability"}
4040
]},
4141
"DedicatedBuilder": { "Fn::Not": [ { "Fn::Equals": [ { "Ref": "BuildInstance" }, "" ] } ] },
42+
"DedicatedBuilderAS": {
43+
"Fn::And": [
44+
{ "Condition": "DedicatedBuilder" },
45+
{ "Fn::Not": [ { "Condition": "UseFargateBuild" } ] }
46+
]
47+
},
4248
"Development": { "Fn::Equals": [ { "Ref": "Development" }, "Yes" ] },
4349
"EnableALBPort80": {
4450
"Fn::And": [ { "Condition": "PublicRouter" }, { "Condition": "AllowALBPort80" } ]
@@ -295,7 +301,7 @@
295301
"Value": { "Ref": "AWS::Region" }
296302
},
297303
"BuildAutoscalingGroup": {
298-
"Value": { "Fn::If": [ "DedicatedBuilder", { "Ref": "BuildInstances" }, { "Ref": "Instances" } ] }
304+
"Value": { "Fn::If": [ "DedicatedBuilderAS", { "Ref": "BuildInstances" }, { "Ref": "Instances" } ] }
299305
},
300306
"BuildCluster": {
301307
"Value": { "Fn::If": [ "DedicatedBuilder", { "Ref": "BuildCluster" }, { "Ref": "Cluster" } ] }
@@ -2007,7 +2013,7 @@
20072013
}
20082014
},
20092015
"BuildInstances": {
2010-
"Condition": "DedicatedBuilder",
2016+
"Condition": "DedicatedBuilderAS",
20112017
"Type": "AWS::AutoScaling::AutoScalingGroup",
20122018
"Properties" : {
20132019
"LaunchTemplate" : {
@@ -4227,7 +4233,19 @@
42274233
{ "Name": "STACK_ID", "Value": { "Ref": "AWS::StackId" } },
42284234
{ "Name": "BUILD_RUNTIME", "Value": "daemonless" }
42294235
],
4230-
"Image": { "Fn::Sub": "convox/build:${Version}" },
4236+
"Image": {
4237+
"Fn::If": [
4238+
"BlankBuildImage",
4239+
{
4240+
"Fn::If": [
4241+
"InstanceARM",
4242+
{ "Fn::Sub": "convox/build:${Version}-arm64" },
4243+
{ "Fn::Sub": "convox/build:${Version}" }
4244+
]
4245+
},
4246+
{ "Ref": "BuildImage" }
4247+
]
4248+
},
42314249
"LogConfiguration": {
42324250
"Fn::If": [
42334251
"EnableSyslog",
@@ -4264,6 +4282,15 @@
42644282
}]
42654283
}
42664284
],
4285+
"RuntimePlatform": {
4286+
"CpuArchitecture" : {
4287+
"Fn::If": [
4288+
"InstanceARM",
4289+
"ARM64",
4290+
"X86_64"
4291+
]
4292+
}
4293+
},
42674294
"ExecutionRoleArn": { "Fn::GetAtt": [ "ApiRole", "Arn" ] },
42684295
"Family": { "Fn::Sub": "${AWS::StackName}-build" },
42694296
"TaskRoleArn": { "Fn::GetAtt": [ "ApiRole", "Arn" ] }

0 commit comments

Comments
 (0)