|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '20 14 * * *' |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - "v*" |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: false |
| 13 | + |
| 14 | +permissions: {} |
| 15 | + |
| 16 | +jobs: |
| 17 | + docker-publish: |
| 18 | + outputs: |
| 19 | + digest: ${{ steps.build-and-push.outputs.digest }} |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: write |
| 23 | + packages: write |
| 24 | + id-token: write # sign archives with cosign |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 28 | + with: |
| 29 | + persist-credentials: false |
| 30 | + fetch-depth: 0 |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca # v3.9.0 |
| 33 | + - name: Install Cosign |
| 34 | + uses: sigstore/cosign-installer@d7d6bc7722e3daa8354c50bcb52f4837da5e9b6a # v3.8.1 |
| 35 | + - name: Login to GitHub Container Registry |
| 36 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
| 37 | + with: |
| 38 | + registry: ghcr.io |
| 39 | + username: ${{ github.actor }} |
| 40 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + - name: Extract Docker metadata |
| 42 | + id: meta |
| 43 | + uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1 |
| 44 | + with: |
| 45 | + images: ghcr.io/${{ github.repository }} |
| 46 | + - name: Build and push Docker image |
| 47 | + id: build-and-push |
| 48 | + uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6.14.0 |
| 49 | + with: |
| 50 | + context: . |
| 51 | + tags: ${{ steps.meta.outputs.tags }} |
| 52 | + push: true |
| 53 | + labels: ${{ steps.meta.outputs.labels }} |
| 54 | + cache-from: type=gha |
| 55 | + cache-to: type=gha,mode=max |
| 56 | + - name: Syft SBOM generation |
| 57 | + uses: anchore/sbom-action@f325610c9f50a54015d37c8d16cb3b0e2c8f4de0 # v0.18.0 |
| 58 | + with: |
| 59 | + image: ghcr.io/natrontech/gcp-mysql-backup@${{ steps.build-and-push.outputs.digest }} |
| 60 | + format: cyclonedx-json |
| 61 | + output-file: gcp-mysql-backup-bom.cdx.json |
| 62 | + upload-artifact: false |
| 63 | + upload-release-assets: false |
| 64 | + - name: Cosign sign image |
| 65 | + # env: |
| 66 | + # COSIGN_REPOSITORY: ghcr.io/${{ github.repository_owner }}/signatures |
| 67 | + run: | |
| 68 | + set -e |
| 69 | + cosign sign --yes \ |
| 70 | + -a "repo=${{ github.repository }}" \ |
| 71 | + -a "workflow=${{ github.workflow }}" \ |
| 72 | + -a "ref=${{ github.sha }}" \ |
| 73 | + ghcr.io/natrontech/gcp-mysql-backup@${{ steps.build-and-push.outputs.digest }} |
| 74 | + - name: Cosign sign sbom |
| 75 | + # env: |
| 76 | + # COSIGN_REPOSITORY: ghcr.io/${{ github.repository_owner }}/sbom |
| 77 | + run: | |
| 78 | + cosign attest --yes \ |
| 79 | + --predicate ./gcp-mysql-backup-bom.cdx.json \ |
| 80 | + --type cyclonedx \ |
| 81 | + --oidc-provider github-actions \ |
| 82 | + ghcr.io/natrontech/gcp-mysql-backup@${{ steps.build-and-push.outputs.digest }} |
| 83 | +
|
| 84 | + image-provenance: |
| 85 | + needs: [docker-publish] |
| 86 | + permissions: |
| 87 | + actions: read |
| 88 | + id-token: write |
| 89 | + packages: write |
| 90 | + # MUST be referenced by tag (see https://github.com/slsa-framework/slsa-github-generator/?tab=readme-ov-file#referencing-slsa-builders-and-generators) |
| 91 | + uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] |
| 92 | + with: |
| 93 | + image: ghcr.io/${{ github.repository_owner }}/gcp-mysql-backup |
| 94 | + digest: ${{ needs.docker-publish.outputs.digest }} |
| 95 | + registry-username: ${{ github.actor }} |
| 96 | + provenance-registry-username: ${{ github.actor }} |
| 97 | + #provenance-repository: ghcr.io/${{ github.repository_owner }}/signatures |
| 98 | + secrets: |
| 99 | + registry-password: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + provenance-registry-password: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + |
| 102 | + verification-with-cosign: |
| 103 | + needs: [docker-publish, image-provenance] |
| 104 | + runs-on: ubuntu-latest |
| 105 | + permissions: read-all |
| 106 | + steps: |
| 107 | + - name: Checkout repository |
| 108 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 109 | + with: |
| 110 | + persist-credentials: false |
| 111 | + fetch-depth: 0 |
| 112 | + |
| 113 | + - name: Login |
| 114 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
| 115 | + with: |
| 116 | + registry: ghcr.io |
| 117 | + username: ${{ github.actor }} |
| 118 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + |
| 120 | + - name: Install Cosign |
| 121 | + uses: sigstore/cosign-installer@d7d6bc7722e3daa8354c50bcb52f4837da5e9b6a # v3.8.1 |
| 122 | + |
| 123 | + - name: Verify provenance of image |
| 124 | + env: |
| 125 | + IMAGE: ghcr.io/${{ github.repository_owner }}/gcp-mysql-backup |
| 126 | + DIGEST: ${{ needs.docker-publish.outputs.digest }} |
| 127 | + REPOSITORY: ${{ github.repository_owner }} |
| 128 | + run: | |
| 129 | + cosign verify-attestation \ |
| 130 | + --type slsaprovenance \ |
| 131 | + --certificate-oidc-issuer https://token.actions.githubusercontent.com \ |
| 132 | + --certificate-identity-regexp '^https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@refs/tags/v[0-9]+.[0-9]+.[0-9]+$' \ |
| 133 | + --policy policy.cue \ |
| 134 | + $IMAGE@$DIGEST |
| 135 | +
|
| 136 | + - name: Verify signature of image |
| 137 | + env: |
| 138 | + IMAGE: ghcr.io/${{ github.repository_owner }}/gcp-mysql-backup |
| 139 | + DIGEST: ${{ needs.docker-publish.outputs.digest }} |
| 140 | + REPOSITORY: ${{ github.repository_owner }} |
| 141 | + run: | |
| 142 | + cosign verify \ |
| 143 | + --certificate-oidc-issuer https://token.actions.githubusercontent.com \ |
| 144 | + --certificate-identity-regexp '^https://github.com/natrontech/gcp-mysql-backup/.github/workflows/release.yml@refs/tags/v[0-9]+.[0-9]+.[0-9]+(-rc.[0-9]+)?$' \ |
| 145 | + --certificate-identity-regexp '^https://github.com/natrontech/gcp-mysql-backup/.github/workflows/release.yml@refs/heads/main$' \ |
| 146 | + $IMAGE@$DIGEST |
| 147 | +
|
| 148 | + - name: Verify sbom of image |
| 149 | + env: |
| 150 | + IMAGE: ghcr.io/${{ github.repository_owner }}/gcp-mysql-backup |
| 151 | + DIGEST: ${{ needs.docker-publish.outputs.digest }} |
| 152 | + REPOSITORY: ${{ github.repository_owner }} |
| 153 | + run: | |
| 154 | + cosign verify-attestation \ |
| 155 | + --type cyclonedx \ |
| 156 | + --certificate-oidc-issuer https://token.actions.githubusercontent.com \ |
| 157 | + --certificate-identity-regexp '^https://github.com/natrontech/gcp-mysql-backup/.github/workflows/release.yml@refs/tags/v[0-9]+.[0-9]+.[0-9]+(-rc.[0-9]+)?$' \ |
| 158 | + --certificate-identity-regexp '^https://github.com/natrontech/gcp-mysql-backup/.github/workflows/release.yml@refs/heads/main$' \ |
| 159 | + $IMAGE@$DIGEST |
0 commit comments