Skip to content

Commit 1f5e60a

Browse files
committed
Build, publish, and scan image to GHCR
1 parent 3a5c997 commit 1f5e60a

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

.github/workflows/build-and-sign-image.yml

+31-19
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
name: Build and sign image
44

55
on:
6-
# THIS BLOCK IS FOR TESTING
7-
create:
6+
pull_request:
7+
types:
8+
- closed
9+
branches:
10+
- "main"
811

9-
# THIS BLOCK IS THE ACTUAL DESIRED EVENT TRIGGER
10-
# pull_request:
12+
# push:
1113
# branches:
12-
# - "*" # Run on all branches
13-
# types:
14-
# - closed ## This needs to be uncommented after testing
14+
# - "trigger-image-build-and-push-1"
1515

1616
env:
17-
REGISTRY: docker.io
18-
IMAGE_NAME: "ciroque/nginx-k8s-loadbalancer" # ${{ github.repository }}
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: ${{ github.repository }}
1919

2020
jobs:
2121
build_and_sign_image:
@@ -24,6 +24,7 @@ jobs:
2424
contents: read
2525
packages: write
2626
id-token: write
27+
security-events: write
2728

2829
steps:
2930
- name: Checkout
@@ -35,23 +36,34 @@ jobs:
3536
with:
3637
cosign-release: 'v1.13.1'
3738

38-
- name: Docker Buildx
39-
uses: docker/setup-buildx-action@4b4e9c3e2d4531116a6f8ba8e71fc6e2cb6e6c8c # v2.5.0
39+
- name: Log into registry ${{ env.REGISTRY }} for ${{ github.actor }}
40+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
4045

41-
# - name: Log into registry ${{ env.REGISTRY }} for ${{ github.actor }}
42-
# uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
43-
# with:
44-
# registry: ${{ env.REGISTRY }}
45-
# username: ${{ github.actor }}
46-
# password: ${{ secrets.DOCKER_HUB_TOKEN }}
46+
- name: Extract metadata (tags, labels) for Docker
47+
id: meta
48+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
49+
with:
50+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4751

4852
- name: Build Docker Image
53+
id: docker-build-and-push
4954
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
5055
with:
5156
context: .
5257
file: ./Dockerfile
53-
push: false
54-
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
58+
push: true
59+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{github.run_number}}
60+
61+
- name: Sign the published Docker images
62+
env:
63+
COSIGN_EXPERIMENTAL: "true"
64+
# This step uses the identity token to provision an ephemeral certificate
65+
# against the sigstore community Fulcio instance.
66+
run: cosign sign "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.docker-build-and-push.outputs.digest }}"
5567

5668
# NOTE: This runs statically against the latest tag in Docker Hub which was not produced by this workflow
5769
# This should be updated once this workflow is fully implemented

0 commit comments

Comments
 (0)