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