Skip to content

Commit a560ef0

Browse files
authored
chore: Added container image build
1 parent 254179a commit a560ef0

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
# Publish semver tags as releases.
7+
tags: [ 'v*.*.*' ]
8+
pull_request:
9+
branches: [ main ]
10+
11+
env:
12+
# Use docker.io for Docker Hub if empty
13+
REGISTRY: ghcr.io
14+
# github.repository as <account>/<repo>
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
18+
jobs:
19+
build:
20+
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
# This is used to complete the identity challenge
26+
# with sigstore/fulcio when running outside of PRs.
27+
id-token: write
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v3
32+
33+
# Install the cosign tool except on PR
34+
# https://github.com/sigstore/cosign-installer
35+
- name: Install cosign
36+
if: github.event_name != 'pull_request'
37+
uses: sigstore/cosign-installer@d6a3abf1bdea83574e28d40543793018b6035605
38+
with:
39+
cosign-release: 'v1.7.1'
40+
41+
42+
# Workaround: https://github.com/docker/build-push-action/issues/461
43+
- name: Setup Docker buildx
44+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
45+
46+
# Login against a Docker registry except on PR
47+
# https://github.com/docker/login-action
48+
- name: Log into registry ${{ env.REGISTRY }}
49+
if: github.event_name != 'pull_request'
50+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
51+
with:
52+
registry: ${{ env.REGISTRY }}
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
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@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
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@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
69+
with:
70+
context: .
71+
push: ${{ github.event_name != 'pull_request' }}
72+
tags: ${{ steps.meta.outputs.tags }}
73+
labels: ${{ steps.meta.outputs.labels }}
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+
COSIGN_EXPERIMENTAL: "true"
84+
# This step uses the identity token to provision an ephemeral certificate
85+
# against the sigstore community Fulcio instance.
86+
run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}

0 commit comments

Comments
 (0)