From e3b200e6b5f6bf7eef23969be939e04717298d57 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 4 Apr 2025 18:59:31 +0200 Subject: [PATCH] Build Docker image for ARM First pass Fix? Minor Dockerfile fixes Fix yet another lint problem Fix? Fix?? Fix 2 Fix? Remove step hopefully this time Fixes to annotations Fix again? Final touch I am stupid Fix --- .github/workflows/docker_image.yml | 149 +++++++++++++++++++++++------ Dockerfile | 7 +- 2 files changed, 126 insertions(+), 30 deletions(-) diff --git a/.github/workflows/docker_image.yml b/.github/workflows/docker_image.yml index 0ea0ad6ca..29690e0cf 100644 --- a/.github/workflows/docker_image.yml +++ b/.github/workflows/docker_image.yml @@ -37,11 +37,19 @@ on: env: REGISTRY: ghcr.io # github.repository as / + # sadly there is no way to lowercase the string, so in some occurences we have to do it in a dedicated step IMAGE_NAME: ${{ github.repository }} jobs: - publish: - runs-on: ubuntu-latest + build: + runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }} + + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 permissions: contents: read @@ -51,48 +59,133 @@ jobs: - name: Check out repository uses: actions/checkout@v4 + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - name: Setup Docker buildx - uses: docker/setup-buildx-action@v3.0.0 + uses: docker/setup-buildx-action@v3.10.0 - # Login against the Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' - uses: docker/login-action@v3.0.0 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # Extract metadata (tags, labels) for Docker + # Extract metadata (tags, labels, annotations) for Docker # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta - uses: docker/metadata-action@v5.5.0 + uses: docker/metadata-action@v5.7.0 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} labels: | org.opencontainers.image.title=Luanti org.opencontainers.image.vendor=Luanti + org.opencontainers.image.description=Luanti (formerly Minetest) is an open source voxel game-creation platform with easy modding and game creation org.opencontainers.image.licenses=LGPL-2.1-only + annotations: | + org.opencontainers.image.title=Luanti + org.opencontainers.image.vendor=Luanti + org.opencontainers.image.description=Luanti (formerly Minetest) is an open source voxel game-creation platform with easy modding and game creation + org.opencontainers.image.licenses=LGPL-2.1-only + + # Login against the Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3.4.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get image name + run: + echo "IMAGE_NAME_LOWERCASE"="${IMAGE_NAME,,}" >> $GITHUB_ENV - # Build and push Docker image - # https://github.com/docker/build-push-action - # No arm support for now. Require cross-compilation support in Dockerfile to not use QEMU. - - name: Build and push Docker image - uses: docker/build-push-action@v5.1.0 + - name: Build and push by digest + id: build + uses: docker/build-push-action@v6.15.0 with: context: . - platforms: linux/amd64 - push: ${{ github.event_name != 'pull_request' }} - load: true - tags: ${{ steps.meta.outputs.tags }} + platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} + annotations: ${{ steps.meta.outputs.annotations }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWERCASE }} + outputs: type=image,push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }} cache-from: type=gha cache-to: type=gha,mode=max no-cache: ${{ (github.event_name == 'workflow_dispatch' && !inputs.use_cache) || startsWith(github.ref, 'refs/tags/') }} - - - name: Test Docker Image + + - name: Export digest + if: github.event_name != 'pull_request' run: | - docker run --rm $(cut -d, -f1 <<<"$DOCKER_METADATA_OUTPUT_TAGS") luantiserver --version - shell: bash + mkdir -p ${{ runner.temp }}/digests + digest="${{ steps.build.outputs.digest }}" + touch "${{ runner.temp }}/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + if: github.event_name != 'pull_request' + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: ${{ runner.temp }}/digests/* + if-no-files-found: error + retention-days: 1 + + push: + runs-on: ubuntu-24.04 + needs: build + if: github.event_name != 'pull_request' + + permissions: + contents: read + packages: write + + steps: + - name: Download digests + uses: actions/download-artifact@v4.2.1 + with: + path: ${{ runner.temp }}/digests + pattern: digests-* + merge-multiple: true + + - name: Get image name + run: + echo "IMAGE_NAME_LOWERCASE"="${IMAGE_NAME,,}" >> $GITHUB_ENV + + # Login against the Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3.4.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3.10.0 + + # Extract metadata (tags, labels, annotations) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5.7.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + labels: | + org.opencontainers.image.title=Luanti + org.opencontainers.image.vendor=Luanti + org.opencontainers.image.description=Luanti (formerly Minetest) is an open source voxel game-creation platform with easy modding and game creation + org.opencontainers.image.licenses=LGPL-2.1-only + annotations: | + org.opencontainers.image.title=Luanti + org.opencontainers.image.vendor=Luanti + org.opencontainers.image.description=Luanti (formerly Minetest) is an open source voxel game-creation platform with easy modding and game creation + org.opencontainers.image.licenses=LGPL-2.1-only + + - name: Create manifest list and push + working-directory: ${{ runner.temp }}/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWERCASE }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWERCASE }}:${{ steps.meta.outputs.version }} diff --git a/Dockerfile b/Dockerfile index c9a9848c5..59a69837c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,10 @@ +# syntax=docker/dockerfile:1 +# check=error=true + ARG DOCKER_IMAGE=alpine:3.19 FROM $DOCKER_IMAGE AS dev -ENV LUAJIT_VERSION v2.1 +ENV LUAJIT_VERSION=v2.1 RUN apk add --no-cache git build-base cmake curl-dev zlib-dev zstd-dev \ sqlite-dev postgresql-dev hiredis-dev leveldb-dev \ @@ -30,7 +33,7 @@ RUN git clone --recursive https://github.com/jupp0r/prometheus-cpp && \ make amalg && make install && \ cd /usr/src/ -FROM dev as builder +FROM dev AS builder COPY .git /usr/src/luanti/.git COPY CMakeLists.txt /usr/src/luanti/CMakeLists.txt