-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (176 loc) · 7.86 KB
/
build-yunyu-web-image.yml
File metadata and controls
201 lines (176 loc) · 7.86 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Build Yunyu Web Image
on:
push:
branches:
- main
paths:
- "yunyu-web/**"
- "docker/frontend/**"
- ".dockerignore"
- ".github/workflows/build-yunyu-web-image.yml"
workflow_dispatch:
env:
REGISTRY: ghcr.io
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
build-amd64:
name: Build amd64 Web Image
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare image name
id: image
run: |
echo "name=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')/yunyu-web" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}
tags: |
type=sha
- name: Build and push amd64 web image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/frontend/Dockerfile
push: true
platforms: linux/amd64
tags: |
${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:latest-amd64
${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:sha-${{ github.sha }}-amd64
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=web-amd64
cache-to: type=gha,mode=max,scope=web-amd64
- name: Output amd64 image summary
run: |
echo "## Yunyu Web amd64 镜像构建结果" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "- 构建分支:\`${{ github.ref_name }}\`" >> "$GITHUB_STEP_SUMMARY"
echo "- 镜像仓库:\`${{ env.REGISTRY }}/${{ steps.image.outputs.name }}\`" >> "$GITHUB_STEP_SUMMARY"
echo "- 构建平台:\`linux/amd64\`" >> "$GITHUB_STEP_SUMMARY"
echo "- Dockerfile:\`docker/frontend/Dockerfile\`" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "### 实际生成的架构镜像标签" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "- \`${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:latest-amd64\`" >> "$GITHUB_STEP_SUMMARY"
echo "- \`${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:sha-${{ github.sha }}-amd64\`" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "### 拉取命令示例" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "\`\`\`bash" >> "$GITHUB_STEP_SUMMARY"
echo "docker pull ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:latest-amd64" >> "$GITHUB_STEP_SUMMARY"
echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY"
build-arm64:
name: Build arm64 Web Image
runs-on: ubuntu-24.04-arm
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare image name
id: image
run: |
echo "name=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')/yunyu-web" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}
tags: |
type=sha
- name: Build and push arm64 web image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/frontend/Dockerfile
push: true
platforms: linux/arm64
tags: |
${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:latest-arm64
${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:sha-${{ github.sha }}-arm64
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=web-arm64
cache-to: type=gha,mode=max,scope=web-arm64
- name: Output arm64 image summary
run: |
echo "## Yunyu Web arm64 镜像构建结果" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "- 构建分支:\`${{ github.ref_name }}\`" >> "$GITHUB_STEP_SUMMARY"
echo "- 镜像仓库:\`${{ env.REGISTRY }}/${{ steps.image.outputs.name }}\`" >> "$GITHUB_STEP_SUMMARY"
echo "- 构建平台:\`linux/arm64\`" >> "$GITHUB_STEP_SUMMARY"
echo "- Dockerfile:\`docker/frontend/Dockerfile\`" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "### 实际生成的架构镜像标签" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "- \`${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:latest-arm64\`" >> "$GITHUB_STEP_SUMMARY"
echo "- \`${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:sha-${{ github.sha }}-arm64\`" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "### 拉取命令示例" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "\`\`\`bash" >> "$GITHUB_STEP_SUMMARY"
echo "docker pull ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:latest-arm64" >> "$GITHUB_STEP_SUMMARY"
echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY"
merge-manifest:
name: Merge Multi-Arch Manifest
runs-on: ubuntu-24.04
needs:
- build-amd64
- build-arm64
permissions:
contents: read
packages: write
steps:
- name: Prepare image name
id: image
run: |
echo "name=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')/yunyu-web" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push multi-arch manifest
run: |
docker buildx imagetools create \
--tag ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:latest \
--tag ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:sha-${{ github.sha }} \
${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:sha-${{ github.sha }}-amd64 \
${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:sha-${{ github.sha }}-arm64
- name: Inspect multi-arch manifest
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:latest
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:sha-${{ github.sha }}
- name: Output manifest summary
run: |
echo "## Yunyu Web 多架构 Manifest 合并结果" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "- 构建分支:\`${{ github.ref_name }}\`" >> "$GITHUB_STEP_SUMMARY"
echo "- 最终标签:\`${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:latest\`" >> "$GITHUB_STEP_SUMMARY"
echo "- 最终标签:\`${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:sha-${{ github.sha }}\`" >> "$GITHUB_STEP_SUMMARY"
echo "- 包含架构:\`linux/amd64\`、\`linux/arm64\`" >> "$GITHUB_STEP_SUMMARY"