Skip to content

Commit 7d26ab8

Browse files
authored
Merge pull request #1 from zcash/docker_sig_attest
Build, Attest (SBOM/Provenance) & Sign to Docker Hub
2 parents 2c57105 + f6a9a3e commit 7d26ab8

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed
Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
name: Build and Push Docker Image to Docker Hub
1+
name: Build, Attest (SBOM/Provenance) & Sign to Docker Hub
22

33
on:
44
workflow_call:
55
inputs:
66
image_name:
7-
description: "Name of the Docker image to build and push"
7+
description: "Docker image name (e.g. user/repo)"
88
required: true
99
type: string
1010
image_tags:
11-
description: "Comma-separated list of tags for the Docker image"
11+
description: "Comma-separated list of tags"
1212
required: true
1313
type: string
1414
dockerfile:
1515
description: "Path to the Dockerfile"
1616
required: true
1717
type: string
1818
context:
19-
description: "Build context for the Docker image"
19+
description: "Build context"
2020
required: true
2121
type: string
2222
build-args:
@@ -26,51 +26,79 @@ on:
2626
secrets:
2727
dockerhub_registry:
2828
required: true
29-
description: "Docker Hub registry URL (e.g., docker.io)"
29+
description: "Docker Hub registry (e.g. docker.io)"
3030
dockerhub_username:
3131
required: true
3232
description: "Docker Hub username"
3333
dockerhub_password:
3434
required: true
3535
description: "Docker Hub password"
3636

37+
permissions:
38+
# Needed for keyless signing with Cosign and checkout
39+
id-token: write
40+
contents: read
41+
3742
jobs:
3843
build-and-push:
3944
runs-on: ubuntu-latest
45+
env:
46+
REGISTRY: ${{ secrets.dockerhub_registry }}
47+
IMAGE_NAME: ${{ inputs.image_name }}
4048
steps:
41-
- name: Set Docker Image Tags
49+
- name: Compute Docker image tags
4250
id: set-tags
4351
run: |
52+
set -euo pipefail
4453
TAGS="${{ inputs.image_tags }}"
45-
REGISTRY="${{ secrets.dockerhub_registry }}/${{ inputs.image_name }}"
4654
IFS=',' read -ra ELEMENTS <<< "$TAGS"
4755
TAGS_FIXED=""
4856
for ELEMENT in "${ELEMENTS[@]}"; do
49-
TAGS_FIXED+="$REGISTRY:$ELEMENT,"
57+
TAGS_FIXED+="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$ELEMENT,"
5058
done
5159
TAGS_FIXED=${TAGS_FIXED%,}
5260
echo "tags_fixed=$TAGS_FIXED" >> $GITHUB_ENV
5361
5462
- name: Checkout
55-
uses: actions/checkout@v2
63+
uses: actions/checkout@v4
5664

5765
- name: Set up QEMU
5866
uses: docker/setup-qemu-action@v3
5967

6068
- name: Set up Docker Buildx
6169
uses: docker/setup-buildx-action@v3
6270

63-
- name: Login to Docker Hub
71+
- name: Log in to Docker Hub
6472
uses: docker/login-action@v3
6573
with:
6674
username: ${{ secrets.dockerhub_username }}
6775
password: ${{ secrets.dockerhub_password }}
6876

69-
- name: Build and Push
70-
uses: docker/build-push-action@v5
77+
# Buildx will push:
78+
# - Image (your tags)
79+
# - SBOM as an OCI referrer (sbom: true)
80+
# - SLSA provenance as an OCI referrer (provenance: true)
81+
- name: Build & Push (with SBOM & provenance)
82+
id: build
83+
uses: docker/build-push-action@v6
7184
with:
7285
file: ${{ inputs.dockerfile }}
7386
context: ${{ inputs.context }}
7487
push: true
7588
tags: ${{ env.tags_fixed }}
76-
build-args: ${{ inputs.build-args }}
89+
# Input name has a hyphen → use index notation
90+
build-args: ${{ inputs['build-args'] }}
91+
sbom: true
92+
provenance: true # or 'provenance: mode=max' if you prefer
93+
94+
- name: Install Cosign
95+
uses: sigstore/cosign-installer@v3
96+
97+
- name: Cosign sign image by digest (keyless OIDC)
98+
env:
99+
IMAGE_REF: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
100+
DIGEST: ${{ steps.build.outputs.digest }}
101+
run: |
102+
set -euo pipefail
103+
echo "Signing $IMAGE_REF@$DIGEST"
104+
cosign sign --yes "$IMAGE_REF@$DIGEST"

0 commit comments

Comments
 (0)