Skip to content

Commit af68b6b

Browse files
author
Jon
committed
Add publish container to ghcr
1 parent c48f1da commit af68b6b

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
# Publish semver tags as releases.
8+
tags:
9+
- "*.*.*"
10+
pull_request:
11+
branches: [ main ]
12+
13+
env:
14+
# Use docker.io for Docker Hub if empty
15+
REGISTRY: ghcr.io
16+
# github.repository as <account>/<repo>
17+
IMAGE_NAME: ${{ github.repository }}
18+
19+
20+
jobs:
21+
build:
22+
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
# This is used to complete the identity challenge
28+
# with sigstore/fulcio when running outside of PRs.
29+
id-token: write
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v2
34+
35+
# Workaround: https://github.com/docker/build-push-action/issues/461
36+
- name: Setup Docker buildx
37+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
38+
39+
# Login against a Docker registry except on PR
40+
# https://github.com/docker/login-action
41+
- name: Log into registry ${{ env.REGISTRY }}
42+
if: github.event_name != 'pull_request'
43+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
44+
with:
45+
registry: ${{ env.REGISTRY }}
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
# Extract metadata (tags, labels) for Docker
50+
# https://github.com/docker/metadata-action
51+
- name: Extract Docker metadata
52+
id: meta
53+
uses: docker/metadata-action@v3.6.2
54+
with:
55+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
56+
57+
# Build and push Docker image with Buildx (don't push on PR)
58+
# https://github.com/docker/build-push-action
59+
- name: Build and push Docker image
60+
id: build-and-push
61+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
62+
with:
63+
context: .
64+
push: ${{ github.event_name != 'pull_request' }}
65+
tags: ${{ steps.meta.outputs.tags }}
66+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)