|
22 | 22 | IMAGE_NAME: ${{ github.repository }}
|
23 | 23 |
|
24 | 24 | jobs:
|
25 |
| - build: |
| 25 | + build-image: |
26 | 26 | runs-on: ubuntu-latest
|
| 27 | + |
27 | 28 | permissions:
|
28 | 29 | contents: read
|
29 | 30 | packages: write
|
30 |
| - # This is used to complete the identity challenge |
31 |
| - # with sigstore/fulcio when running outside of PRs. |
32 |
| - id-token: write |
| 31 | + id-token: write # needed for signing the images with GitHub OIDC Token |
33 | 32 |
|
| 33 | + name: build-image |
34 | 34 | steps:
|
35 |
| - - name: Checkout repository |
36 |
| - uses: actions/checkout@v4 |
37 |
| - |
38 |
| - # Install the cosign tool except on PR |
39 |
| - # https://github.com/sigstore/cosign-installer |
40 |
| - - name: Install cosign |
41 |
| - if: github.event_name != 'pull_request' |
42 |
| - uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 |
| 35 | + |
43 | 36 | with:
|
44 |
| - cosign-release: "v2.1.1" |
| 37 | + fetch-depth: 1 |
| 38 | + |
| 39 | + - name: Install Cosign |
| 40 | + |
| 41 | + |
| 42 | + - name: Set up QEMU |
| 43 | + |
45 | 44 |
|
46 |
| - # Workaround: https://github.com/docker/build-push-action/issues/461 |
47 |
| - - name: Setup Docker buildx |
48 |
| - uses: docker/setup-buildx-action@aa33708b10e362ff993539393ff100fa93ed6a27 |
| 45 | + - name: Set up Docker Buildx |
| 46 | + |
49 | 47 |
|
50 |
| - # Login against a Docker registry except on PR |
51 |
| - # https://github.com/docker/login-action |
52 |
| - - name: Log into registry ${{ env.REGISTRY }} |
53 |
| - if: github.event_name != 'pull_request' |
54 |
| - |
| 48 | + - name: Login to GitHub Container Registry |
| 49 | + |
55 | 50 | with:
|
56 |
| - registry: ${{ env.REGISTRY }} |
| 51 | + registry: ghcr.io |
57 | 52 | username: ${{ github.actor }}
|
58 | 53 | password: ${{ secrets.GITHUB_TOKEN }}
|
59 | 54 |
|
60 |
| - # Extract metadata (tags, labels) for Docker |
61 |
| - # https://github.com/docker/metadata-action |
62 |
| - - name: Extract Docker metadata |
63 |
| - id: meta |
64 |
| - uses: docker/metadata-action@60a0d343a0d8a18aedee9d34e62251f752153bdb |
| 55 | + - id: docker_meta |
| 56 | + |
65 | 57 | with:
|
66 |
| - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 58 | + images: ghcr.io/sigstore/sample-honk |
| 59 | + tags: type=sha,format=long |
67 | 60 |
|
68 |
| - # Build and push Docker image with Buildx (don't push on PR) |
69 |
| - # https://github.com/docker/build-push-action |
70 |
| - - name: Build and push Docker image |
| 61 | + - name: Build and Push container images |
| 62 | + |
71 | 63 | id: build-and-push
|
72 |
| - uses: docker/build-push-action@5176d81f87c23d6fc96624dfdbcd9f3830bbe445 |
73 | 64 | with:
|
74 |
| - context: . |
75 |
| - push: ${{ github.event_name != 'pull_request' }} |
76 |
| - tags: ${{ steps.meta.outputs.tags }} |
77 |
| - labels: ${{ steps.meta.outputs.labels }} |
78 |
| - cache-from: type=gha |
79 |
| - cache-to: type=gha,mode=max |
80 |
| - platforms: linux/amd64,linux/arm64 |
81 |
| - outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }} |
| 65 | + platforms: linux/amd64,linux/arm/v7,linux/arm64 |
| 66 | + push: true |
| 67 | + tags: ${{ steps.docker_meta.outputs.tags }} |
| 68 | + |
| 69 | + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable |
| 70 | + - name: Sign image with a key |
| 71 | + run: | |
| 72 | + images="" |
| 73 | + for tag in ${TAGS}; do |
| 74 | + images+="${tag}@${DIGEST} " |
| 75 | + done |
| 76 | + cosign sign --yes --key env://COSIGN_PRIVATE_KEY ${images} |
| 77 | + env: |
| 78 | + TAGS: ${{ steps.docker_meta.outputs.tags }} |
| 79 | + COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} |
| 80 | + COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} |
| 81 | + DIGEST: ${{ steps.build-and-push.outputs.digest }} |
82 | 82 |
|
83 |
| - # Sign the resulting Docker image digest except on PRs. |
84 |
| - # This will only write to the public Rekor transparency log when the Docker |
85 |
| - # repository is public to avoid leaking data. If you would like to publish |
86 |
| - # transparency data even for private images, pass --force to cosign below. |
87 |
| - # https://github.com/sigstore/cosign |
88 |
| - - name: Sign the published Docker image |
89 |
| - if: ${{ github.event_name != 'pull_request' }} |
| 83 | + - name: Sign the images with GitHub OIDC Token |
90 | 84 | env:
|
91 |
| - # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable |
92 |
| - TAGS: ${{ steps.meta.outputs.tags }} |
93 | 85 | DIGEST: ${{ steps.build-and-push.outputs.digest }}
|
94 |
| - # This step uses the identity token to provision an ephemeral certificate |
95 |
| - # against the sigstore community Fulcio instance. |
96 |
| - run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |
| 86 | + TAGS: ${{ steps.docker_meta.outputs.tags }} |
| 87 | + run: | |
| 88 | + images="" |
| 89 | + for tag in ${TAGS}; do |
| 90 | + images+="${tag}@${DIGEST} " |
| 91 | + done |
| 92 | + cosign sign --yes ${images} |
0 commit comments