Skip to content

Commit fcfe30b

Browse files
committed
Add GitHub action for building and pushing images to GitHub Container Registry (GHCR)
1 parent 2a239ef commit fcfe30b

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

.github/workflows/ghcr.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: "GHCR Publish"
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
packages: write
9+
contents: read
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
jobs:
16+
GHCR:
17+
name: GHCR Build & Publish
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
24+
- name: Login to DockerHub
25+
uses: docker/login-action@v2
26+
env:
27+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
28+
if: ${{ env.DOCKERHUB_USERNAME != '' }}
29+
with:
30+
username: ${{ secrets.DOCKERHUB_USERNAME }}
31+
password: ${{ secrets.DOCKERHUB_TOKEN }}
32+
33+
- name: Login to GitHub Container Registry
34+
uses: docker/login-action@v2
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata (tags, labels) for Docker
41+
id: meta
42+
uses: docker/metadata-action@v4
43+
with:
44+
images: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}
45+
flavor: latest=true
46+
47+
- name: Build and push Docker image
48+
uses: docker/build-push-action@v3
49+
with:
50+
context: .
51+
push: true
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
55+
- name: Show info about built Docker image
56+
uses: essentialkaos/docker-info-action@v1
57+
with:
58+
image: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
59+
show-labels: true

0 commit comments

Comments
 (0)