Skip to content

Commit 571543f

Browse files
authored
fix(docker): fix base image for multi-platform build (runatlantis#2099)
* Correct indentation of run commands * Split installation of packages into the ones needed at run time and build time This allows us to now repeat the packages which need to be uninstalled again by making use of a virtual package, which - when removed - removes the packages installed as a dependency of it. * Remove unnecessary `rm -rf /var/cache/apk/*` command It's no needed when `apt add` is run with the `--no-cache` option. * Add vertical spacing so it's clearer what is happening when * Test the downloaded binaries to make sure they work on the platform This can help find issues where binaries are downloaded for the wrong platform compared to the architecture the Docker image is built for. * Install dumb-init via apk It's available as a package for Alpine Linux in version 1.2.5 as well, which makes it easier to handle for the different architectures. * Get git-lfs binaries in the right architecture for the Docker image This makes use of the `TARGETPLATFORM` argument which automatically is populated by Docker BuildKit with a string such as "linux/amd64" when the image is being build for an x86_64 architecture. * Install gosu for the right architecture The `case` statement was taken from https://github.com/BretFisher/multi-platform-docker-build as a way of translating the platform name into what we needed for downloading gosu.
1 parent 23e2b15 commit 571543f

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

docker-base/Dockerfile

+31-15
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,35 @@ RUN addgroup atlantis && \
1717
chmod g=u /home/atlantis/ && \
1818
chmod g=u /etc/passwd
1919

20-
# Install dumb-init, gosu and git-lfs.
21-
ENV DUMB_INIT_VERSION=1.2.5
20+
# Install gosu and git-lfs.
2221
ENV GOSU_VERSION=1.14
2322
ENV GIT_LFS_VERSION=3.1.2
24-
RUN apk add --no-cache ca-certificates gnupg curl git unzip bash openssh libcap openssl && \
25-
curl -L -s --output /bin/dumb-init "https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_x86_64" && \
26-
chmod +x /bin/dumb-init && \
23+
24+
# Automatically populated with the architecture the image is being built for.
25+
ARG TARGETPLATFORM
26+
27+
# Install packages needed for running Atlantis.
28+
RUN apk add --no-cache ca-certificates curl git unzip bash openssh libcap dumb-init && \
29+
# Install packages needed for building dependencies.
30+
apk add --no-cache --virtual .build-deps gnupg openssl && \
2731
mkdir -p /tmp/build && \
2832
cd /tmp/build && \
29-
curl -L -s --output git-lfs.tar.gz "https://github.com/git-lfs/git-lfs/releases/download/v${GIT_LFS_VERSION}/git-lfs-linux-amd64-v${GIT_LFS_VERSION}.tar.gz" && \
33+
34+
# git-lfs
35+
curl -L -s --output git-lfs.tar.gz "https://github.com/git-lfs/git-lfs/releases/download/v${GIT_LFS_VERSION}/git-lfs-linux-${TARGETPLATFORM##*/}-v${GIT_LFS_VERSION}.tar.gz" && \
3036
tar -xf git-lfs.tar.gz && \
3137
chmod +x git-lfs && \
3238
mv git-lfs /usr/bin/git-lfs && \
33-
curl -L -s --output gosu "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64" && \
34-
curl -L -s --output gosu.asc "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64.asc" && \
39+
git-lfs --version && \
40+
41+
# gosu
42+
case ${TARGETPLATFORM} in \
43+
"linux/amd64") GOSU_ARCH=amd64 ;; \
44+
"linux/arm64") GOSU_ARCH=arm64 ;; \
45+
"linux/arm/v7") GOSU_ARCH=armhf ;; \
46+
esac && \
47+
curl -L -s --output gosu "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${GOSU_ARCH}" && \
48+
curl -L -s --output gosu.asc "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${GOSU_ARCH}.asc" && \
3549
for server in $(shuf -e ipv4.pool.sks-keyservers.net \
3650
hkp://p80.pool.sks-keyservers.net:80 \
3751
keyserver.ubuntu.com \
@@ -42,13 +56,15 @@ RUN apk add --no-cache ca-certificates gnupg curl git unzip bash openssh libcap
4256
gpg --batch --verify gosu.asc gosu && \
4357
chmod +x gosu && \
4458
cp gosu /bin && \
45-
cd /tmp && \
46-
rm -rf /tmp/build && \
47-
gpgconf --kill dirmngr && \
48-
gpgconf --kill gpg-agent && \
49-
apk del gnupg openssl && \
50-
rm -rf /root/.gnupg && \
51-
rm -rf /var/cache/apk/*
59+
gosu --version && \
60+
61+
# Cleanup
62+
cd /tmp && \
63+
rm -rf /tmp/build && \
64+
gpgconf --kill dirmngr && \
65+
gpgconf --kill gpg-agent && \
66+
apk del .build-deps && \
67+
rm -rf /root/.gnupg
5268

5369
# Set up nsswitch.conf for Go's "netgo" implementation
5470
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275

0 commit comments

Comments
 (0)