diff --git a/.forgejo/workflows/docker-publish-semantic.yml b/.forgejo/workflows/docker-publish-semantic.yml index 9219343..daba10d 100644 --- a/.forgejo/workflows/docker-publish-semantic.yml +++ b/.forgejo/workflows/docker-publish-semantic.yml @@ -20,14 +20,22 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - build-and-push-semantic: - runs-on: docker + build: + runs-on: ${{ matrix.runner }} container: image: node:lts-bookworm options: --privileged permissions: contents: read packages: write + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + runner: docker-amd64 + - platform: linux/arm64 + runner: docker-arm64 steps: - name: Install Docker @@ -53,9 +61,6 @@ jobs: "https://oauth2:${{ github.token }}@bitfreedom.net/code/${{ github.repository }}.git" \ . - - name: Set up QEMU (for multi-arch builds) - uses: https://github.com/docker/setup-qemu-action@v3 - - name: Set up Docker Buildx uses: https://github.com/docker/setup-buildx-action@v3 with: @@ -68,29 +73,77 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.REGISTRY_TOKEN }} + - name: Build and push platform image + id: build + uses: https://github.com/docker/build-push-action@v6 + with: + context: . + platforms: ${{ matrix.platform }} + push: true + provenance: false + build-args: | + SEMANTIC_CACHE=true + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-semantic-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-semantic-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-semantic-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }},mode=max + + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + uses: https://github.com/actions/upload-artifact@v4 + with: + name: digest-semantic-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: docker-amd64 + needs: build + permissions: + contents: read + packages: write + steps: + - name: Download digests + uses: https://github.com/actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digest-semantic-* + merge-multiple: true + + - name: Install Docker + run: | + apt-get update -qq + apt-get install -y -qq docker.io + + - name: Set up Docker Buildx + uses: https://github.com/docker/setup-buildx-action@v3 + + - name: Log in to Forgejo Container Registry + uses: https://github.com/docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.REGISTRY_TOKEN }} + - name: Extract Docker metadata id: meta uses: https://github.com/docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - # Versioned semantic tags on git tags (e.g. v0.7.0 → 0.7.0-semantic, 0.7-semantic) type=semver,pattern={{version}}-semantic type=semver,pattern={{major}}.{{minor}}-semantic - # latest-semantic only on main branch pushes type=raw,value=latest-semantic,enable=${{ github.ref == 'refs/heads/main' }} - # SHA-tagged for traceability type=sha,prefix=sha-,suffix=-semantic - - name: Build and push semantic Docker image - uses: https://github.com/docker/build-push-action@v6 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - build-args: | - SEMANTIC_CACHE=true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-semantic - cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-semantic,mode=max + - name: Create and push multi-arch manifest + working-directory: /tmp/digests + run: | + docker buildx imagetools create \ + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) diff --git a/.forgejo/workflows/docker-publish.yml b/.forgejo/workflows/docker-publish.yml index 3305b7d..d53c83c 100644 --- a/.forgejo/workflows/docker-publish.yml +++ b/.forgejo/workflows/docker-publish.yml @@ -13,14 +13,22 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - build-and-push: - runs-on: docker + build: + runs-on: ${{ matrix.runner }} container: image: node:lts-bookworm options: --privileged permissions: contents: read packages: write + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + runner: docker-amd64 + - platform: linux/arm64 + runner: docker-arm64 steps: - name: Install Docker @@ -46,9 +54,6 @@ jobs: "https://oauth2:${{ github.token }}@bitfreedom.net/code/${{ github.repository }}.git" \ . - - name: Set up QEMU (for multi-arch builds) - uses: https://github.com/docker/setup-qemu-action@v3 - - name: Set up Docker Buildx uses: https://github.com/docker/setup-buildx-action@v3 with: @@ -61,27 +66,75 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.REGISTRY_TOKEN }} + - name: Build and push platform image + id: build + uses: https://github.com/docker/build-push-action@v6 + with: + context: . + platforms: ${{ matrix.platform }} + push: true + provenance: false + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }},mode=max + + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + uses: https://github.com/actions/upload-artifact@v4 + with: + name: digest-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: docker-amd64 + needs: build + permissions: + contents: read + packages: write + steps: + - name: Download digests + uses: https://github.com/actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digest-* + merge-multiple: true + + - name: Install Docker + run: | + apt-get update -qq + apt-get install -y -qq docker.io + + - name: Set up Docker Buildx + uses: https://github.com/docker/setup-buildx-action@v3 + + - name: Log in to Forgejo Container Registry + uses: https://github.com/docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.REGISTRY_TOKEN }} + - name: Extract Docker metadata id: meta uses: https://github.com/docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - # Tag with version on git tags (e.g. v0.7.0 → 0.7.0 and 0.7) type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - # Tag latest only on main branch pushes type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} - # Tag with short SHA for traceability type=sha,prefix=sha- - - name: Build and push Docker image - uses: https://github.com/docker/build-push-action@v6 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache - cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max + - name: Create and push multi-arch manifest + working-directory: /tmp/digests + run: | + docker buildx imagetools create \ + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)