Skip to content

Commit 948cbe5

Browse files
authored
build: support native architecture builds on ARM hosts (#8547)
Allows make-deb.sh to produce either amd64 or arm64 debian packages. Adds plumbing to the build scripts upstream of that one (namely container-build.sh and the Containerfile) to plumb the architecture through.
1 parent d1d5b45 commit 948cbe5

5 files changed

Lines changed: 34 additions & 11 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ test/certs/webpki
88
test/certs/.softhsm-tokens
99
.git
1010
.gocache
11+
.github

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*.a
44
*.so
55
*.pyc
6+
boulder-*.deb
7+
boulder-*.tar.gz
68

79
# Folders
810
_obj

Containerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ FROM docker.io/ubuntu:24.04 AS builder
66
ARG COMMIT_ID
77
ARG COMMIT_TIMESTAMP
88
ARG GO_VERSION
9+
ARG TARGETPLATFORM
910
ARG VERSION
1011

1112
ENV DEBIAN_FRONTEND=noninteractive
@@ -14,7 +15,12 @@ RUN apt-get --assume-yes --no-install-recommends --update install \
1415
ca-certificates curl gcc git gnupg2 libc6-dev
1516

1617
COPY tools/fetch-and-verify-go.sh /tmp
17-
RUN /tmp/fetch-and-verify-go.sh ${GO_VERSION}
18+
RUN case "${TARGETPLATFORM}" in \
19+
"linux/amd64"|"") PLATFORM="linux-amd64" ;; \
20+
"linux/arm64") PLATFORM="linux-arm64" ;; \
21+
*) echo "Unsupported platform: ${TARGETPLATFORM}" && exit 1 ;; \
22+
esac && \
23+
/tmp/fetch-and-verify-go.sh ${GO_VERSION} ${PLATFORM}
1824
RUN tar -C /opt -xzf go.tar.gz
1925
ENV PATH="/opt/go/bin:${PATH}"
2026

tools/container-build.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,34 @@
77

88
set -ex
99

10-
# Without this, `go install` produces:
11-
# # runtime/cgo
12-
# gcc: error: unrecognized command-line option '-m64'
13-
if [ "$(uname -m)" = "arm64" ]; then
14-
export DOCKER_DEFAULT_PLATFORM=linux/amd64
15-
fi
16-
1710
if [ -z "${GO_VERSION}" ] ; then
1811
echo "GO_VERSION not set"
1912
exit 1
2013
fi
2114

22-
ARCH="$(uname -m)"
15+
# Determine what architecture to build for
16+
if [ -n "${DOCKER_DEFAULT_PLATFORM:-}" ]; then
17+
PLATFORM="${DOCKER_DEFAULT_PLATFORM}"
18+
else
19+
case "$(uname -m)" in
20+
x86_64) PLATFORM="linux/amd64" ;;
21+
aarch64|arm64) PLATFORM="linux/arm64" ;;
22+
*) echo "Unsupported architecture: $(uname -m)" && exit 1 ;;
23+
esac
24+
fi
25+
26+
case "${PLATFORM}" in
27+
linux/amd64) ARCH="amd64" ;;
28+
linux/arm64) ARCH="arm64" ;;
29+
*) echo "Unsupported platform: ${PLATFORM}" && exit 1 ;;
30+
esac
2331
COMMIT_ID="$(git rev-parse --short=8 HEAD)"
2432
COMMIT_TIMESTAMP="$(git show -s --format=%ct HEAD)"
2533
COMMIT_DATE_ISO8601="$(TZ=UTC0 git show -s --format=%cd --date=format:%Y-%m-%dT%H:%M:%SZ HEAD)"
2634
VERSION="${GO_VERSION}.${COMMIT_TIMESTAMP}"
2735

2836
docker buildx build \
37+
--platform "$PLATFORM" \
2938
--file Containerfile \
3039
--build-arg "COMMIT_ID=${COMMIT_ID}" \
3140
--build-arg "COMMIT_TIMESTAMP=${COMMIT_TIMESTAMP}" \
@@ -40,6 +49,7 @@ docker buildx build \
4049
docker run boulder tar -C /opt/boulder --mtime="@${COMMIT_TIMESTAMP}" --owner=0 --group=0 --numeric-owner --sort=name -cp . | gzip -n > "./boulder-${VERSION}-${COMMIT_ID}.${ARCH}.tar.gz"
4150
# Produces e.g. boulder-1.25.0.1754519595-591c0545.x86_64.deb
4251
docker run -v .:/boulderrepo \
52+
-e "ARCH=${ARCH}" \
4353
-e "COMMIT_ID=${COMMIT_ID}" \
4454
-e "VERSION=${VERSION}" \
4555
-e "SOURCE_DATE_EPOCH=${COMMIT_TIMESTAMP}" \

tools/make-deb.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
set -eu
1111
cd "$(realpath -- "$(dirname -- "$0")")/.."
1212

13+
if [ -z "${ARCH:-}" ]; then echo "ARCH not set"; exit 1; fi
14+
if [ -z "${VERSION:-}" ]; then echo "VERSION not set"; exit 1; fi
15+
if [ -z "${COMMIT_ID:-}" ]; then echo "COMMIT_ID not set"; exit 1; fi
16+
1317
BUILD="$(mktemp -d)"
1418

1519
mkdir -p "${BUILD}/opt"
@@ -21,7 +25,7 @@ Package: boulder
2125
Version: 1:${VERSION}
2226
License: Mozilla Public License v2.0
2327
Vendor: ISRG
24-
Architecture: amd64
28+
Architecture: ${ARCH}
2529
Maintainer: Community
2630
Section: default
2731
Priority: extra
@@ -33,4 +37,4 @@ EOF
3337
find "${BUILD}" ! -type l -exec touch -d "@${SOURCE_DATE_EPOCH}" {} \;
3438
find "${BUILD}" -type l -exec touch -h -d "@${SOURCE_DATE_EPOCH}" {} \;
3539

36-
dpkg-deb -Zgzip -b "${BUILD}" "boulder-${VERSION}-${COMMIT_ID}.x86_64.deb"
40+
dpkg-deb -Zgzip -b "${BUILD}" "boulder-${VERSION}-${COMMIT_ID}.${ARCH}.deb"

0 commit comments

Comments
 (0)