|
| 1 | +name: Build (amd64 and arm64) and push to quay registries |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + tags: ["v*.*.*"] |
| 7 | + pull_request: |
| 8 | + branches: ["main"] |
| 9 | + |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +env: |
| 16 | + REGISTRY: localhost |
| 17 | + NAME: patternizer |
| 18 | + TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || (github.ref_name == 'main' && 'latest' || github.ref_name) }} |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-container: |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - targetarch: amd64 |
| 26 | + runner: ubuntu-latest |
| 27 | + - targetarch: arm64 |
| 28 | + runner: ubuntu-24.04-arm |
| 29 | + |
| 30 | + runs-on: ${{ matrix.runner }} |
| 31 | + permissions: |
| 32 | + contents: read |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout repository |
| 36 | + uses: actions/checkout@v5 |
| 37 | + with: |
| 38 | + persist-credentials: false |
| 39 | + |
| 40 | + - name: Build container and save tarball |
| 41 | + env: |
| 42 | + CONTAINER: ${{ env.NAME }}:${{ env.TAG }} |
| 43 | + TARGETARCH: ${{ matrix.targetarch }} |
| 44 | + run: | |
| 45 | + make "${TARGETARCH}" |
| 46 | + buildah push "${CONTAINER}-${TARGETARCH}" "docker-archive:/tmp/image-${TARGETARCH}.tar:${CONTAINER}-${TARGETARCH}" |
| 47 | +
|
| 48 | + - name: Upload image artifact |
| 49 | + uses: actions/upload-artifact@v4 |
| 50 | + with: |
| 51 | + name: image-${{ matrix.targetarch }}-${{ github.run_id }} |
| 52 | + path: /tmp/image-${{ matrix.targetarch }}.tar |
| 53 | + retention-days: 1 |
| 54 | + |
| 55 | + push-multiarch-manifest: |
| 56 | + needs: [build-container] |
| 57 | + if: github.event_name != 'pull_request' |
| 58 | + strategy: |
| 59 | + matrix: |
| 60 | + include: |
| 61 | + - upload_registry: quay.io/validatedpatterns |
| 62 | + legacy: false |
| 63 | + - upload_registry: quay.io/hybridcloudpatterns |
| 64 | + legacy: true |
| 65 | + |
| 66 | + runs-on: ubuntu-latest |
| 67 | + permissions: |
| 68 | + contents: read |
| 69 | + # This is used to complete the identity challenge |
| 70 | + # with sigstore/fulcio when running outside of PRs. |
| 71 | + id-token: write |
| 72 | + |
| 73 | + steps: |
| 74 | + - name: Checkout repository |
| 75 | + uses: actions/checkout@v5 |
| 76 | + with: |
| 77 | + persist-credentials: false |
| 78 | + |
| 79 | + - name: Download AMD64 image |
| 80 | + uses: actions/download-artifact@v5 |
| 81 | + with: |
| 82 | + name: image-amd64-${{ github.run_id }} |
| 83 | + path: /tmp |
| 84 | + |
| 85 | + - name: Download ARM64 image |
| 86 | + uses: actions/download-artifact@v5 |
| 87 | + with: |
| 88 | + name: image-arm64-${{ github.run_id }} |
| 89 | + path: /tmp |
| 90 | + |
| 91 | + - name: Load tarballs into local containers-storage |
| 92 | + run: | |
| 93 | + buildah pull docker-archive:/tmp/image-amd64.tar |
| 94 | + buildah pull docker-archive:/tmp/image-arm64.tar |
| 95 | +
|
| 96 | + - name: Log into Quay |
| 97 | + env: |
| 98 | + USERNAME: ${{ matrix.legacy && secrets.LEGACY_QUAY_USERNAME || secrets.QUAY_USERNAME }} |
| 99 | + PASSWORD: ${{ matrix.legacy && secrets.LEGACY_QUAY_PASSWORD || secrets.QUAY_PASSWORD }} |
| 100 | + run: | |
| 101 | + buildah login -u "${USERNAME}" -p "${PASSWORD}" quay.io |
| 102 | +
|
| 103 | + # The compressed manifest in Quay has a different digest than the local so we |
| 104 | + # need to use skopeo to retrieve the correct digest for signing |
| 105 | + - name: Create manifest and push to Quay |
| 106 | + id: manifest-push |
| 107 | + env: |
| 108 | + UPLOADREGISTRY: ${{ matrix.upload_registry }} |
| 109 | + CONTAINER: ${{ env.NAME }}:${{ env.TAG }} |
| 110 | + run: | |
| 111 | + make manifest |
| 112 | + buildah manifest add --arch=amd64 "${REGISTRY}/${CONTAINER}" "${REGISTRY}/${CONTAINER}-amd64" |
| 113 | + buildah manifest add --arch=arm64 "${REGISTRY}/${CONTAINER}" "${REGISTRY}/${CONTAINER}-arm64" |
| 114 | + make upload |
| 115 | + DIGEST=$(skopeo inspect --format "{{.Digest}}" "docker://${UPLOADREGISTRY}/${CONTAINER}") |
| 116 | + echo "digest=$DIGEST" >> "$GITHUB_OUTPUT" |
| 117 | +
|
| 118 | + - name: Install cosign |
| 119 | + uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0 |
| 120 | + with: |
| 121 | + cosign-release: "v2.2.4" |
| 122 | + |
| 123 | + # Cosign expects the docker config.json for registry authentication so we must |
| 124 | + # copy it from buildah |
| 125 | + - name: Sign the published Docker image |
| 126 | + env: |
| 127 | + CONTAINER: ${{ env.NAME }}:${{ env.TAG }} |
| 128 | + DIGEST: ${{ steps.manifest-push.outputs.digest }} |
| 129 | + UPLOADREGISTRY: ${{ matrix.upload_registry }} |
| 130 | + run: | |
| 131 | + cat "${XDG_RUNTIME_DIR}/containers/auth.json" > ~/.docker/config.json |
| 132 | + cosign sign --yes "${UPLOADREGISTRY}/${CONTAINER}@${DIGEST}" |
0 commit comments