Skip to content

Commit 182b2dc

Browse files
authored
Create docker-publish.yml
1 parent 89ec3a4 commit 182b2dc

File tree

1 file changed

+85
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)