Skip to content

Commit 5126020

Browse files
authored
Update Docker CI workflow to support tags and buildx
1 parent 2b4e171 commit 5126020

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

.github/workflows/docker-image.yml

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,56 @@
1-
name: Docker Image CI
1+
name: Build and Publish Docker Image
22

33
on:
44
push:
5-
branches: [ "main" ]
6-
pull_request:
7-
branches: [ "main" ]
5+
branches: [main]
6+
tags: ['v*']
7+
workflow_dispatch:
88

9-
jobs:
10-
11-
build:
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
1212

13+
jobs:
14+
build-and-push:
1315
runs-on: ubuntu-latest
16+
# 仅在主仓库运行,fork 仓库跳过
17+
if: github.repository == 'dext7r/KiroGate'
18+
permissions:
19+
contents: read
20+
packages: write
1421

1522
steps:
16-
- uses: actions/checkout@v4
17-
- name: Build the Docker image
18-
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Log in to Container Registry
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract metadata (tags, labels)
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
tags: |
42+
type=ref,event=branch
43+
type=semver,pattern={{version}}
44+
type=semver,pattern={{major}}.{{minor}}
45+
type=sha,prefix=
46+
47+
- name: Build and push Docker image
48+
uses: docker/build-push-action@v6
49+
with:
50+
context: .
51+
push: true
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max
56+
platforms: linux/amd64,linux/arm64

0 commit comments

Comments
 (0)