Skip to content

Commit eeff45b

Browse files
committed
feat: 添加 GitHub Actions 工作流以构建和推送 Docker 镜像
1 parent b72ee22 commit eeff45b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

.github/workflows/docker.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
packages: write
13+
id-token: write
14+
actions: read
15+
16+
jobs:
17+
build-docker:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code (full history)
21+
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v2
27+
28+
- name: Login to GitHub Container Registry
29+
if: github.event_name != 'pull_request'
30+
uses: docker/login-action@v2
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract metadata for Docker
37+
id: meta
38+
uses: docker/metadata-action@v4
39+
with:
40+
images: ghcr.io/${{ github.repository_owner }}/abmc-forwarder
41+
tags: |
42+
type=ref,event=branch
43+
type=ref,event=pr
44+
type=semver,pattern={{version}}
45+
type=semver,pattern={{major}}.{{minor}}
46+
type=sha,format=short
47+
latest
48+
49+
- name: Build and push Docker image
50+
uses: docker/build-push-action@v4
51+
with:
52+
context: .
53+
file: ./Dockerfile
54+
push: ${{ github.event_name != 'pull_request' }}
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}
57+
platforms: linux/amd64,linux/arm64
58+
cache-from: type=gha
59+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)