|
| 1 | +name: Build & Publish Moltis multi-arch image to GHCR |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master, main ] |
| 6 | + paths: |
| 7 | + - 'vendor/moltis/**' |
| 8 | + - '.github/workflows/build-docker-moltis.yml' |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + image_tag: |
| 12 | + description: 'Docker image tag (default: latest)' |
| 13 | + required: false |
| 14 | + default: 'latest' |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + packages: write |
| 19 | + |
| 20 | +env: |
| 21 | + IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-moltis |
| 22 | + |
| 23 | +jobs: |
| 24 | + prepare: |
| 25 | + name: Prepare tag |
| 26 | + runs-on: ubuntu-latest |
| 27 | + outputs: |
| 28 | + tag: ${{ steps.tag.outputs.tag }} |
| 29 | + steps: |
| 30 | + - name: Resolve image tag |
| 31 | + id: tag |
| 32 | + run: | |
| 33 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.image_tag }}" ]; then |
| 34 | + TAG="${{ github.event.inputs.image_tag }}" |
| 35 | + else |
| 36 | + TAG="latest" |
| 37 | + fi |
| 38 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 39 | + echo "Using image tag: $TAG" |
| 40 | +
|
| 41 | + build-amd64: |
| 42 | + name: Build AMD64 image |
| 43 | + needs: prepare |
| 44 | + runs-on: ubuntu-latest |
| 45 | + steps: |
| 46 | + - name: Checkout code |
| 47 | + uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Set up QEMU |
| 50 | + uses: docker/setup-qemu-action@v3 |
| 51 | + |
| 52 | + - name: Set up Docker Buildx |
| 53 | + uses: docker/setup-buildx-action@v3 |
| 54 | + |
| 55 | + - name: Log in to GHCR |
| 56 | + uses: docker/login-action@v3 |
| 57 | + with: |
| 58 | + registry: ghcr.io |
| 59 | + username: ${{ github.actor }} |
| 60 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + |
| 62 | + - name: Build & push AMD64 image |
| 63 | + uses: docker/build-push-action@v5 |
| 64 | + with: |
| 65 | + context: ./vendor/moltis |
| 66 | + file: ./vendor/moltis/Dockerfile.stack |
| 67 | + platforms: linux/amd64 |
| 68 | + push: true |
| 69 | + tags: | |
| 70 | + ${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.tag }}-amd64 |
| 71 | + cache-from: type=gha,scope=moltis-amd64 |
| 72 | + cache-to: type=gha,mode=max,scope=moltis-amd64 |
| 73 | + |
| 74 | + build-arm64: |
| 75 | + name: Build ARM64 image |
| 76 | + needs: prepare |
| 77 | + runs-on: ubuntu-latest |
| 78 | + steps: |
| 79 | + - name: Checkout code |
| 80 | + uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - name: Set up QEMU |
| 83 | + uses: docker/setup-qemu-action@v3 |
| 84 | + |
| 85 | + - name: Set up Docker Buildx |
| 86 | + uses: docker/setup-buildx-action@v3 |
| 87 | + |
| 88 | + - name: Log in to GHCR |
| 89 | + uses: docker/login-action@v3 |
| 90 | + with: |
| 91 | + registry: ghcr.io |
| 92 | + username: ${{ github.actor }} |
| 93 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + |
| 95 | + - name: Build & push ARM64 image |
| 96 | + uses: docker/build-push-action@v5 |
| 97 | + with: |
| 98 | + context: ./vendor/moltis |
| 99 | + file: ./vendor/moltis/Dockerfile.stack |
| 100 | + platforms: linux/arm64 |
| 101 | + push: true |
| 102 | + tags: | |
| 103 | + ${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.tag }}-arm64 |
| 104 | + cache-from: type=gha,scope=moltis-arm64 |
| 105 | + cache-to: type=gha,mode=max,scope=moltis-arm64 |
| 106 | + |
| 107 | + create-manifest: |
| 108 | + name: Create multi-arch manifest |
| 109 | + needs: [prepare, build-amd64, build-arm64] |
| 110 | + if: always() && needs.build-amd64.result == 'success' && needs.build-arm64.result == 'success' |
| 111 | + runs-on: ubuntu-latest |
| 112 | + steps: |
| 113 | + - name: Log in to GHCR |
| 114 | + uses: docker/login-action@v3 |
| 115 | + with: |
| 116 | + registry: ghcr.io |
| 117 | + username: ${{ github.actor }} |
| 118 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + |
| 120 | + - name: Create and push multi-arch manifest |
| 121 | + run: | |
| 122 | + TAG="${{ needs.prepare.outputs.tag }}" |
| 123 | + IMAGE="${{ env.IMAGE_NAME }}" |
| 124 | +
|
| 125 | + docker buildx imagetools create \ |
| 126 | + --tag "${IMAGE}:${TAG}" \ |
| 127 | + "${IMAGE}:${TAG}-amd64" \ |
| 128 | + "${IMAGE}:${TAG}-arm64" |
| 129 | +
|
| 130 | + echo "Created manifest: ${IMAGE}:${TAG}" |
0 commit comments