3
3
name : Build and sign image
4
4
5
5
on :
6
- # THIS BLOCK IS FOR TESTING
7
- create :
6
+ pull_request :
7
+ types :
8
+ - closed
9
+ branches :
10
+ - " main"
8
11
9
- # THIS BLOCK IS THE ACTUAL DESIRED EVENT TRIGGER
10
- # pull_request:
12
+ # push:
11
13
# branches:
12
- # - "*" # Run on all branches
13
- # types:
14
- # - closed ## This needs to be uncommented after testing
14
+ # - "trigger-image-build-and-push-1"
15
15
16
16
env :
17
- REGISTRY : docker .io
18
- IMAGE_NAME : " ciroque/nginx-k8s-loadbalancer " # ${{ github.repository }}
17
+ REGISTRY : ghcr .io
18
+ IMAGE_NAME : ${{ github.repository }}
19
19
20
20
jobs :
21
21
build_and_sign_image :
24
24
contents : read
25
25
packages : write
26
26
id-token : write
27
+ security-events : write
27
28
28
29
steps :
29
30
- name : Checkout
@@ -35,23 +36,34 @@ jobs:
35
36
with :
36
37
cosign-release : ' v1.13.1'
37
38
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 }}
40
45
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 }}
47
51
48
52
- name : Build Docker Image
53
+ id : docker-build-and-push
49
54
uses : docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
50
55
with :
51
56
context : .
52
57
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 }}"
55
67
56
68
# NOTE: This runs statically against the latest tag in Docker Hub which was not produced by this workflow
57
69
# This should be updated once this workflow is fully implemented
0 commit comments