|
| 1 | +name: Publish nilchaind to GHCR |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + packages: write # Required to push to GHCR |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-and-push-arch: |
| 19 | + runs-on: ${{ matrix.runner }} |
| 20 | + strategy: |
| 21 | + fail-fast: false |
| 22 | + matrix: |
| 23 | + include: |
| 24 | + - arch: amd64 |
| 25 | + platform: linux/amd64 |
| 26 | + runner: ubuntu-latest |
| 27 | + - arch: arm64 |
| 28 | + platform: linux/arm64 |
| 29 | + runner: ubuntu-24.04-arm |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: 0 |
| 35 | + |
| 36 | + - name: Log in to GitHub Container Registry |
| 37 | + uses: docker/login-action@v3 |
| 38 | + with: |
| 39 | + registry: ghcr.io |
| 40 | + username: ${{ github.actor }} |
| 41 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + |
| 43 | + - name: Set up Docker Buildx |
| 44 | + uses: docker/setup-buildx-action@v3 |
| 45 | + |
| 46 | + - name: Extract metadata for version |
| 47 | + id: meta_tag |
| 48 | + uses: docker/metadata-action@v5 |
| 49 | + with: |
| 50 | + images: ghcr.io/nillionnetwork/nilchaind |
| 51 | + tags: | |
| 52 | + type=ref,event=branch |
| 53 | + type=ref,event=tag |
| 54 | + type=sha,prefix= |
| 55 | + flavor: | |
| 56 | + latest=false |
| 57 | +
|
| 58 | + - name: Build and push arch-specific image |
| 59 | + uses: docker/build-push-action@v6 |
| 60 | + with: |
| 61 | + context: . |
| 62 | + platforms: ${{ matrix.platform }} |
| 63 | + push: true |
| 64 | + tags: ghcr.io/nillionnetwork/nilchaind:${{ github.sha }}-${{ matrix.arch }} |
| 65 | + build-args: | |
| 66 | + VERSION=${{ steps.meta_tag.outputs.version }} |
| 67 | + cache-from: type=gha |
| 68 | + cache-to: type=gha,mode=max |
| 69 | + provenance: false |
| 70 | + |
| 71 | + create-and-push-manifest: |
| 72 | + runs-on: ubuntu-latest |
| 73 | + needs: build-and-push-arch |
| 74 | + steps: |
| 75 | + - name: Log in to GitHub Container Registry |
| 76 | + uses: docker/login-action@v3 |
| 77 | + with: |
| 78 | + registry: ghcr.io |
| 79 | + username: ${{ github.actor }} |
| 80 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + |
| 82 | + - name: Extract final tags |
| 83 | + id: meta |
| 84 | + uses: docker/metadata-action@v5 |
| 85 | + with: |
| 86 | + images: ghcr.io/nillionnetwork/nilchaind |
| 87 | + tags: | |
| 88 | + type=ref,event=branch |
| 89 | + type=ref,event=tag |
| 90 | + flavor: | |
| 91 | + latest=false |
| 92 | +
|
| 93 | + - name: Create and push multi-arch manifest |
| 94 | + run: | |
| 95 | + echo "${{ steps.meta.outputs.tags }}" > tags.txt |
| 96 | + |
| 97 | + while IFS= read -r tag; do |
| 98 | + if [ -n "$tag" ]; then |
| 99 | + echo "Creating and pushing manifest for tag: $tag" |
| 100 | + |
| 101 | + docker manifest create "$tag" \ |
| 102 | + ghcr.io/nillionnetwork/nilchaind:${{ github.sha }}-amd64 \ |
| 103 | + ghcr.io/nillionnetwork/nilchaind:${{ github.sha }}-arm64 |
| 104 | + |
| 105 | + docker manifest push "$tag" |
| 106 | + fi |
| 107 | + done < tags.txt |
0 commit comments