-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (110 loc) · 3.97 KB
/
Copy pathdocker-server.yml
File metadata and controls
121 lines (110 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# ============================================================
# 服务端 Docker 镜像自动构建并发布到 GHCR
# ============================================================
# 触发条件:
# 1. 推送到 main 分支且 server/ 目录有变更
# 2. 推送 v* 格式的 tag(如 v1.0.0)
# 3. 手动触发
#
# 发布产物:
# - ghcr.io/<owner>/serverstatusapi-server:latest (main 分支)
# - ghcr.io/<owner>/serverstatusapi-server:<tag> (版本 tag,如 v1.0.0)
# - ghcr.io/<owner>/serverstatusapi-server:1.0 (主次版本号)
# - ghcr.io/<owner>/serverstatusapi-server:sha-<short> (commit SHA 前12位)
# ============================================================
name: Build & Publish Server Docker Image
on:
push:
branches:
- main
- master
paths:
- "server/**"
- ".github/workflows/docker-server.yml"
tags:
- "v*"
workflow_dispatch:
inputs:
reason:
description: "构建原因"
required: false
default: "manual"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-server
concurrency:
group: docker-server-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
packages: write
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# ----------------------------------------------------
# 1. 检出代码
# ----------------------------------------------------
- name: Checkout
uses: actions/checkout@v4
# ----------------------------------------------------
# 2. 提取镜像元数据(tags + labels)
# ----------------------------------------------------
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix=sha-,format=short
labels: |
org.opencontainers.image.title=MC服务器状态监测-服务端
org.opencontainers.image.description=Minecraft Server Status Monitor - Server
org.opencontainers.image.licenses=MIT
# ----------------------------------------------------
# 3. 登录 GHCR
# ----------------------------------------------------
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# ----------------------------------------------------
# 4. 设置 Docker Buildx
# ----------------------------------------------------
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# ----------------------------------------------------
# 5. 构建并推送镜像
# ----------------------------------------------------
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: server/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ----------------------------------------------------
# 6. 输出镜像摘要
# ----------------------------------------------------
- name: Image digest
run: |
echo "✅ 服务端镜像构建并推送成功"
echo ""
echo "镜像地址:"
echo " ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
echo ""
echo "Tags:"
echo "${{ steps.meta.outputs.tags }}" | sed 's/^/ /'
echo ""
echo "Digest:"
echo " ${{ steps.meta.outputs.digest }}"