|
4 | 4 | pull_request: |
5 | 5 | branches: ["main", "release/**"] |
6 | 6 | paths: |
7 | | - ["Dockerfile", "bin/**", "config/**", ".github/workflows/ci-docker.yml"] |
| 7 | + ["Dockerfile", "bin/**", "config/**", ".github/workflows/**"] |
| 8 | + push: |
| 9 | + branches: ["main"] |
| 10 | + paths: |
| 11 | + ["Dockerfile", "bin/**", "config/**", ".github/workflows/**"] |
| 12 | + tags: |
| 13 | + - "v*.*.*" |
8 | 14 |
|
9 | 15 | env: |
10 | | - REGISTRY: ghcr.io |
11 | | - IMAGE_NAME: blinklabs/cardano-node |
| 16 | + GHCR_IMAGE_NAME: ${{ vars.GHCR_IMAGE_NAME || format('ghcr.io/{0}/cardano-node', github.repository_owner) }} |
12 | 17 |
|
13 | 18 | permissions: |
14 | 19 | contents: read |
| 20 | + packages: write # Required for pushing to GHCR |
15 | 21 |
|
16 | 22 | jobs: |
17 | 23 | build: |
18 | 24 | strategy: |
19 | 25 | matrix: |
20 | | - arch: [amd64, arm64] |
21 | | - runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }} |
| 26 | + include: |
| 27 | + - platform: linux/amd64 |
| 28 | + runner: ubuntu-latest |
| 29 | + - platform: linux/arm64 |
| 30 | + runner: ubuntu-24.04-arm |
| 31 | + runs-on: ${{ matrix.runner }} |
22 | 32 | steps: |
23 | 33 | - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 https://github.com/actions/checkout/releases/tag/v6.0.0 |
24 | 34 |
|
25 | 35 | - uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 https://github.com/docker/setup-buildx-action/releases/tag/v3.11.1 |
26 | 36 |
|
| 37 | + - name: Login to GHCR |
| 38 | + if: github.event_name == 'push' |
| 39 | + uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 https://github.com/docker/login-action/releases/tag/v3.6.0 |
| 40 | + with: |
| 41 | + registry: ghcr.io |
| 42 | + username: ${{ github.actor }} |
| 43 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + |
| 45 | + - name: Prepare |
| 46 | + run: | |
| 47 | + platform=${{ matrix.platform }} |
| 48 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 49 | + echo "ARCH=${platform##*/}" >> $GITHUB_ENV |
| 50 | +
|
27 | 51 | - id: meta |
28 | | - uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0 https://github.com/docker/metadata-action/releases/tag/v5.9.0 |
| 52 | + uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0 https://github.com/docker/metadata-action/releases/tag/v5.10.0 |
29 | 53 | with: |
30 | | - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
31 | | - flavor: | |
32 | | - latest=false |
33 | | - suffix=-${{ matrix.arch == 'arm64' && 'arm64v8' || 'amd64' }} |
| 54 | + images: ${{ env.GHCR_IMAGE_NAME }} |
34 | 55 |
|
35 | | - - name: Build Docker image |
| 56 | + - name: Build and push by digest |
| 57 | + id: build |
36 | 58 | uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 https://github.com/docker/build-push-action/releases/tag/v6.18.0 |
37 | 59 | with: |
38 | 60 | context: . |
39 | | - push: false |
40 | | - tags: ${{ steps.meta.outputs.tags }} |
| 61 | + platforms: ${{ matrix.platform }} |
41 | 62 | labels: ${{ steps.meta.outputs.labels }} |
42 | | - cache-from: type=gha,scope=buildkit-${{ matrix.arch }} |
43 | | - cache-to: type=gha,mode=max,scope=buildkit-${{ matrix.arch }} |
| 63 | + tags: ${{ env.GHCR_IMAGE_NAME }} |
| 64 | + cache-from: type=gha,scope=buildkit-${{ env.ARCH }} |
| 65 | + cache-to: type=gha,mode=max,scope=buildkit-${{ env.ARCH }} |
| 66 | + outputs: ${{ github.event_name == 'push' && 'type=image,name-canonical=true,push-by-digest=true,push=true' || 'type=cacheonly' }} |
| 67 | + |
| 68 | + - name: Export digest |
| 69 | + if: github.event_name == 'push' |
| 70 | + run: | |
| 71 | + mkdir -p ${{ runner.temp }}/digests |
| 72 | + digest="${{ steps.build.outputs.digest }}" |
| 73 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 74 | + echo "Digest: $digest" |
| 75 | + echo "Image pushed to GHCR with tags:" |
| 76 | + echo "${{ steps.meta.outputs.tags }}" |
| 77 | +
|
| 78 | + - name: Upload digest |
| 79 | + if: github.event_name == 'push' |
| 80 | + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 https://github.com/actions/upload-artifact/releases/tag/v5.0.0 |
| 81 | + with: |
| 82 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 83 | + path: ${{ runner.temp }}/digests/* |
| 84 | + if-no-files-found: error |
| 85 | + retention-days: 1 |
| 86 | + |
| 87 | + ref-info: |
| 88 | + runs-on: ubuntu-latest |
| 89 | + if: github.event_name == 'push' |
| 90 | + steps: |
| 91 | + - name: Export ref info |
| 92 | + run: | |
| 93 | + mkdir -p ${{ runner.temp }}/ref-info |
| 94 | + echo "${{ github.ref }}" > ${{ runner.temp }}/ref-info/ref.txt |
| 95 | + echo "${{ github.ref_name }}" > ${{ runner.temp }}/ref-info/ref_name.txt |
| 96 | + echo "${{ github.ref_type }}" > ${{ runner.temp }}/ref-info/ref_type.txt |
| 97 | + echo "Exported ref info:" |
| 98 | + echo " ref: ${{ github.ref }}" |
| 99 | + echo " ref_name: ${{ github.ref_name }}" |
| 100 | + echo " ref_type: ${{ github.ref_type }}" |
| 101 | +
|
| 102 | + - name: Upload ref info |
| 103 | + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 https://github.com/actions/upload-artifact/releases/tag/v5.0.0 |
| 104 | + |
| 105 | + with: |
| 106 | + name: ref-info |
| 107 | + path: ${{ runner.temp }}/ref-info/* |
| 108 | + if-no-files-found: error |
| 109 | + retention-days: 1 |
0 commit comments