Skip to content

Commit a694c19

Browse files
committed
Push docker builds to GHCR
1 parent 01587a2 commit a694c19

File tree

5 files changed

+184
-168
lines changed

5 files changed

+184
-168
lines changed

.dockerignore

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

0 commit comments

Comments
 (0)