Skip to content

Commit 13894bf

Browse files
committed
ci: add docker publish
1 parent de6cb39 commit 13894bf

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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: [ $default-branch ]
11+
# Publish semver tags as releases.
12+
tags: [ 'v*.*.*' ]
13+
14+
env:
15+
# Use docker.io for Docker Hub if empty
16+
REGISTRY: ghcr.io
17+
# github.repository as <account>/<repo>
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
21+
jobs:
22+
build:
23+
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
# This is used to complete the identity challenge
29+
# with sigstore/fulcio when running outside of PRs.
30+
id-token: write
31+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v3
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@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
63+
with:
64+
context: .
65+
push: ${{ github.event_name != 'pull_request' }}
66+
tags: ${{ steps.meta.outputs.tags }}
67+
labels: ${{ steps.meta.outputs.labels }}
68+
cache-from: type=gha
69+
cache-to: type=gha,mode=max
70+

0 commit comments

Comments
 (0)