|
| 1 | +name: Container |
| 2 | + |
| 3 | +# Build the ingot daemon image and publish it to GHCR on merges to main. |
| 4 | +# Mirrors sprue's dev/prod pattern so smelt can pull a consistent |
| 5 | +# ghcr.io/fil-forge/ingot:main (prod) and :main-dev (debug + dlv) pair. |
| 6 | +# ingot has no releaser, so this is the PR build-check + publish-on-main |
| 7 | +# half of sprue's workflow. |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: [main] |
| 12 | + pull_request: |
| 13 | + branches: [main] |
| 14 | + |
| 15 | +# Cancel in-progress runs on new pushes to the same ref. |
| 16 | +concurrency: |
| 17 | + group: container-${{ github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +env: |
| 21 | + REGISTRY: ghcr.io |
| 22 | + IMAGE_NAME: ${{ github.repository }} |
| 23 | + |
| 24 | +jobs: |
| 25 | + # Publish both prod and dev images on push to main. |
| 26 | + # prod -> :main, :sha-<short> |
| 27 | + # dev -> :main-dev, :sha-<short>-dev |
| 28 | + publish-main: |
| 29 | + name: Publish ${{ matrix.target }} |
| 30 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + packages: write |
| 35 | + strategy: |
| 36 | + matrix: |
| 37 | + include: |
| 38 | + - target: prod |
| 39 | + suffix: "" |
| 40 | + - target: dev |
| 41 | + suffix: "-dev" |
| 42 | + steps: |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Set up QEMU |
| 47 | + uses: docker/setup-qemu-action@v3 |
| 48 | + |
| 49 | + - name: Set up Docker Buildx |
| 50 | + uses: docker/setup-buildx-action@v3 |
| 51 | + |
| 52 | + - name: Log in to GHCR |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + registry: ${{ env.REGISTRY }} |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Extract metadata |
| 60 | + id: meta |
| 61 | + uses: docker/metadata-action@v5 |
| 62 | + with: |
| 63 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 64 | + tags: | |
| 65 | + type=raw,value=main${{ matrix.suffix }} |
| 66 | + type=sha,suffix=${{ matrix.suffix }} |
| 67 | +
|
| 68 | + - name: Build and push |
| 69 | + uses: docker/build-push-action@v6 |
| 70 | + with: |
| 71 | + context: . |
| 72 | + target: ${{ matrix.target }} |
| 73 | + platforms: linux/amd64,linux/arm64 |
| 74 | + push: true |
| 75 | + tags: ${{ steps.meta.outputs.tags }} |
| 76 | + labels: ${{ steps.meta.outputs.labels }} |
| 77 | + cache-from: type=gha,scope=${{ matrix.target }} |
| 78 | + cache-to: type=gha,scope=${{ matrix.target }},mode=max |
| 79 | + |
| 80 | + # PR build check (no push) - both targets, single platform for speed. |
| 81 | + build-check: |
| 82 | + name: Build Check (${{ matrix.target }}) |
| 83 | + if: github.event_name == 'pull_request' |
| 84 | + runs-on: ubuntu-latest |
| 85 | + permissions: |
| 86 | + contents: read |
| 87 | + strategy: |
| 88 | + matrix: |
| 89 | + target: [dev, prod] |
| 90 | + steps: |
| 91 | + - name: Checkout |
| 92 | + uses: actions/checkout@v4 |
| 93 | + |
| 94 | + - name: Set up Docker Buildx |
| 95 | + uses: docker/setup-buildx-action@v3 |
| 96 | + |
| 97 | + - name: Build ${{ matrix.target }} |
| 98 | + uses: docker/build-push-action@v6 |
| 99 | + with: |
| 100 | + context: . |
| 101 | + target: ${{ matrix.target }} |
| 102 | + platforms: linux/amd64 |
| 103 | + push: false |
| 104 | + cache-from: type=gha,scope=${{ matrix.target }} |
0 commit comments