|
| 1 | +name: Build (amd64 and arm64) and push to quay registries |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: ["main"] |
| 5 | + tags: ['[0-9]+.[0-9]+.[0-9]+'] |
| 6 | + pull_request: |
| 7 | + branches: ["main"] |
| 8 | + |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +env: |
| 15 | + REGISTRY: localhost |
| 16 | + NAME: patterns-operator |
| 17 | + TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || (github.ref_name == 'main' && 'latest' || github.ref_name) }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + build-container: |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + include: |
| 24 | + - targetarch: amd64 |
| 25 | + runner: ubuntu-latest |
| 26 | + - targetarch: arm64 |
| 27 | + runner: ubuntu-24.04-arm |
| 28 | + |
| 29 | + runs-on: ${{ matrix.runner }} |
| 30 | + permissions: |
| 31 | + contents: read |
| 32 | + steps: |
| 33 | + - name: Checkout repository |
| 34 | + uses: actions/checkout@v5 |
| 35 | + with: |
| 36 | + persist-credentials: false |
| 37 | + |
| 38 | + - name: Build container and save tarball |
| 39 | + env: |
| 40 | + TARGETARCH: ${{ matrix.targetarch }} |
| 41 | + OPERATOR_IMG: ${{ env.NAME }}:${{ env.TAG }} |
| 42 | + KEY: ${{ secrets.API_KEY }} |
| 43 | + run: | |
| 44 | + export APIFILE="internal/controller/apikey.txt" |
| 45 | + trap "rm -f ${APIFILE}" SIGINT EXIT |
| 46 | +
|
| 47 | + if [ -z "${KEY}" ]; then |
| 48 | + echo "Key is empty" |
| 49 | + echo '' > "${APIFILE}" |
| 50 | + else |
| 51 | + echo "Key is set" |
| 52 | + echo "${KEY}" > "${APIFILE}" |
| 53 | + fi |
| 54 | + make "podman-build-${TARGETARCH}" |
| 55 | + buildah push "${OPERATOR_IMG}-${TARGETARCH}" "docker-archive:/tmp/image-${TARGETARCH}.tar:${OPERATOR_IMG}-${TARGETARCH}" |
| 56 | +
|
| 57 | + - name: Upload image artifact |
| 58 | + uses: actions/upload-artifact@v4 |
| 59 | + with: |
| 60 | + name: image-${{ matrix.targetarch }}-${{ github.run_id }} |
| 61 | + path: /tmp/image-${{ matrix.targetarch }}.tar |
| 62 | + retention-days: 1 |
| 63 | + |
| 64 | + pre-push-check: |
| 65 | + needs: [build-container] |
| 66 | + if: github.event_name != 'pull_request' |
| 67 | + runs-on: ubuntu-latest |
| 68 | + steps: |
| 69 | + - name: Checkout repository |
| 70 | + uses: actions/checkout@v5 |
| 71 | + with: |
| 72 | + persist-credentials: false |
| 73 | + |
| 74 | + # We use an env due to https://docs.zizmor.sh/audits/#remediation_18 |
| 75 | + - name: Check that tag version corresponds to metadata version |
| 76 | + run: |- |
| 77 | + VERSION=$(yq -r '.spec.version' bundle/manifests/patterns-operator.clusterserviceversion.yaml) |
| 78 | + if [ "${VERSION}" != "${TAG}" ]; then |
| 79 | + echo "Version in metadata ${VERSION} whereas tag is different: ${TAG}" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + push-multiarch-manifest: |
| 84 | + needs: [pre-push-check] |
| 85 | + if: github.event_name != 'pull_request' |
| 86 | + strategy: |
| 87 | + matrix: |
| 88 | + include: |
| 89 | + - upload_registry: quay.io/validatedpatterns |
| 90 | + legacy: false |
| 91 | + - upload_registry: quay.io/hybridcloudpatterns |
| 92 | + legacy: true |
| 93 | + runs-on: ubuntu-latest |
| 94 | + permissions: |
| 95 | + contents: read |
| 96 | + # This is used to complete the identity challenge |
| 97 | + # with sigstore/fulcio when running outside of PRs. |
| 98 | + id-token: write |
| 99 | + |
| 100 | + steps: |
| 101 | + - name: Checkout repository |
| 102 | + uses: actions/checkout@v5 |
| 103 | + with: |
| 104 | + persist-credentials: false |
| 105 | + |
| 106 | + - name: Download AMD64 image |
| 107 | + uses: actions/download-artifact@v5 |
| 108 | + with: |
| 109 | + name: image-amd64-${{ github.run_id }} |
| 110 | + path: /tmp |
| 111 | + |
| 112 | + - name: Download ARM64 image |
| 113 | + uses: actions/download-artifact@v5 |
| 114 | + with: |
| 115 | + name: image-arm64-${{ github.run_id }} |
| 116 | + path: /tmp |
| 117 | + |
| 118 | + - name: Load tarballs into local containers-storage |
| 119 | + run: | |
| 120 | + buildah pull docker-archive:/tmp/image-amd64.tar |
| 121 | + buildah pull docker-archive:/tmp/image-arm64.tar |
| 122 | +
|
| 123 | + - name: Log into Quay |
| 124 | + env: |
| 125 | + USERNAME: ${{ matrix.legacy && secrets.LEGACY_QUAY_USERNAME || secrets.QUAY_USERNAME }} |
| 126 | + PASSWORD: ${{ matrix.legacy && secrets.LEGACY_QUAY_PASSWORD || secrets.QUAY_PASSWORD }} |
| 127 | + run: | |
| 128 | + buildah login -u "${USERNAME}" -p "${PASSWORD}" quay.io |
| 129 | +
|
| 130 | + # The compressed manifest in Quay has a different digest than the local so we |
| 131 | + # need to use skopeo to retrieve the correct digest for signing |
| 132 | + - name: Create manifest and push to Quay |
| 133 | + id: manifest-push |
| 134 | + env: |
| 135 | + UPLOADREGISTRY: ${{ matrix.upload_registry }} |
| 136 | + OPERATOR_IMG: ${{ env.NAME }}:${{ env.TAG }} |
| 137 | + run: | |
| 138 | + make buildah-manifest |
| 139 | + buildah manifest add --arch=amd64 "${REGISTRY}/${OPERATOR_IMG}" "${REGISTRY}/${OPERATOR_IMG}-amd64" |
| 140 | + buildah manifest add --arch=arm64 "${REGISTRY}/${OPERATOR_IMG}" "${REGISTRY}/${OPERATOR_IMG}-arm64" |
| 141 | + make buildah-push |
| 142 | + DIGEST=$(skopeo inspect --format "{{.Digest}}" "docker://${UPLOADREGISTRY}/${OPERATOR_IMG}") |
| 143 | + echo "digest=$DIGEST" >> "$GITHUB_OUTPUT" |
| 144 | +
|
| 145 | + - name: Install cosign |
| 146 | + uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0 |
| 147 | + with: |
| 148 | + cosign-release: "v2.2.4" |
| 149 | + |
| 150 | + # Cosign expects the docker config.json for registry authentication so we must |
| 151 | + # copy it from buildah |
| 152 | + - name: Sign the published Docker image |
| 153 | + env: |
| 154 | + DIGEST: ${{ steps.manifest-push.outputs.digest }} |
| 155 | + UPLOADREGISTRY: ${{ matrix.upload_registry }} |
| 156 | + OPERATOR_IMG: ${{ env.NAME }}:${{ env.TAG }} |
| 157 | + run: | |
| 158 | + cat "${XDG_RUNTIME_DIR}/containers/auth.json" > ~/.docker/config.json |
| 159 | + cosign sign --yes "${UPLOADREGISTRY}/${OPERATOR_IMG}@${DIGEST}" |
0 commit comments