1
+ name : Build Container Image
2
+
3
+ # This workflow uses actions that are not certified by GitHub.
4
+ # They are provided by a third-party and are governed by
5
+ # separate terms of service, privacy policy, and support
6
+ # documentation.
7
+
8
+ on :
9
+ push :
10
+ branches : [ "main" ]
11
+ # Publish semver tags as releases.
12
+ tags : [ '*.*.*' ]
13
+ pull_request :
14
+ branches : [ "main" ]
15
+
16
+ env :
17
+ # Use docker.io for Docker Hub if empty
18
+ REGISTRY : ghcr.io
19
+ # github.repository as <account>/<repo>
20
+ IMAGE_NAME : ${{ github.repository }}
21
+
22
+
23
+ jobs :
24
+ build :
25
+
26
+ runs-on : ubuntu-latest
27
+ permissions :
28
+ contents : read
29
+ packages : write
30
+ # This is used to complete the identity challenge
31
+ # with sigstore/fulcio when running outside of PRs.
32
+ id-token : write
33
+
34
+ steps :
35
+ - name : Checkout repository
36
+ uses : actions/checkout@v3
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
+
43
+ with :
44
+ cosign-release : ' v2.2.3'
45
+
46
+ # Set up QEMU to be able to build to multiple architectures
47
+ - name : Set up QEMU
48
+ uses : docker/setup-qemu-action@v1
49
+
50
+ # Workaround: https://github.com/docker/build-push-action/issues/461
51
+ - name : Setup Docker buildx
52
+
53
+
54
+ # Login against a Docker registry except on PR
55
+ # https://github.com/docker/login-action
56
+ - name : Log into registry ${{ env.REGISTRY }}
57
+ if : github.event_name != 'pull_request'
58
+
59
+ with :
60
+ registry : ${{ env.REGISTRY }}
61
+ username : ${{ github.actor }}
62
+ password : ${{ secrets.GITHUB_TOKEN }}
63
+
64
+ # Extract metadata (tags, labels) for Docker
65
+ # https://github.com/docker/metadata-action
66
+ - name : Extract Docker metadata
67
+ id : meta
68
+
69
+ with :
70
+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
71
+
72
+ # Build and push Docker image with Buildx (don't push on PR)
73
+ # https://github.com/docker/build-push-action
74
+ - name : Build and push Docker image
75
+ id : build-and-push
76
+
77
+ with :
78
+ context : .
79
+ push : ${{ github.event_name != 'pull_request' }}
80
+ tags : ${{ steps.meta.outputs.tags }}
81
+ labels : ${{ steps.meta.outputs.labels }}
82
+ platforms : linux/amd64,linux/arm64
83
+
84
+
85
+ # Sign the resulting Docker image digest except on PRs.
86
+ # This will only write to the public Rekor transparency log when the Docker
87
+ # repository is public to avoid leaking data. If you would like to publish
88
+ # transparency data even for private images, pass --force to cosign below.
89
+ # https://github.com/sigstore/cosign
90
+ - name : Sign the published Docker image
91
+ if : ${{ github.event_name != 'pull_request' }}
92
+ env :
93
+ COSIGN_EXPERIMENTAL : " true"
94
+ # This step uses the identity token to provision an ephemeral certificate
95
+ # against the sigstore community Fulcio instance.
96
+ run : echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push.outputs.digest }}
0 commit comments