From 4f820ebce8b10575ab23b9963f8dd40be7ed907e Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Tue, 31 Dec 2019 14:11:22 -0500 Subject: [PATCH 1/8] add hooks and dockerfiles add hooks and dockerfiles --- amd64.dockerfile | 17 +++++++++++++++++ arm32v5.dockerfile | 26 ++++++++++++++++++++++++++ arm32v7.dockerfile | 26 ++++++++++++++++++++++++++ arm64v8.dockerfile | 26 ++++++++++++++++++++++++++ hooks/post_push | 9 +++++++++ hooks/pre_build | 5 +++++ 6 files changed, 109 insertions(+) create mode 100644 amd64.dockerfile create mode 100644 arm32v5.dockerfile create mode 100644 arm32v7.dockerfile create mode 100644 arm64v8.dockerfile create mode 100644 hooks/post_push create mode 100644 hooks/pre_build diff --git a/amd64.dockerfile b/amd64.dockerfile new file mode 100644 index 0000000..4797b82 --- /dev/null +++ b/amd64.dockerfile @@ -0,0 +1,17 @@ +FROM amd64/python:3.7-alpine as base + +FROM base as builder + +# add build utils (gcc, others) +RUN apk add build-base + +FROM base + +COPY . /bumper + +WORKDIR /bumper + +# install required python packages +RUN pip3 install -r requirements.txt + +ENTRYPOINT ["python3", "-m", "bumper"] diff --git a/arm32v5.dockerfile b/arm32v5.dockerfile new file mode 100644 index 0000000..c6736b5 --- /dev/null +++ b/arm32v5.dockerfile @@ -0,0 +1,26 @@ +FROM alpine as builder + +# Download QEMU, see https://github.com/docker/hub-feedback/issues/1261 +ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-arm.tar.gz +RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1 + +FROM arm32v5/python:3.7-alpine as base + +# Add QEMU +COPY --from=builder qemu-arm-static /usr/bin + +FROM base as builder + +# add build utils (gcc, others) +RUN apk add build-base + +FROM base + +COPY . /bumper + +WORKDIR /bumper + +# install required python packages +RUN pip3 install -r requirements.txt + +ENTRYPOINT ["python3", "-m", "bumper"] diff --git a/arm32v7.dockerfile b/arm32v7.dockerfile new file mode 100644 index 0000000..a977d51 --- /dev/null +++ b/arm32v7.dockerfile @@ -0,0 +1,26 @@ +FROM alpine as builder + +# Download QEMU, see https://github.com/docker/hub-feedback/issues/1261 +ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-arm.tar.gz +RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1 + +FROM arm32v7/python:3.7-alpine as base + +# Add QEMU +COPY --from=builder qemu-arm-static /usr/bin + +FROM base as builder + +# add build utils (gcc, others) +RUN apk add build-base + +FROM base + +COPY . /bumper + +WORKDIR /bumper + +# install required python packages +RUN pip3 install -r requirements.txt + +ENTRYPOINT ["python3", "-m", "bumper"] diff --git a/arm64v8.dockerfile b/arm64v8.dockerfile new file mode 100644 index 0000000..a540ec0 --- /dev/null +++ b/arm64v8.dockerfile @@ -0,0 +1,26 @@ +FROM alpine as builder + +# Download QEMU, see https://github.com/docker/hub-feedback/issues/1261 +ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-aarch64.tar.gz +RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1 + +FROM arm64v8/python:3.7-alpine as base + +# Add QEMU +COPY --from=builder qemu-aarch64-static /usr/bin + +FROM base as builder + +# add build utils (gcc, others) +RUN apk add build-base + +FROM base + +COPY . /bumper + +WORKDIR /bumper + +# install required python packages +RUN pip3 install -r requirements.txt + +ENTRYPOINT ["python3", "-m", "bumper"] diff --git a/hooks/post_push b/hooks/post_push new file mode 100644 index 0000000..dc4c90a --- /dev/null +++ b/hooks/post_push @@ -0,0 +1,9 @@ +#!/bin/bash + +# Use manifest-tool to create the manifest, given the experimental +# "docker manifest" command isn't available yet on Docker Hub. + +curl -Lo manifest-tool https://github.com/estesp/manifest-tool/releases/download/v1.0.0/manifest-tool-linux-amd64 +chmod +x manifest-tool + +./manifest-tool push from-spec multi-arch-manifest.yaml \ No newline at end of file diff --git a/hooks/pre_build b/hooks/pre_build new file mode 100644 index 0000000..d5a811d --- /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 From 5d9334fb75b441ff74f6a3ae4349b321db358e4c Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Tue, 31 Dec 2019 14:25:49 -0500 Subject: [PATCH 2/8] add manifest --- multi-arch-manifest.yml | 21 +++++++++++++++++++++ Dockerfile => old_dockerfile | 0 2 files changed, 21 insertions(+) create mode 100644 multi-arch-manifest.yml rename Dockerfile => old_dockerfile (100%) diff --git a/multi-arch-manifest.yml b/multi-arch-manifest.yml new file mode 100644 index 0000000..65a9d57 --- /dev/null +++ b/multi-arch-manifest.yml @@ -0,0 +1,21 @@ +image: bmartin5692/bumper:multiarch +manifests: + - image: bmartin5692/bumper:amd64 + platform: + architecture: amd64 + os: linux + - image: bmartin5692/bumper:arm32v5 + platform: + architecture: arm + os: linux + variant: v5 + - image: bmartin5692/bumper:arm32v7 + platform: + architecture: arm + os: linux + variant: v7 + - image: bmartin5692/bumper:arm64v8 + platform: + architecture: arm64 + os: linux + variant: v8 \ No newline at end of file diff --git a/Dockerfile b/old_dockerfile similarity index 100% rename from Dockerfile rename to old_dockerfile From 2fb540d34a5de65375ea503e10ecf6d2292c1bae Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Tue, 31 Dec 2019 14:47:51 -0500 Subject: [PATCH 3/8] rename dockerfiles --- old_dockerfile => Dockerfile | 0 amd64.dockerfile => Dockerfile.amd64 | 0 arm32v5.dockerfile => Dockerfile.arm32v5 | 0 arm32v7.dockerfile => Dockerfile.arm32v7 | 0 arm64v8.dockerfile => Dockerfile.arm64v8 | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename old_dockerfile => Dockerfile (100%) rename amd64.dockerfile => Dockerfile.amd64 (100%) rename arm32v5.dockerfile => Dockerfile.arm32v5 (100%) rename arm32v7.dockerfile => Dockerfile.arm32v7 (100%) rename arm64v8.dockerfile => Dockerfile.arm64v8 (100%) diff --git a/old_dockerfile b/Dockerfile similarity index 100% rename from old_dockerfile rename to Dockerfile diff --git a/amd64.dockerfile b/Dockerfile.amd64 similarity index 100% rename from amd64.dockerfile rename to Dockerfile.amd64 diff --git a/arm32v5.dockerfile b/Dockerfile.arm32v5 similarity index 100% rename from arm32v5.dockerfile rename to Dockerfile.arm32v5 diff --git a/arm32v7.dockerfile b/Dockerfile.arm32v7 similarity index 100% rename from arm32v7.dockerfile rename to Dockerfile.arm32v7 diff --git a/arm64v8.dockerfile b/Dockerfile.arm64v8 similarity index 100% rename from arm64v8.dockerfile rename to Dockerfile.arm64v8 From f1c603ddaad62753f2f6abf29af59ea56aa1b421 Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Tue, 31 Dec 2019 14:57:01 -0500 Subject: [PATCH 4/8] build push --- hooks/build | 10 ++++++++++ hooks/push | 9 +++++++++ multi-arch-manifest.yml => multi-arch-manifest.yaml | 0 3 files changed, 19 insertions(+) create mode 100644 hooks/build create mode 100644 hooks/push rename multi-arch-manifest.yml => multi-arch-manifest.yaml (100%) diff --git a/hooks/build b/hooks/build new file mode 100644 index 0000000..ef9d4cb --- /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: ckulka/baikal:apache + +for arch in amd64 arm32v5 arm32v7 arm64v8 +do + echo "Building $IMAGE_NAME-$arch" + docker build --build-arg FROM_ARCH=$arch --file $DOCKERFILE_PATH --tag $IMAGE_NAME-$arch . +done \ No newline at end of file diff --git a/hooks/push b/hooks/push new file mode 100644 index 0000000..5efae61 --- /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 arm32v5 arm32v7 arm64v8 +do + echo "Pushing $IMAGE_NAME-$arch" + docker push $IMAGE_NAME-$arch +done \ No newline at end of file diff --git a/multi-arch-manifest.yml b/multi-arch-manifest.yaml similarity index 100% rename from multi-arch-manifest.yml rename to multi-arch-manifest.yaml From 332efa9c94d87e8ed4e2dfaae5a591c98637ce92 Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Tue, 31 Dec 2019 15:03:42 -0500 Subject: [PATCH 5/8] Update multi-arch-manifest.yaml --- multi-arch-manifest.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/multi-arch-manifest.yaml b/multi-arch-manifest.yaml index 65a9d57..b9f9879 100644 --- a/multi-arch-manifest.yaml +++ b/multi-arch-manifest.yaml @@ -1,20 +1,20 @@ image: bmartin5692/bumper:multiarch manifests: - - image: bmartin5692/bumper:amd64 + - image: bmartin5692/bumper:multiarch-amd64 platform: architecture: amd64 os: linux - - image: bmartin5692/bumper:arm32v5 + - image: bmartin5692/bumper:multiarch-arm32v5 platform: architecture: arm os: linux variant: v5 - - image: bmartin5692/bumper:arm32v7 + - image: bmartin5692/bumper:multiarch-arm32v7 platform: architecture: arm os: linux variant: v7 - - image: bmartin5692/bumper:arm64v8 + - image: bmartin5692/bumper:multiarch-arm64v8 platform: architecture: arm64 os: linux From e8817454e5a121542da399e979c19bf068a252da Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Tue, 31 Dec 2019 15:20:17 -0500 Subject: [PATCH 6/8] add FROM_ARCH --- Dockerfile | 17 ++++++++++++++++- Dockerfile.amd64 => old.Dockerfile.amd64 | 0 Dockerfile.arm32v5 => old.Dockerfile.arm32v5 | 0 Dockerfile.arm32v7 => old.Dockerfile.arm32v7 | 0 Dockerfile.arm64v8 => old.Dockerfile.arm64v8 | 0 5 files changed, 16 insertions(+), 1 deletion(-) rename Dockerfile.amd64 => old.Dockerfile.amd64 (100%) rename Dockerfile.arm32v5 => old.Dockerfile.arm32v5 (100%) rename Dockerfile.arm32v7 => old.Dockerfile.arm32v7 (100%) rename Dockerfile.arm64v8 => old.Dockerfile.arm64v8 (100%) diff --git a/Dockerfile b/Dockerfile index 604ddb2..00f5afc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,19 @@ -FROM python:3.7-alpine as base +ARG FROM_ARCH=amd64 + +FROM alpine as builder + +# Download QEMU, see https://github.com/ckulka/docker-multi-arch-example +ADD https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-arm.tar.gz . +RUN tar zxvf qemu-3.0.0+resin-arm.tar.gz --strip-components 1 +ADD https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-aarch64.tar.gz . +RUN tar zxvf qemu-3.0.0+resin-aarch64.tar.gz --strip-components 1 + +FROM $FROM_ARCH/python:3.7-alpine as base + +# Add QEMU +# Add QEMU +COPY --from=builder qemu-arm-static /usr/bin +COPY --from=builder qemu-aarch64-static /usr/bin FROM base as builder diff --git a/Dockerfile.amd64 b/old.Dockerfile.amd64 similarity index 100% rename from Dockerfile.amd64 rename to old.Dockerfile.amd64 diff --git a/Dockerfile.arm32v5 b/old.Dockerfile.arm32v5 similarity index 100% rename from Dockerfile.arm32v5 rename to old.Dockerfile.arm32v5 diff --git a/Dockerfile.arm32v7 b/old.Dockerfile.arm32v7 similarity index 100% rename from Dockerfile.arm32v7 rename to old.Dockerfile.arm32v7 diff --git a/Dockerfile.arm64v8 b/old.Dockerfile.arm64v8 similarity index 100% rename from Dockerfile.arm64v8 rename to old.Dockerfile.arm64v8 From 420f8efb32180f4a86fb0bf859afe7a3f3a9a7ac Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Tue, 31 Dec 2019 15:26:55 -0500 Subject: [PATCH 7/8] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 00f5afc..dde7ee9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ FROM $FROM_ARCH/python:3.7-alpine as base COPY --from=builder qemu-arm-static /usr/bin COPY --from=builder qemu-aarch64-static /usr/bin -FROM base as builder +FROM base as builderfinal # add build utils (gcc, others) RUN apk add build-base From 038bafb368fb6057d5d2b4234a4ccfaf257318f2 Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Tue, 31 Dec 2019 16:05:46 -0500 Subject: [PATCH 8/8] builds Remove armv5 Remove old Dockerfile.arch Generate manifest in post_push --- hooks/build | 2 +- hooks/post_push | 31 ++++++++++++++++++++++++++++--- hooks/push | 2 +- multi-arch-manifest.yaml | 21 --------------------- old.Dockerfile.amd64 | 17 ----------------- old.Dockerfile.arm32v5 | 26 -------------------------- old.Dockerfile.arm32v7 | 26 -------------------------- old.Dockerfile.arm64v8 | 26 -------------------------- 8 files changed, 30 insertions(+), 121 deletions(-) delete mode 100644 multi-arch-manifest.yaml delete mode 100644 old.Dockerfile.amd64 delete mode 100644 old.Dockerfile.arm32v5 delete mode 100644 old.Dockerfile.arm32v7 delete mode 100644 old.Dockerfile.arm64v8 diff --git a/hooks/build b/hooks/build index ef9d4cb..9d5e830 100644 --- a/hooks/build +++ b/hooks/build @@ -3,7 +3,7 @@ # Custom build script to build images for all supported architectures. # Example for IMAGE_NAME: ckulka/baikal:apache -for arch in amd64 arm32v5 arm32v7 arm64v8 +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 . diff --git a/hooks/post_push b/hooks/post_push index dc4c90a..063de94 100644 --- a/hooks/post_push +++ b/hooks/post_push @@ -2,8 +2,33 @@ # Use manifest-tool to create the manifest, given the experimental # "docker manifest" command isn't available yet on Docker Hub. - -curl -Lo manifest-tool https://github.com/estesp/manifest-tool/releases/download/v1.0.0/manifest-tool-linux-amd64 +curl -Lo manifest-tool https://github.com/estesp/manifest-tool/releases/download/v0.9.0/manifest-tool-linux-amd64 chmod +x manifest-tool -./manifest-tool push from-spec multi-arch-manifest.yaml \ No newline at end of file +# Generate the manifest file. +# Parameter 1 is the multi-arch image name, e.g. ckulka/baikal:0.5.1 +# Parameter 2 is the base-image for the variants, e.g. ckulka/baikal:0.5.1-apache +function generate_manifest { + cat > manifest-generated.yaml << EOF +image: $1 +manifests: + - image: $2-amd64 + platform: + architecture: amd64 + os: linux + - image: $2-arm32v7 + platform: + architecture: arm + os: linux + variant: v7 + - image: $2-arm64v8 + platform: + architecture: arm64 + os: linux + variant: v8 +EOF +} + +echo "Pushing multi-arch manifest $IMAGE_NAME" +generate_manifest $IMAGE_NAME $IMAGE_NAME +./manifest-tool push from-spec manifest-generated.yaml \ No newline at end of file diff --git a/hooks/push b/hooks/push index 5efae61..8d65007 100644 --- a/hooks/push +++ b/hooks/push @@ -2,7 +2,7 @@ # Custom build script to push images for all supported architectures. -for arch in amd64 arm32v5 arm32v7 arm64v8 +for arch in amd64 arm32v7 arm64v8 do echo "Pushing $IMAGE_NAME-$arch" docker push $IMAGE_NAME-$arch diff --git a/multi-arch-manifest.yaml b/multi-arch-manifest.yaml deleted file mode 100644 index b9f9879..0000000 --- a/multi-arch-manifest.yaml +++ /dev/null @@ -1,21 +0,0 @@ -image: bmartin5692/bumper:multiarch -manifests: - - image: bmartin5692/bumper:multiarch-amd64 - platform: - architecture: amd64 - os: linux - - image: bmartin5692/bumper:multiarch-arm32v5 - platform: - architecture: arm - os: linux - variant: v5 - - image: bmartin5692/bumper:multiarch-arm32v7 - platform: - architecture: arm - os: linux - variant: v7 - - image: bmartin5692/bumper:multiarch-arm64v8 - platform: - architecture: arm64 - os: linux - variant: v8 \ No newline at end of file diff --git a/old.Dockerfile.amd64 b/old.Dockerfile.amd64 deleted file mode 100644 index 4797b82..0000000 --- a/old.Dockerfile.amd64 +++ /dev/null @@ -1,17 +0,0 @@ -FROM amd64/python:3.7-alpine as base - -FROM base as builder - -# add build utils (gcc, others) -RUN apk add build-base - -FROM base - -COPY . /bumper - -WORKDIR /bumper - -# install required python packages -RUN pip3 install -r requirements.txt - -ENTRYPOINT ["python3", "-m", "bumper"] diff --git a/old.Dockerfile.arm32v5 b/old.Dockerfile.arm32v5 deleted file mode 100644 index c6736b5..0000000 --- a/old.Dockerfile.arm32v5 +++ /dev/null @@ -1,26 +0,0 @@ -FROM alpine as builder - -# Download QEMU, see https://github.com/docker/hub-feedback/issues/1261 -ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-arm.tar.gz -RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1 - -FROM arm32v5/python:3.7-alpine as base - -# Add QEMU -COPY --from=builder qemu-arm-static /usr/bin - -FROM base as builder - -# add build utils (gcc, others) -RUN apk add build-base - -FROM base - -COPY . /bumper - -WORKDIR /bumper - -# install required python packages -RUN pip3 install -r requirements.txt - -ENTRYPOINT ["python3", "-m", "bumper"] diff --git a/old.Dockerfile.arm32v7 b/old.Dockerfile.arm32v7 deleted file mode 100644 index a977d51..0000000 --- a/old.Dockerfile.arm32v7 +++ /dev/null @@ -1,26 +0,0 @@ -FROM alpine as builder - -# Download QEMU, see https://github.com/docker/hub-feedback/issues/1261 -ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-arm.tar.gz -RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1 - -FROM arm32v7/python:3.7-alpine as base - -# Add QEMU -COPY --from=builder qemu-arm-static /usr/bin - -FROM base as builder - -# add build utils (gcc, others) -RUN apk add build-base - -FROM base - -COPY . /bumper - -WORKDIR /bumper - -# install required python packages -RUN pip3 install -r requirements.txt - -ENTRYPOINT ["python3", "-m", "bumper"] diff --git a/old.Dockerfile.arm64v8 b/old.Dockerfile.arm64v8 deleted file mode 100644 index a540ec0..0000000 --- a/old.Dockerfile.arm64v8 +++ /dev/null @@ -1,26 +0,0 @@ -FROM alpine as builder - -# Download QEMU, see https://github.com/docker/hub-feedback/issues/1261 -ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-aarch64.tar.gz -RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1 - -FROM arm64v8/python:3.7-alpine as base - -# Add QEMU -COPY --from=builder qemu-aarch64-static /usr/bin - -FROM base as builder - -# add build utils (gcc, others) -RUN apk add build-base - -FROM base - -COPY . /bumper - -WORKDIR /bumper - -# install required python packages -RUN pip3 install -r requirements.txt - -ENTRYPOINT ["python3", "-m", "bumper"]