|
1 |
| -name: Create and publish a Docker image |
| 1 | +name: Create and publish a multi-architecture Docker image |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | push:
|
5 | 5 | tags: ['v[0-9]+.[0-9]+.[0-9]+']
|
6 | 6 |
|
7 | 7 | env:
|
8 | 8 | REGISTRY: ghcr.io
|
9 |
| - IMAGE_NAME: ${{ github.repository }} |
| 9 | + IMAGE_NAME: ghcr.io/${{ github.repository }} |
10 | 10 |
|
11 | 11 | jobs:
|
12 |
| - build-and-push-image: |
13 |
| - runs-on: ubuntu-latest |
| 12 | + build-image: |
| 13 | + strategy: |
| 14 | + fail-fast: false |
| 15 | + matrix: |
| 16 | + runner: [ubuntu-latest, buildjet-4vcpu-ubuntu-2204-arm] |
| 17 | + runs-on: ${{ matrix.runner }} |
14 | 18 | permissions:
|
15 | 19 | contents: read
|
16 | 20 | packages: write
|
17 |
| - |
18 | 21 | steps:
|
19 | 22 | - name: Checkout repository
|
20 |
| - uses: actions/checkout@v3 |
21 |
| - |
22 |
| - - name: Log in to the Container registry |
23 |
| - |
| 23 | + uses: actions/checkout@v4 |
| 24 | + - name: Docker meta |
| 25 | + id: meta |
| 26 | + uses: docker/metadata-action@v5 |
| 27 | + with: |
| 28 | + images: ${{ env.IMAGE_NAME }} |
| 29 | + - name: Set up Docker Buildx |
| 30 | + uses: docker/setup-buildx-action@v3 |
| 31 | + - name: Login to the Container Registry |
| 32 | + uses: docker/login-action@v3 |
24 | 33 | with:
|
25 | 34 | registry: ${{ env.REGISTRY }}
|
26 | 35 | username: ${{ github.actor }}
|
27 | 36 | password: ${{ secrets.GITHUB_TOKEN }}
|
28 |
| - |
29 |
| - - name: Extract metadata (tags, labels) for Docker |
30 |
| - id: meta |
31 |
| - |
| 37 | + - name: Build and export the image to Docker |
| 38 | + uses: docker/build-push-action@v5 |
32 | 39 | with:
|
33 |
| - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
34 |
| - tags: | |
35 |
| - type=semver,pattern=v{{version}} |
36 |
| -
|
37 |
| - - name: Build and push Docker image |
38 |
| - |
| 40 | + context: . |
| 41 | + load: true |
| 42 | + tags: ${{ env.IMAGE_NAME }}:test |
| 43 | + - name: Test the image |
| 44 | + run: | |
| 45 | + docker run --rm -i ${{ env.IMAGE_NAME }}:test < examples/nfldb.er >| nfldb.pdf |
| 46 | + - name: Push the image by digest |
| 47 | + id: build |
| 48 | + uses: docker/build-push-action@v5 |
39 | 49 | with:
|
40 | 50 | context: .
|
41 |
| - push: true |
42 |
| - tags: | |
43 |
| - ${{ steps.meta.outputs.tags }} |
44 | 51 | labels: ${{ steps.meta.outputs.labels }}
|
| 52 | + outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true |
| 53 | + - name: Export the digest |
| 54 | + run: | |
| 55 | + mkdir -p /tmp/digests |
| 56 | + digest="${{ steps.build.outputs.digest }}" |
| 57 | + touch "/tmp/digests/${digest#sha256:}" |
| 58 | + - name: Upload the digest |
| 59 | + uses: actions/upload-artifact@v3 |
| 60 | + with: |
| 61 | + name: digests |
| 62 | + path: /tmp/digests/* |
| 63 | + if-no-files-found: error |
| 64 | + retention-days: 1 |
| 65 | + - name: Upload artifacts |
| 66 | + uses: actions/upload-artifact@v3 |
| 67 | + with: |
| 68 | + name: example-diagram-nfldb |
| 69 | + path: nfldb.pdf |
| 70 | + |
| 71 | + merge-image: |
| 72 | + runs-on: ubuntu-latest |
| 73 | + needs: |
| 74 | + - build-image |
| 75 | + steps: |
| 76 | + - name: Download digests |
| 77 | + uses: actions/download-artifact@v3 |
| 78 | + with: |
| 79 | + name: digests |
| 80 | + path: /tmp/digests |
| 81 | + - name: Set up Docker Buildx |
| 82 | + uses: docker/setup-buildx-action@v3 |
| 83 | + - name: Docker meta |
| 84 | + id: meta |
| 85 | + uses: docker/metadata-action@v5 |
| 86 | + with: |
| 87 | + images: ${{ env.IMAGE_NAME }} |
| 88 | + - name: Login to the Container Registry |
| 89 | + uses: docker/login-action@v3 |
| 90 | + with: |
| 91 | + registry: ${{ env.REGISTRY }} |
| 92 | + username: ${{ github.actor }} |
| 93 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + - name: Create manifest list and push |
| 95 | + working-directory: /tmp/digests |
| 96 | + run: | |
| 97 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 98 | + $(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *) |
| 99 | + - name: Inspect image |
| 100 | + run: | |
| 101 | + docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} |
0 commit comments