Skip to content

Commit 9db87c3

Browse files
committed
Enhance platform support in Docker build scripts for Boulder
- Added TARGETPLATFORM argument to Containerfile for architecture-specific builds. - Updated container-build.sh to detect architecture and set appropriate platform. - Modified make-deb.sh to dynamically set the architecture in the .deb package.
1 parent 3250145 commit 9db87c3

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

Containerfile

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

1011
ENV DEBIAN_FRONTEND=noninteractive
1112
RUN apt-get --assume-yes --no-install-recommends --update install \
1213
ca-certificates curl gcc git gnupg2 libc6-dev
1314

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

tools/container-build.sh

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,53 @@
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)"
2315
COMMIT_ID="$(git rev-parse --short=8 HEAD)"
2416
VERSION="${GO_VERSION}.$(date +%s)"
2517

18+
# Detect architecture to build for (allow override via DOCKER_DEFAULT_PLATFORM)
19+
if [ -n "${DOCKER_DEFAULT_PLATFORM}" ]; then
20+
PLATFORM="${DOCKER_DEFAULT_PLATFORM}"
21+
else
22+
case "$(uname -m)" in
23+
"x86_64") PLATFORM="linux/amd64" ;;
24+
"aarch64"|"arm64") PLATFORM="linux/arm64" ;;
25+
*) echo "Unsupported architecture: $(uname -m)" && exit 1 ;;
26+
esac
27+
fi
28+
29+
# Extract architecture from platform
30+
case "$PLATFORM" in
31+
"linux/amd64") ARCH="amd64" ;;
32+
"linux/arm64") ARCH="arm64" ;;
33+
*) echo "Unsupported platform: ${PLATFORM}" && exit 1 ;;
34+
esac
35+
36+
# Create platform-specific image
2637
docker buildx build \
2738
--file Containerfile \
39+
--platform "$PLATFORM" \
2840
--build-arg "COMMIT_ID=${COMMIT_ID}" \
2941
--build-arg "GO_VERSION=${GO_VERSION}" \
3042
--build-arg "VERSION=${VERSION}" \
43+
--tag "boulder:${VERSION}-${ARCH}" \
3144
--tag "boulder:${VERSION}" \
3245
--tag "boulder:${COMMIT_ID}" \
3346
--tag boulder \
47+
--load \
3448
.
3549

36-
docker run boulder tar -C /opt/boulder -cpz . > "./boulder-${VERSION}-${COMMIT_ID}.${ARCH}.tar.gz" .
37-
# Produces e.g. boulder-1.25.0.1754519595-591c0545.x86_64.deb
50+
# Create tarball
51+
docker run "boulder:${VERSION}-${ARCH}" tar -C /opt/boulder -cpz . > "./boulder-${VERSION}-${COMMIT_ID}.${ARCH}.tar.gz"
52+
53+
# Create .deb package
3854
docker run -v .:/boulderrepo \
39-
-e "COMMIT_ID=$(git rev-parse --short=8 HEAD)" \
40-
-e "VERSION=${VERSION}" \
41-
boulder \
42-
/boulderrepo/tools/make-deb.sh
55+
-e "COMMIT_ID=${COMMIT_ID}" \
56+
-e "VERSION=${VERSION}" \
57+
-e "ARCH=${ARCH}" \
58+
"boulder:${VERSION}-${ARCH}" \
59+
/boulderrepo/tools/make-deb.sh

tools/make-deb.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,29 @@ BUILD="$(mktemp -d)"
1515
mkdir -p "${BUILD}/opt"
1616
cp -a /opt/boulder "${BUILD}/opt/boulder"
1717

18+
# Determine architecture - use ARCH env var if set, otherwise detect from uname
19+
if [ -n "${ARCH:-}" ]; then
20+
DEB_ARCH="${ARCH}"
21+
else
22+
case "$(uname -m)" in
23+
"x86_64") DEB_ARCH="amd64" ;;
24+
"aarch64"|"arm64") DEB_ARCH="arm64" ;;
25+
*) echo "Unsupported architecture: $(uname -m)" && exit 1 ;;
26+
esac
27+
fi
28+
1829
mkdir -p "${BUILD}/DEBIAN"
1930
cat > "${BUILD}/DEBIAN/control" <<-EOF
2031
Package: boulder
2132
Version: 1:${VERSION}
2233
License: Mozilla Public License v2.0
2334
Vendor: ISRG
24-
Architecture: amd64
35+
Architecture: ${DEB_ARCH}
2536
Maintainer: Community
2637
Section: default
2738
Priority: extra
2839
Homepage: https://github.com/letsencrypt/boulder
2940
Description: Boulder is an ACME-compatible X.509 Certificate Authority
3041
EOF
3142

32-
dpkg-deb -Zgzip -b "${BUILD}" "boulder-${VERSION}-${COMMIT_ID}.x86_64.deb"
43+
dpkg-deb -Zgzip -b "${BUILD}" "boulder-${VERSION}-${COMMIT_ID}.${DEB_ARCH}.deb"

0 commit comments

Comments
 (0)