Skip to content

Commit 89fc4fc

Browse files
authored
Merge pull request #24 from JW-CH/master
Build action for docker
2 parents 0ebeae1 + 3392827 commit 89fc4fc

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

.github/workflows/build-docker.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Build and Publish image to Docker Hub
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version number"
8+
default: "1.0.0.0"
9+
push:
10+
tags:
11+
- "v*" # Only triggers on versioned tags, e.g., v1.0, v20.15.10
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
permissions:
18+
packages: write
19+
20+
jobs:
21+
publish_images:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
with:
30+
install: true
31+
32+
# Login to GHCR
33+
- name: Log into registry ${{ env.REGISTRY }}
34+
if: github.event_name != 'pull_request'
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
# Extract metadata (tags, labels) for Docker
42+
- name: Extract Docker metadata (${{ env.IMAGE_NAME }})
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
47+
48+
- name: Extract version (from tag or manual input)
49+
id: version
50+
run: |
51+
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
52+
echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
53+
else
54+
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
55+
fi
56+
57+
# Build and push Docker image for multiple platforms
58+
- name: Build and push Docker image (${{ env.IMAGE_NAME }})
59+
uses: docker/build-push-action@v6
60+
with:
61+
context: .
62+
platforms: linux/amd64,linux/arm64
63+
push: ${{ github.event_name != 'pull_request' }}
64+
tags: ${{ steps.meta.outputs.tags }}
65+
labels: ${{ steps.meta.outputs.labels }}
66+
build-args: |
67+
VERSION=${{ steps.version.outputs.VERSION }}

0 commit comments

Comments
 (0)