Skip to content

Commit 6ab4992

Browse files
committed
ci: add docker build to ci
1 parent eb72617 commit 6ab4992

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

.github/workflows/publish.yaml

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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: [ "main" ]
11+
# Publish semver tags as releases.
12+
tags: [ 'v*.*.*' ]
13+
pull_request:
14+
branches: [ "main" ]
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+
strategy:
26+
matrix:
27+
directory: [app, backend]
28+
29+
runs-on: ubuntu-latest
30+
permissions:
31+
contents: read
32+
packages: write
33+
# This is used to complete the identity challenge
34+
# with sigstore/fulcio when running outside of PRs.
35+
id-token: write
36+
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v3
40+
41+
# Install the cosign tool except on PR
42+
# https://github.com/sigstore/cosign-installer
43+
- name: Install cosign
44+
if: github.event_name != 'pull_request'
45+
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
46+
with:
47+
cosign-release: 'v2.1.1'
48+
49+
# Set up BuildKit Docker container builder to be able to build
50+
# multi-platform images and export cache
51+
# https://github.com/docker/setup-buildx-action
52+
- name: Set up Docker Buildx
53+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
54+
55+
# Login against a Docker registry except on PR
56+
# https://github.com/docker/login-action
57+
- name: Log into registry ${{ env.REGISTRY }}
58+
if: github.event_name != 'pull_request'
59+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
60+
with:
61+
registry: ${{ env.REGISTRY }}
62+
username: ${{ github.actor }}
63+
password: ${{ secrets.GITHUB_TOKEN }}
64+
65+
# Extract metadata (tags, labels) for Docker
66+
# https://github.com/docker/metadata-action
67+
- name: Extract Docker metadata
68+
id: meta
69+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
70+
with:
71+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.directory }}
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@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
78+
with:
79+
context: ./${{ matrix.directory }}
80+
push: ${{ github.event_name != 'pull_request' }}
81+
tags: ${{ steps.meta.outputs.tags }}
82+
labels: ${{ steps.meta.outputs.labels }}
83+
cache-from: type=gha
84+
cache-to: type=gha,mode=max
85+
86+
# Sign the resulting Docker image digest except on PRs.
87+
# This will only write to the public Rekor transparency log when the Docker
88+
# repository is public to avoid leaking data. If you would like to publish
89+
# transparency data even for private images, pass --force to cosign below.
90+
# https://github.com/sigstore/cosign
91+
- name: Sign the published Docker image
92+
if: ${{ github.event_name != 'pull_request' }}
93+
env:
94+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
95+
TAGS: ${{ steps.meta.outputs.tags }}
96+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
97+
# This step uses the identity token to provision an ephemeral certificate
98+
# against the sigstore community Fulcio instance.
99+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 commit comments

Comments
 (0)