Skip to content

Commit 5653896

Browse files
authored
Merge pull request #1437 from Anselmoo/feature/docker-sign
feat: 👷 Update Docker dependencies for Docker actions
2 parents 48b394a + ee91807 commit 5653896

File tree

1 file changed

+48
-52
lines changed

1 file changed

+48
-52
lines changed

.github/workflows/docker-cd.yml

+48-52
Original file line numberDiff line numberDiff line change
@@ -22,75 +22,71 @@ env:
2222
IMAGE_NAME: ${{ github.repository }}
2323

2424
jobs:
25-
build:
25+
build-image:
2626
runs-on: ubuntu-latest
27+
2728
permissions:
2829
contents: read
2930
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
3332

33+
name: build-image
3434
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+
- uses: actions/[email protected]
4336
with:
44-
cosign-release: "v2.1.1"
37+
fetch-depth: 1
38+
39+
- name: Install Cosign
40+
uses: sigstore/[email protected]
41+
42+
- name: Set up QEMU
43+
uses: docker/[email protected]
4544

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+
uses: docker/[email protected]
4947

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-
uses: docker/[email protected]
48+
- name: Login to GitHub Container Registry
49+
uses: docker/[email protected]
5550
with:
56-
registry: ${{ env.REGISTRY }}
51+
registry: ghcr.io
5752
username: ${{ github.actor }}
5853
password: ${{ secrets.GITHUB_TOKEN }}
5954

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+
uses: docker/[email protected]
6557
with:
66-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
58+
images: ghcr.io/sigstore/sample-honk
59+
tags: type=sha,format=long
6760

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+
uses: docker/[email protected]
7163
id: build-and-push
72-
uses: docker/build-push-action@5176d81f87c23d6fc96624dfdbcd9f3830bbe445
7364
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 }}
8282

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
9084
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 }}
9385
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

Comments
 (0)