From 64f9c3a250fd529dd6f5678d386c524f61672f11 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 10 Apr 2023 13:31:08 -0500 Subject: [PATCH] Add multi-architecture image build (#314) --- .github/workflows/ci.yml | 21 +++++++-------------- Dockerfile | 19 +++++++++---------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dea60ec..0bc56b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,20 +19,12 @@ jobs: if: github.repository == 'itzg/docker-minecraft-bedrock-server' steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - name: Login to DockerHub if: github.event_name != 'pull_request' uses: docker/login-action@v2 @@ -42,17 +34,18 @@ jobs: - name: Docker Metadata action id: meta - uses: docker/metadata-action@v4.3.0 + uses: docker/metadata-action@v4 with: images: itzg/minecraft-bedrock-server flavor: | - latest=${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + latest=${{ github.event_name == 'push' && github.ref_name == 'master' }} - name: Build and push - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v4 with: - context: . push: ${{ github.event_name != 'pull_request' }} + provenance: false + platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: | ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 6737396..13429cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,8 @@ FROM debian -# ARCH is only set to avoid repetition in Dockerfile, use --build-arg ARCH=arm64 for arm cpu -ARG ARCH=amd64 - -ARG APT_UPDATE=20210112 +# hook into docker BuildKit --platform support +# see https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope +ARG TARGETARCH RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ @@ -14,7 +13,7 @@ RUN apt-get update && \ && rm -rf /var/lib/apt/lists/* # Instal box64 on arm -RUN if [ "$ARCH" = "arm64" ] ; then \ +RUN if [ "$TARGETARCH" = "arm64" ] ; then \ apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y debian-keyring && \ curl -L https://ryanfortner.github.io/box64-debs/box64.list -o /etc/apt/sources.list.d/box64.list && \ @@ -34,16 +33,16 @@ WORKDIR /data ENTRYPOINT ["/usr/local/bin/entrypoint-demoter", "--match", "/data", "--debug", "--stdin-on-term", "stop", "/opt/bedrock-entry.sh"] ARG EASY_ADD_VERSION=0.7.0 -ADD https://github.com/itzg/easy-add/releases/download/${EASY_ADD_VERSION}/easy-add_linux_${ARCH} /usr/local/bin/easy-add +ADD https://github.com/itzg/easy-add/releases/download/${EASY_ADD_VERSION}/easy-add_linux_${TARGETARCH} /usr/local/bin/easy-add RUN chmod +x /usr/local/bin/easy-add -RUN easy-add --var version=0.4.0 --var app=entrypoint-demoter --file {{.app}} --from https://github.com/itzg/{{.app}}/releases/download/v{{.version}}/{{.app}}_{{.version}}_linux_${ARCH}.tar.gz +RUN easy-add --var version=0.4.0 --var app=entrypoint-demoter --file {{.app}} --from https://github.com/itzg/{{.app}}/releases/download/v{{.version}}/{{.app}}_{{.version}}_linux_${TARGETARCH}.tar.gz -RUN easy-add --var version=0.1.1 --var app=set-property --file {{.app}} --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_linux_${ARCH}.tar.gz +RUN easy-add --var version=0.1.1 --var app=set-property --file {{.app}} --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_linux_${TARGETARCH}.tar.gz -RUN easy-add --var version=1.6.1 --var app=restify --file {{.app}} --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_linux_${ARCH}.tar.gz +RUN easy-add --var version=1.6.1 --var app=restify --file {{.app}} --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_linux_${TARGETARCH}.tar.gz -RUN easy-add --var version=0.5.0 --var app=mc-monitor --file {{.app}} --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_linux_${ARCH}.tar.gz +RUN easy-add --var version=0.5.0 --var app=mc-monitor --file {{.app}} --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_linux_${TARGETARCH}.tar.gz COPY *.sh /opt/