From 3585575d68cc51a4b23356715b54e9166082b0f4 Mon Sep 17 00:00:00 2001 From: Bockiii Date: Thu, 13 May 2021 19:57:10 +0200 Subject: [PATCH] [Docker] Add support for arm32/64 (#2104) --- Dockerfile | 21 ++++++++++++++++++++- hooks/build | 10 ++++++++++ hooks/post_push | 34 ++++++++++++++++++++++++++++++++++ hooks/pre_build | 5 +++++ hooks/push | 9 +++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 hooks/build create mode 100644 hooks/post_push create mode 100644 hooks/pre_build create mode 100644 hooks/push diff --git a/Dockerfile b/Dockerfile index 4b844541d58..ef1084088ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,23 @@ -FROM php:7-apache +ARG FROM_ARCH=amd64 + +# Multi-stage build, see https://docs.docker.com/develop/develop-images/multistage-build/ +FROM alpine AS builder + +# Download QEMU +ADD https://github.com/balena-io/qemu/releases/download/v5.2.0%2Bbalena4/qemu-5.2.0.balena4-arm.tar.gz . +RUN tar zxvf qemu-5.2.0.balena4-arm.tar.gz --strip-components 1 +ADD https://github.com/balena-io/qemu/releases/download/v5.2.0%2Bbalena4/qemu-5.2.0.balena4-aarch64.tar.gz . +RUN tar zxvf qemu-5.2.0.balena4-aarch64.tar.gz --strip-components 1 + +FROM $FROM_ARCH/php:7-apache + +LABEL description="RSS-Bridge is a PHP project capable of generating RSS and Atom feeds for websites that don't have one." +LABEL repository="https://github.com/RSS-Bridge/rss-bridge" +LABEL website="https://github.com/RSS-Bridge/rss-bridge" + +# Add QEMU +COPY --from=builder qemu-arm-static /usr/bin +COPY --from=builder qemu-aarch64-static /usr/bin ENV APACHE_DOCUMENT_ROOT=/app diff --git a/hooks/build b/hooks/build new file mode 100644 index 00000000000..4d9e99abdc7 --- /dev/null +++ b/hooks/build @@ -0,0 +1,10 @@ +#!/bin/bash + +# Custom build script to build images for all supported architectures. +# Example for IMAGE_NAME: rss-builder/rss-builder:stable + +for arch in amd64 arm32v7 arm64v8 +do + echo "Building $IMAGE_NAME-$arch" + docker build --build-arg FROM_ARCH=$arch --file $DOCKERFILE_PATH --tag $IMAGE_NAME-$arch . +done diff --git a/hooks/post_push b/hooks/post_push new file mode 100644 index 00000000000..45db96dfe45 --- /dev/null +++ b/hooks/post_push @@ -0,0 +1,34 @@ +#!/bin/bash + +# Use manifest-tool to create the manifest, given the experimental +# "docker manifest" command isn't available yet on Docker Hub. +MANIFEST_TOOL_VERSION=$(curl -s https://api.github.com/repos/estesp/manifest-tool/releases/latest | grep 'tag_name' | cut -d\" -f4) +curl -Lo manifest-tool https://github.com/estesp/manifest-tool/releases/download/$MANIFEST_TOOL_VERSION/manifest-tool-linux-amd64 +chmod +x manifest-tool + +# Generate the manifest file. +# Parameter 1 is the multi-arch image name, e.g. rss-bridge/rss-bridge:stable +function generate_manifest { + cat > manifest-generated.yaml << EOF +image: $1 +manifests: + - image: $1-amd64 + platform: + architecture: amd64 + os: linux + - image: $1-arm32v7 + platform: + architecture: arm + os: linux + variant: v7 + - image: $1-arm64v8 + platform: + architecture: arm64 + os: linux + variant: v8 +EOF +} + +echo "Pushing multi-arch manifest $IMAGE_NAME" +generate_manifest $IMAGE_NAME +./manifest-tool push from-spec manifest-generated.yaml diff --git a/hooks/pre_build b/hooks/pre_build new file mode 100644 index 00000000000..76a62755c7f --- /dev/null +++ b/hooks/pre_build @@ -0,0 +1,5 @@ +#!/bin/bash + +# Register qemu-*-static for all supported processors except the +# current one, but also remove all registered binfmt_misc before +docker run --rm --privileged multiarch/qemu-user-static:register --reset \ No newline at end of file diff --git a/hooks/push b/hooks/push new file mode 100644 index 00000000000..297ddd050a9 --- /dev/null +++ b/hooks/push @@ -0,0 +1,9 @@ +#!/bin/bash + +# Custom build script to push images for all supported architectures. + +for arch in amd64 arm32v7 arm64v8 +do + echo "Pushing $IMAGE_NAME-$arch" + docker push $IMAGE_NAME-$arch +done