-
Notifications
You must be signed in to change notification settings - Fork 75
130 lines (116 loc) · 4.88 KB
/
docker.yml
File metadata and controls
130 lines (116 loc) · 4.88 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
122
123
124
125
126
127
128
129
130
name: Docker CI (release)
on:
push:
tags: [ 'v*.*.*' ]
branches: [ main ]
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# 过滤掉 beta 标签,只处理正式版本
if: ${{ !contains(github.ref, 'beta') }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
# 使用默认的buildx实例,避免平台检测问题
use: true
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🔍 验证构建环境
run: |
echo "🏗️ Docker Buildx信息:"
docker buildx ls
echo ""
echo "🎯 支持的平台:"
docker buildx inspect --bootstrap | grep "Platforms:"
echo ""
echo "📋 当前构建配置:"
echo " - 目标平台: linux/amd64, linux/arm64"
echo " - 触发方式: ${{ github.ref }}"
- name: 📝 获取版本信息
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
# Tag触发,从tag获取版本
TAG_VERSION=${GITHUB_REF#refs/tags/v}
VERSION=$TAG_VERSION
IS_RELEASE=true
echo "🏷️ Tag触发,版本: $VERSION (正式发布)"
else
# 非tag触发,使用package.json版本
VERSION=$(node -p "require('./web/package.json').version")
IS_RELEASE=false
echo "📦 非tag触发,使用package.json版本: $VERSION (开发版本)"
fi
REPO_LC=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT
echo "is_main=${{ github.ref == 'refs/heads/main' }}" >> $GITHUB_OUTPUT
echo "repo_name=$REPO_LC" >> $GITHUB_OUTPUT
echo "📦 最终版本: $VERSION, 是否发布: $IS_RELEASE"
- name: 📋 提取镜像元数据
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ steps.get_version.outputs.repo_name }}
tags: |
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' }}
type=raw,value=${{ steps.get_version.outputs.version }},enable=${{ startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' }}
labels: |
org.opencontainers.image.version=${{ steps.get_version.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.title=NodePassDash
org.opencontainers.image.description=NodePassDash - 隧道管理面板
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}
- name: 🏗️ 构建和推送 Docker 镜像
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILDKIT_INLINE_CACHE=1
VERSION=${{ steps.get_version.outputs.version }}
# 明确指定支持的架构,避免unknown/unknown
platforms: linux/amd64,linux/arm64
# 启用构建缓存以提高速度
cache-from: type=gha
cache-to: type=gha,mode=max
# 确保只推送指定平台的镜像
provenance: false
sbom: false
- name: 🧹 清理构建缓存(避免unknown平台)
if: always()
run: |
echo "🧹 清理可能的无效构建缓存..."
docker buildx prune -f --filter until=1h
echo "✅ 缓存清理完成"
- name: 📢 输出版本信息
run: |
echo "🏷️ 版本: ${{ steps.get_version.outputs.version }}"
echo "🎯 触发方式: ${{ github.ref }}"
echo ""
echo "📦 生成的镜像标签:"
echo "${{ steps.meta.outputs.tags }}" | sed 's/^/ - /'
echo ""
echo "🏗️ 构建架构: linux/amd64, linux/arm64"
echo ""
echo "💡 标签说明:"
echo " ✅ 正式发布版本"
echo " 📦 标签: latest + ${{ steps.get_version.outputs.version }}"
echo " 🚀 推荐使用: docker pull ghcr.io/${{ steps.get_version.outputs.repo_name }}:latest"