From 8e5b86e6e89fb8feabcec65feaeb7b9e5d653aaa Mon Sep 17 00:00:00 2001 From: Badlop Date: Fri, 17 Jan 2025 10:18:34 +0100 Subject: [PATCH] Container: Build arm64 in runner instead of QEMU, then merge and clean --- .github/workflows/container.yml | 111 ++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 6 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 0bb169ccc..3293594bf 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -15,9 +15,15 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - container: + + build-amd64: name: Container - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04${{ matrix.runner-suffix }} + strategy: + matrix: + include: + - platform: amd64 + runner-suffix: permissions: packages: write steps: @@ -48,14 +54,12 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: suffix=--${{ matrix.platform }},latest=false labels: | org.opencontainers.image.revision=${{ steps.gitdescribe.outputs.ver }} org.opencontainers.image.licenses=GPL-2.0 org.opencontainers.image.vendor=ProcessOne - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -69,6 +73,101 @@ jobs: context: . file: .github/container/Dockerfile labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64,linux/arm64 + platforms: linux/${{ matrix.platform }} push: true tags: ${{ steps.meta.outputs.tags }} + + build-arm64: + name: Container + runs-on: ubuntu-24.04${{ matrix.runner-suffix }} + strategy: + matrix: + include: + - platform: arm64 + runner-suffix: -arm + permissions: + packages: write + steps: + - name: Check out repository code + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Checkout ejabberd-contrib + uses: actions/checkout@v5 + with: + repository: processone/ejabberd-contrib + path: .ejabberd-modules/sources/ejabberd-contrib + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get git describe + id: gitdescribe + run: echo "ver=$(git describe --tags)" >> $GITHUB_OUTPUT + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: suffix=--${{ matrix.platform }},latest=false + labels: | + org.opencontainers.image.revision=${{ steps.gitdescribe.outputs.ver }} + org.opencontainers.image.licenses=GPL-2.0 + org.opencontainers.image.vendor=ProcessOne + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + build-args: | + VERSION=${{ steps.gitdescribe.outputs.ver }} + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + file: .github/container/Dockerfile + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/${{ matrix.platform }} + push: true + tags: ${{ steps.meta.outputs.tags }} + + merge: + needs: + - build-amd64 + - build-arm64 + runs-on: ubuntu-24.04 + outputs: + image-uri: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.merge.outputs.digest }} + steps: + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/metadata-action@v5 + id: metadata + with: + images: ghcr.io/${{ github.repository }} + - uses: int128/docker-manifest-create-action@v2 + id: merge + with: + index-annotations: ${{ steps.metadata.outputs.labels }} + tags: ${{ steps.metadata.outputs.tags }} + sources: | + ${{ steps.metadata.outputs.tags }}--amd64 + ${{ steps.metadata.outputs.tags }}--arm64 + - uses: dataaxiom/ghcr-cleanup-action@v1 + with: + dry-run: true + delete-tags: '*--a??64' + delete-untagged: true + delete-ghost-images: true + delete-partial-images: true + delete-orphaned-images: true