Skip to content

Commit 1d68828

Browse files
ci: Refactor docker image github actions
1 parent 882079a commit 1d68828

File tree

1 file changed

+77
-0
lines changed
  • {{cookiecutter.project_slug}}/.github/workflows

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Publish Docker image
2+
3+
on:
4+
schedule:
5+
- cron: "0 10 * * *"
6+
push:
7+
branches:
8+
- "main"
9+
- "master"
10+
tags:
11+
- "*.*.*"
12+
paths-ignore:
13+
- "DOCS.md"
14+
- "README.md"
15+
16+
env:
17+
REGISTRY_URL: ghcr.io
18+
REGISTRY_USER: ${{ github.repository_owner }}
19+
IMAGE: ${{ github.repository }}
20+
21+
jobs:
22+
docker:
23+
strategy:
24+
fail-fast: true
25+
runs-on: ubuntu-latest
26+
permissions:
27+
packages: write
28+
contents: read
29+
steps:
30+
- name: Check out the repo
31+
uses: actions/checkout@v3
32+
33+
- name: Log into Docker Hub
34+
if: ${{ github.event_name != 'pull_request' }}
35+
uses: docker/login-action@v3
36+
with:
37+
username: ${{ secrets.DOCKERHUB_USERNAME }}
38+
password: ${{ secrets.DOCKERHUB_TOKEN }}
39+
40+
- name: Login to GitHub Container Registry
41+
if: ${{ github.event_name != 'pull_request' }}
42+
uses: docker/login-action@v2
43+
with:
44+
registry: ghcr.io
45+
username: ${{ github.repository_owner }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Extract metadata (tags, labels) for Docker
49+
id: meta
50+
uses: docker/metadata-action@v4
51+
with:
52+
images: |
53+
name=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ env.IMAGE }}
54+
tags: |
55+
type=raw,value=latest,enable=${{ endsWith(github.ref, 'main') }}
56+
type=ref,event=branch,enable=${{ !endsWith(github.ref, 'main') }}
57+
type=semver,pattern={{version}}
58+
flavor: |
59+
latest=false
60+
61+
- name: Set up QEMU
62+
uses: docker/setup-qemu-action@v2
63+
64+
- name: Set up Docker Buildx
65+
uses: docker/setup-buildx-action@v3
66+
67+
- name: Build and push Docker image
68+
uses: docker/build-push-action@v5
69+
with:
70+
context: .
71+
file: ./Dockerfile
72+
push: ${{ github.event_name != 'pull_request' }}
73+
tags: ${{ steps.meta.outputs.tags }}
74+
labels: ${{ steps.meta.outputs.labels }}
75+
platforms: linux/amd64
76+
cache-from: type=gha
77+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)