Skip to content

Commit 65ed9c7

Browse files
test: Add support for multi-arch docker images (letsencrypt#5837)
1 parent c17946b commit 65ed9c7

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3'
22
services:
33
boulder:
4-
image: &boulder_image letsencrypt/boulder-tools:${BOULDER_TOOLS_TAG:-go1.17_2021-10-22}
4+
image: &boulder_image letsencrypt/boulder-tools:${BOULDER_TOOLS_TAG:-go1.17_2021-12-08}
55
environment:
66
FAKE_DNS: 10.77.77.77
77
BOULDER_CONFIG_DIR: test/config

test/boulder-tools/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
FROM buildpack-deps:focal-scm
22
ARG GO_VERSION
33

4+
# Provided automatically by docker buildx.
5+
ARG TARGETPLATFORM
6+
ARG BUILDPLATFORM
7+
48
# Copied from https://github.com/docker-library/golang/blob/master/Dockerfile-debian.template
59
ENV GOPATH /go
10+
ENV GOARCH=$TARGETARCH
611
ENV PATH $GOPATH/bin:/usr/local/go/bin:/usr/local/protoc/bin:$PATH
712
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
813
WORKDIR $GOPATH
914

10-
RUN wget -O go.tgz "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" && tar -C /usr/local -xzf go.tgz && rm go.tgz;
15+
RUN arch=$(echo $TARGETPLATFORM | sed 's|\/|-|') && wget -O go.tgz "https://dl.google.com/go/go${GO_VERSION}.${arch}.tar.gz" && tar -C /usr/local -xzf go.tgz && rm go.tgz;
1116
COPY requirements.txt /tmp/requirements.txt
1217
COPY boulder.rsyslog.conf /etc/rsyslog.d/
1318
COPY build.sh /tmp/build.sh

test/boulder-tools/build.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ apt-get install -y --no-install-recommends \
2424
autoconf \
2525
automake
2626

27-
curl -L https://github.com/google/protobuf/releases/download/v3.15.6/protoc-3.15.6-linux-x86_64.zip -o /tmp/protoc.zip
27+
PROTO_ARCH=x86_64
28+
if [ "${GOARCH}" = arm64 ]
29+
then
30+
PROTO_ARCH=aarch_64
31+
fi
32+
33+
curl -L https://github.com/google/protobuf/releases/download/v3.15.6/protoc-3.15.6-linux-"${PROTO_ARCH}".zip -o /tmp/protoc.zip
2834
unzip /tmp/protoc.zip -d /usr/local/protoc
2935

3036
# Override default GOBIN and GOCACHE

test/boulder-tools/tag_and_upload.sh

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,25 @@ DOCKER_REPO="letsencrypt/boulder-tools"
77

88
GO_VERSIONS=( "1.17" )
99

10-
# Build a tagged image for each GO_VERSION
11-
for GO_VERSION in "${GO_VERSIONS[@]}"
12-
do
13-
TAG_NAME="$DOCKER_REPO:go${GO_VERSION}_${DATESTAMP}"
14-
echo "Building boulder-tools image $TAG_NAME"
15-
16-
# Build the docker image using the templated Dockerfile, tagging it with
17-
# TAG_NAME
18-
docker build . \
19-
-t $TAG_NAME \
20-
--build-arg "GO_VERSION=${GO_VERSION}"
21-
done
22-
23-
# Log in once now that images are ready to upload
24-
echo "Images ready, please login to allow Dockerhub push"
10+
echo "Please login to allow push to DockerHub"
2511
docker login
2612

27-
# Upload a tagged image for each GO_VERSION
13+
# Build and push a tagged image for each GO_VERSION.
2814
for GO_VERSION in "${GO_VERSIONS[@]}"
2915
do
30-
TAG_NAME="$DOCKER_REPO:go${GO_VERSION}_${DATESTAMP}"
31-
echo "Pushing ${TAG_NAME} to Dockerhub"
32-
docker push ${TAG_NAME}
16+
TAG_NAME="${DOCKER_REPO}:go${GO_VERSION}_${DATESTAMP}"
17+
echo "Building boulder-tools image ${TAG_NAME}"
18+
19+
# create a docker buildx node for cross-compilation.
20+
docker buildx create --use --name=cross
21+
22+
# build, tag, and push the image.
23+
docker buildx build --build-arg "GO_VERSION=${GO_VERSION}" \
24+
--push --tag "${TAG_NAME}" \
25+
--platform=linux/amd64,linux/arm64 .
26+
27+
# delete the docker buildx node.
28+
docker buildx rm cross
3329
done
3430

3531
# TODO(@cpu): Figure out a `sed` for updating the date in `docker-compose.yml`'s

0 commit comments

Comments
 (0)