1
- name : Docker Latest Version
2
-
3
1
on :
4
2
push :
5
- branches :
6
- - " master"
3
+ branches : [ "master" ]
4
+ # Publish semver tags as releases.
5
+ tags : [ 'v*.*.*' ]
7
6
pull_request :
8
- branches :
9
- - " master"
10
- workflow_dispatch :
7
+ branches : [ "master" ]
11
8
12
9
env :
13
- # Docker Hub registry URL (use docker.io for Docker Hub)
14
- REGISTRY : docker.io/narmidm
15
- IMAGE_NAME : k8s-pod-cpu-stressor
10
+ # Use docker.io for Docker Hub if empty
11
+ REGISTRY : docker.io
12
+ # github.repository as <account>/<repo>
13
+ IMAGE_NAME : ${{ github.repository }}
14
+
16
15
17
16
jobs :
18
17
build :
18
+
19
19
runs-on : ubuntu-latest
20
20
permissions :
21
21
contents : read
22
22
packages : write
23
+ # This is used to complete the identity challenge
24
+ # with sigstore/fulcio when running outside of PRs.
23
25
id-token : write
26
+
24
27
steps :
25
28
- name : Checkout repository
26
29
uses : actions/checkout@v4
27
30
28
- # Install cosign tool, only run if it's not a pull request
31
+ # Install the cosign tool except on PR
32
+ # https://github.com/sigstore/cosign-installer
29
33
- name : Install cosign
30
34
if : github.event_name != 'pull_request'
31
-
35
+ uses : sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # v3.5.0
32
36
with :
33
37
cosign-release : ' v2.2.4'
34
38
35
- # Set up Docker Buildx for multi-platform builds
39
+ # Set up BuildKit Docker container builder to be able to build
40
+ # multi-platform images and export cache
41
+ # https://github.com/docker/setup-buildx-action
36
42
- name : Set up Docker Buildx
37
-
43
+ uses : docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
38
44
39
- # Login to Docker Hub if not a pull request
40
- - name : Login to Docker Hub
45
+ # Login against a Docker registry except on PR
46
+ # https://github.com/docker/login-action
47
+ - name : Log into registry ${{ env.REGISTRY }}
41
48
if : github.event_name != 'pull_request'
42
- uses : docker/login-action@v3
49
+ uses : docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
43
50
with :
44
- username : ${{ vars.DOCKERHUB_USERNAME }}
45
- password : ${{ secrets.DOCKERHUB_TOKEN }}
51
+ registry : ${{ env.REGISTRY }}
52
+ username : ${{ github.actor }}
53
+ password : ${{ secrets.GITHUB_TOKEN }}
46
54
47
55
# Extract metadata (tags, labels) for Docker
56
+ # https://github.com/docker/metadata-action
48
57
- name : Extract Docker metadata
49
58
id : meta
50
-
59
+ uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
51
60
with :
52
61
images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
53
- tags : latest
54
62
55
- # Build and push Docker image, skip pushing on PRs
63
+ # Build and push Docker image with Buildx (don't push on PR)
64
+ # https://github.com/docker/build-push-action
56
65
- name : Build and push Docker image
57
66
id : build-and-push
58
-
67
+ uses : docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
59
68
with :
60
69
context : .
61
70
push : ${{ github.event_name != 'pull_request' }}
62
- tags : latest
71
+ tags : ${{ steps.meta.outputs.tags }}
63
72
labels : ${{ steps.meta.outputs.labels }}
64
73
cache-from : type=gha
65
74
cache-to : type=gha,mode=max
75
+
76
+ # Sign the resulting Docker image digest except on PRs.
77
+ # This will only write to the public Rekor transparency log when the Docker
78
+ # repository is public to avoid leaking data. If you would like to publish
79
+ # transparency data even for private images, pass --force to cosign below.
80
+ # https://github.com/sigstore/cosign
81
+ # - name: Sign the published Docker image
82
+ # if: ${{ github.event_name != 'pull_request' }}
83
+ # env:
84
+ # # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
85
+ # TAGS: ${{ steps.meta.outputs.tags }}
86
+ # DIGEST: ${{ steps.build-and-push.outputs.digest }}
87
+ # # This step uses the identity token to provision an ephemeral certificate
88
+ # # against the sigstore community Fulcio instance.
89
+ # run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
0 commit comments