Skip to content

Commit c21cfdb

Browse files
committed
add docker workflow
1 parent ca4ed2d commit c21cfdb

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

.github/workflows/docker.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
10+
11+
jobs:
12+
Build-and-Push:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Prepare Docker Meta
19+
id: meta
20+
uses: docker/metadata-action@v5
21+
with:
22+
images: |
23+
ghcr.io/transprogrammer/rodhaj
24+
tags: |
25+
type=semver,pattern={{version}}
26+
type=semver,pattern={{major}}.{{minor}}
27+
type=semver,pattern={{major}}
28+
type=edge,branch=main
29+
30+
- name: Setup Docker Buildx
31+
id: buildx
32+
uses: docker/setup-buildx-action@v3
33+
with:
34+
version: latest
35+
36+
- name: Login to GitHub Container Registry
37+
uses: docker/login-action@v3
38+
# Skip when PR from a fork
39+
if: ${{ !github.event.pull_request.head.repo.fork }}
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.repository_owner }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
46+
- name: Determine build cache output
47+
id: cache-target
48+
run: |
49+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
50+
# Essentially just ignore the cache output (PR can't write to registry cache)
51+
echo "cache-to=type=local,dest=/tmp/discard,ignore-error=true" >> $GITHUB_OUTPUT
52+
else
53+
echo "cache-to=type=registry,mode=max,ref=ghcr.io/${{ github.repository_owner }}/rodhaj:bot" >> $GITHUB_OUTPUT
54+
fi
55+
56+
- name: Build and push image
57+
uses: docker/build-push-action@v6
58+
with:
59+
context: .
60+
file: ./docker/Dockerfile
61+
# Skip pushing when PR from a fork
62+
push: ${{ !github.event.pull_request.head.repo.fork }}
63+
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/rodhaj:bot
64+
cache-to: ${{ steps.cache-target.outputs.cache-to }}
65+
tags: ${{ steps.meta.outputs.tags }}
66+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)