55 types : [published]
66
77env :
8- # Use docker.io for Docker Hub if empty
98 REGISTRY : docker.io
10- # github.repository as <account>/<repo>
11- IMAGE_NAME : ${{ github.repository }}
9+ REPOSITORY : getspike
1210 DOCKERHUB_USERNAME : ${{ secrets.DOCKERHUB_USERNAME }}
1311 COSIGN_EXPERIMENTAL : 1
1412 DOCKER_CONTENT_TRUST : 1
15- DOCKER_CONTENT_TRUST_SERVER : https://notary.docker.io
1613
1714jobs :
1815 docker :
1916 runs-on : ubuntu-latest
2017 strategy :
2118 matrix :
22- include :
23- - dockerfile : k8s/dockerfiles/pilot.Dockerfile
24- image : getspike/pilot
25- - dockerfile : k8s/dockerfiles/keeper.Dockerfile
26- image : getspike/keeper
27- - dockerfile : k8s/dockerfiles/nexus.Dockerfile
28- image : getspike/nexus
19+ app : [pilot, keeper, nexus]
20+ arch : [linux/amd64, linux/arm64]
2921 permissions :
3022 contents : read
3123 packages : write
4638 - name : Install cosign
4739 uses : sigstore/cosign-installer@v3.3.0
4840
49- # Setup Docker Content Trust keys
50- - name : Setup DCT
51- if : github.event_name == 'release'
52- env :
53- DCT_DELEGATION_KEY : ${{ secrets.DCT_DELEGATION_KEY }}
54- run : |
55- mkdir -p ~/.docker/trust/private
56- echo "$DCT_DELEGATION_KEY" > ~/.docker/trust/private/$(echo -n "${{ env.REGISTRY }}/${{ matrix.image }}" | sha256sum | cut -d' ' -f1).key
57-
5841 # Login to Docker Hub
5942 - name : Log in to Docker Hub
6043 uses : docker/login-action@v3
@@ -67,86 +50,47 @@ jobs:
6750 id : meta
6851 uses : docker/metadata-action@v5
6952 with :
70- images : ${{ env.REGISTRY }}/${{ matrix.image }}
53+ images : ${{ env.REGISTRY }}/${{ env.REPOSITORY }}/${{ matrix.app }}
7154 tags : |
72- type=semver,pattern={{version}},value=${{ github.event.release.tag_name }}
73- type=semver,pattern={{major}}.{{minor}},value=${{ github.event.release.tag_name }}
74- type=raw,value=latest
75- type=sha
76- # example tags in order: 1.2.3, 1.2, latest, sha-1234567890(git commit sha)
55+ type=semver,pattern={{version}}-${{ matrix.arch }},value=${{ github.event.release.tag_name }}
56+ type=semver,pattern={{major}}.{{minor}}-${{ matrix.arch }},value=${{ github.event.release.tag_name }}
57+ type=raw,value=latest-${{ matrix.arch }}
58+ type=sha-${{ matrix.arch }}
59+ ${{ matrix.arch == 'linux/amd64' && 'type=raw,value=latest' || '' }}
60+ # example tags in order: 1.2.3-linux/amd64, 1.2-linux/amd64, latest-linux/amd64, sha-1234567890(git commit sha)
61+ # if arch is linux/amd64, then add latest tag
7762
78- # Build and push Docker image
79- - name : Build and push
63+ # Build and load Docker image
64+ - name : Build and load
8065 uses : docker/build-push-action@v5
81- id : build-and-push
82- env :
83- DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE : ${{ secrets.DCT_DELEGATION_PASSPHRASE }}
84- DOCKER_CONTENT_TRUST : 1
66+ id : build-and-load
8567 with :
8668 context : .
87- file : ${{ matrix.dockerfile }}
88- platforms : linux/amd64,linux/arm64
89- push : ${{ github.event_name == 'release' }}
69+ file : k8s/dockerfiles/${{ matrix.app }}.Dockerfile
70+ platforms : ${{ matrix.arch }}
71+ load : true
72+ push : false
9073 tags : ${{ steps.meta.outputs.tags }}
9174 labels : ${{ steps.meta.outputs.labels }}
92- cache-from : type=registry,ref=${{ env.REGISTRY }}/${{ matrix.image }}:buildcache
93- cache-to : type=registry,ref=${{ env.REGISTRY }}/${{ matrix.image }}:buildcache ,mode=max
75+ cache-from : type=gha
76+ cache-to : type=gha ,mode=max
9477 provenance : mode=max
9578
96- - name : Install Notary CLI
79+ - name : Push to Docker Hub
80+ env :
81+ DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE : ${{ secrets.DCT_DELEGATION_PASSPHRASE }}
82+ DOCKER_CONTENT_TRUST : 1
9783 run : |
98- curl -L https://github.com/notaryproject/notary/releases/download/v0.6.1/notary-Linux-amd64 -o /usr/local/bin/notary
99- chmod +x /usr/local/bin/notary
84+ for tag in $(echo "${{ steps.meta.outputs.tags }}"); do
85+ echo "Pushing tag: $tag"
86+ docker push "${{ env.REGISTRY }}/${{ env.REPOSITORY }}/${{ matrix.app }}:$tag"
87+ done
10088
101- - name : Sign the image using Notary
102- if : github.event_name == 'release'
89+ - name : Sign the images with GitHub OIDC (Cosign)
10390 env :
104- DCT_DELEGATION_PASSPHRASE : ${{ secrets.DCT_DELEGATION_PASSPHRASE }}
105- DOCKERHUB_USERNAME : ${{ secrets.DOCKERHUB_USERNAME }}
106- DOCKERHUB_TOKEN : ${{ secrets.DOCKERHUB_TOKEN }}
91+ DIGEST : ${{ steps.build-and-load.outputs.digest }}
92+ TAGS : ${{ steps.meta.outputs.tags }}
10793 run : |
108- set -e # Exit on any error
109-
110- export DOCKER_CONTENT_TRUST=1
111- export DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE="${{ secrets.DCT_DELEGATION_PASSPHRASE }}"
112-
113- echo "Authenticating with Docker Hub..."
114- echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
115-
116- echo "Checking if notary CLI is installed..."
117- if ! command -v notary &> /dev/null; then
118- echo "Error: notary CLI is not installed. Install it before proceeding."
119- exit 1
120- fi
121-
122- echo "Inspecting trust data for ${{ env.REGISTRY }}/${{ matrix.image }}..."
123- if ! docker trust inspect --pretty "${{ env.REGISTRY }}/${{ matrix.image }}"; then
124- echo "No trust data found, signing now."
125- fi
126-
127- echo "Fetching image size..."
128- MANIFEST_JSON=$(docker manifest inspect "${{ env.REGISTRY }}/${{ matrix.image }}")
129-
130- if [ -z "$MANIFEST_JSON" ] || [ "$MANIFEST_JSON" == "null" ]; then
131- echo "Error: Unable to fetch manifest for the image. Ensure the image exists and is public."
132- exit 1
133- fi
134-
135- IMAGE_SIZE=$(echo "$MANIFEST_JSON" | jq -r 'if .layers then .layers | map(.size) | add else .manifests | map(.size) | add end')
136-
137- if [ -z "$IMAGE_SIZE" ] || [ "$IMAGE_SIZE" == "null" ]; then
138- echo "Error: Unable to determine image size."
139- exit 1
140- fi
141-
142- # Extract the hash without the 'sha256:' prefix
143- DIGEST_RAW=$(echo "${{ steps.build-and-push.outputs.digest }}" | sed 's/^sha256://')
144-
145- echo "digest: $DIGEST_RAW"
146-
147- echo "Signing the image with Notary..."
148- notary -s https://notary.docker.io -d ~/.docker/trust addhash \
149- "${{ env.REGISTRY }}/${{ matrix.image }}" "${{ steps.build-and-push.outputs.digest }}" \
150- "$IMAGE_SIZE" --sha256 "$DIGEST_RAW"
151-
152- echo "Signature added successfully."
94+ echo "${TAGS}" | tr ',' '\n' | while read -r tag; do
95+ cosign sign --yes "${tag}@${DIGEST}"
96+ done
0 commit comments