Skip to content

Commit 5cf5c5e

Browse files
committed
Add a GitHub workflow to automatically build and push to a public Docker registry
1 parent 813162e commit 5cf5c5e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags: [v*]
7+
pull_request:
8+
branches: [main]
9+
release:
10+
types: [published]
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
REPOSITORY: ${{ github.repository }}
15+
16+
jobs:
17+
docker-image:
18+
name: Build and push Docker image
19+
runs-on: ubuntu-latest
20+
21+
permissions:
22+
contents: read
23+
packages: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v3
28+
29+
- name: Log in to the Container registry
30+
uses: docker/login-action@v1
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract metadata (tags, labels) for Docker
37+
id: meta
38+
uses: docker/metadata-action@v3
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}
41+
tags: |
42+
type=ref,event=branch
43+
type=ref,event=pr
44+
type=semver,pattern={{version}}
45+
type=semver,pattern={{major}}.{{minor}}
46+
47+
- name: Build and push ${{ env.REGISTRY }}/${{ env.REPOSITORY }} image
48+
uses: docker/build-push-action@v2
49+
with:
50+
context: .
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
push: true

0 commit comments

Comments
 (0)