Skip to content

Commit b9a7db9

Browse files
committed
Add publish-docker workflow
1 parent 4c2c33d commit b9a7db9

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Build and publish Docker image
2+
3+
env:
4+
platforms: linux/amd64,linux/arm64
5+
6+
on:
7+
release:
8+
types:
9+
- published
10+
push:
11+
branches:
12+
- main
13+
tags:
14+
- v*
15+
paths-ignore:
16+
- 'docs/**'
17+
- '**/*.md'
18+
pull_request:
19+
paths-ignore:
20+
- 'docs/**'
21+
- '**/*.md'
22+
types: [labeled, unlabeled, opened, synchronize, reopened]
23+
24+
permissions:
25+
contents: read
26+
packages: write
27+
28+
jobs:
29+
publish-docker:
30+
name: Build and publish Docker image
31+
# Condition: Run on push to main, published release, OR PR with 'ok-to-image' label
32+
if: |
33+
github.event_name == 'push' ||
34+
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ok-to-image')) ||
35+
(github.event_name == 'release' && github.event.action == 'published')
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Check out repository
39+
uses: actions/checkout@v4
40+
with:
41+
ref: ${{ github.event.pull_request.head.sha }}
42+
- name: Collect metadata
43+
uses: docker/metadata-action@v5
44+
id: meta
45+
with:
46+
images: |
47+
ghcr.io/${{ github.repository_owner }}/khalkeon
48+
tags: |
49+
type=semver,pattern={{version}}
50+
type=schedule
51+
type=ref,event=branch
52+
type=ref,event=tag
53+
type=ref,event=pr
54+
type=sha
55+
flavor: |
56+
latest=${{ github.ref == 'refs/heads/main' }}
57+
- name: Set up QEMU
58+
uses: docker/setup-qemu-action@v3
59+
with:
60+
image: tonistiigi/binfmt:latest
61+
platforms: ${{ env.platforms }}
62+
- name: Set up Docker Buildx context
63+
run: |
64+
docker context create builders
65+
- name: Set up Docker Buildx
66+
uses: docker/setup-buildx-action@v3
67+
timeout-minutes: 5
68+
with:
69+
version: latest
70+
endpoint: builders
71+
- name: Log in to GHCR
72+
uses: docker/login-action@v3
73+
with:
74+
registry: ghcr.io
75+
username: ${{ github.actor }}
76+
password: ${{ secrets.GITHUB_TOKEN }}
77+
- name: Build and push Docker image
78+
uses: docker/build-push-action@v6
79+
timeout-minutes: 10
80+
with:
81+
context: .
82+
platforms: ${{ env.platforms }}
83+
tags: ${{ steps.meta.outputs.tags }}
84+
labels: ${{ steps.meta.outputs.labels }}
85+
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'ok-to-publish') }}

0 commit comments

Comments
 (0)