Skip to content

Commit fac03a6

Browse files
authored
Install a github action to publish docker images. (#1416)
* Install a github action to publish docker images. * Our main branch name is still "master".
1 parent 8d97a31 commit fac03a6

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Docker
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
branches: [ master ]
11+
# Publish semver tags as releases.
12+
tags: [ 'v*.*.*' ]
13+
pull_request:
14+
branches: [ master ]
15+
16+
env:
17+
# Use docker.io for Docker Hub if empty
18+
REGISTRY: ghcr.io
19+
# github.repository as <account>/<repo>
20+
IMAGE_NAME: ${{ github.repository }}
21+
22+
23+
jobs:
24+
build:
25+
26+
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
29+
packages: write
30+
# This is used to complete the identity challenge
31+
# with sigstore/fulcio when running outside of PRs.
32+
id-token: write
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v2
37+
38+
39+
# Install the cosign tool except on PR
40+
# https://github.com/sigstore/cosign-installer
41+
- name: Install cosign
42+
if: github.event_name != 'pull_request'
43+
uses: sigstore/[email protected]
44+
with:
45+
cosign-release: 'v1.4.1'
46+
47+
48+
# Workaround: https://github.com/docker/build-push-action/issues/461
49+
- name: Setup Docker buildx
50+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
51+
52+
# Login against a Docker registry except on PR
53+
# https://github.com/docker/login-action
54+
- name: Log into registry ${{ env.REGISTRY }}
55+
if: github.event_name != 'pull_request'
56+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
57+
with:
58+
registry: ${{ env.REGISTRY }}
59+
username: ${{ github.actor }}
60+
password: ${{ secrets.GITHUB_TOKEN }}
61+
62+
# Extract metadata (tags, labels) for Docker
63+
# https://github.com/docker/metadata-action
64+
- name: Extract Docker metadata
65+
id: meta
66+
uses: docker/[email protected]
67+
with:
68+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
69+
tags: |
70+
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
71+
type=semver,pattern={{version}}
72+
73+
# Build and push Docker image with Buildx (don't push on PR)
74+
# https://github.com/docker/build-push-action
75+
- name: Build and push Docker image
76+
id: build-and-push
77+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
78+
with:
79+
context: .
80+
push: ${{ github.event_name != 'pull_request' }}
81+
tags: ${{ steps.meta.outputs.tags }}
82+
labels: ${{ steps.meta.outputs.labels }}
83+
84+
# Sign the resulting Docker image digest except on PRs.
85+
# This will only write to the public Rekor transparency log when the Docker
86+
# repository is public to avoid leaking data. If you would like to publish
87+
# transparency data even for private images, pass --force to cosign below.
88+
# https://github.com/sigstore/cosign
89+
- name: Sign the published Docker image
90+
if: ${{ github.event_name != 'pull_request' }}
91+
env:
92+
COSIGN_EXPERIMENTAL: "true"
93+
# This step uses the identity token to provision an ephemeral certificate
94+
# against the sigstore community Fulcio instance.
95+
run: cosign sign ${{ steps.meta.outputs.tags }}@${{ steps.build-and-push.outputs.digest }}

0 commit comments

Comments
 (0)