Skip to content

Commit

Permalink
Add support for multiarch container images (amd64/arm64)
Browse files Browse the repository at this point in the history
Container images built with support for the ARM architecture
perform much better on Apple Silicon laptops.
  • Loading branch information
ihalaij1 authored and markkuriekkinen committed Jun 22, 2023
1 parent eeae457 commit 4210560
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
7 changes: 5 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM apluslms/service-base:django-1.17
FROM --platform=$TARGETPLATFORM apluslms/service-base:django-1.18

# Set container related configuration via environment variables.
ENV CONTAINER_TYPE="gitmanager" \
Expand All @@ -7,15 +7,18 @@ ENV CONTAINER_TYPE="gitmanager" \
REDIS_HOST="redis" \
HUEY_IMMEDIATE="true"

ARG TARGETPLATFORM

RUN : \
&& apt_install \
apt-transport-https \
rsync \
# temp
gnupg curl \
# install docker-ce
&& if [ "$TARGETPLATFORM" = "linux/amd64" ] ; then ARCH=amd64 ; elif [ "$TARGETPLATFORM" = "linux/arm64" ] ; then ARCH=arm64 ; else exit 1 ; fi \
&& curl -LSs https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg >/dev/null 2>&1 \
&& echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian bullseye stable" > /etc/apt/sources.list.d/docker.list \
&& echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian bullseye stable" > /etc/apt/sources.list.d/docker.list \
&& apt_install docker-ce \
\
# create user
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.huey
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG FULL_TAG=latest
FROM apluslms/run-gitmanager:$FULL_TAG
FROM --platform=$TARGETPLATFORM apluslms/run-gitmanager:$FULL_TAG

ENV CONTAINER_TYPE="gitmanagerhuey" \
GITMANAGER_LOCAL_SETTINGS="/srv/gitmanagerhuey-cont-settings.py" \
Expand All @@ -18,4 +18,4 @@ RUN touch /etc/services.d/postgresql/down \


WORKDIR /srv/gitmanager/
CMD [ "-u", "gitmanager", "--", "manage", "run_huey" ]
CMD [ "-u", "gitmanager", "--", "manage", "run_huey" ]
14 changes: 11 additions & 3 deletions docker/hooks/build
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/sh

docker run --privileged --rm tonistiigi/binfmt --install all

docker buildx create --use default

ver="$DOCKER_TAG"

# Docker Hub builds seem to break if the absolute file path $DOCKERFILE_PATH
Expand All @@ -21,12 +25,16 @@ for layer in "" "huey"; do
echo "### > -t $DOCKER_REPO:$tag ."
echo "### PWD=$(pwd)"

docker build --build-arg "FULL_TAG=$ver" \
-t "$DOCKER_REPO":"$tag" -f "$file" ..
docker buildx build \
--push \
--platform linux/amd64,linux/arm64 \
--build-arg "FULL_TAG=$ver" \
-t "$DOCKER_REPO":"$tag" \
-f "$file" ..

res=$?
if [ $res -ne 0 ]; then
echo "Building layer '$layer' returned $res" >&2
exit $res
fi
done

15 changes: 1 addition & 14 deletions docker/hooks/push
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
#!/bin/sh

ver=${DOCKER_TAG##*-}
if [ "$ver" -a "$ver" = "$DOCKER_TAG" ]; then
ver="$DOCKER_TAG"
fi

for layer in "" "huey"; do
if [ "$layer" ]; then
tag="${layer}-${ver}"
else
tag="$ver"
fi
docker push "$DOCKER_REPO":"$tag"
done

# This hook is empty because the images were pushed to the registry in the build hook

0 comments on commit 4210560

Please sign in to comment.