Skip to content

Commit f61aeef

Browse files
authored
Create docker-publish.yml
1 parent f6efd44 commit f61aeef

File tree

1 file changed

+88
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)