-
Notifications
You must be signed in to change notification settings - Fork 173
69 lines (60 loc) · 1.82 KB
/
docker-publish.yml
File metadata and controls
69 lines (60 loc) · 1.82 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
name: Manual Docker Build
# 核心配置:仅允许手动触发
on:
workflow_dispatch:
inputs:
reason:
description: '构建原因'
required: false
default: 'Manual build update'
env:
IMAGE_NAME: foxhui/webai-2api
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# 1. 拉取代码
- name: Checkout repository
uses: actions/checkout@v4
# 2. 设置 QEMU (支持多架构构建,如 ARM64)
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# 3. 设置 Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 4. 登录 Docker Hub
- name: Log into Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# 5. 生成 Docker 标签
# 逻辑:
# - 总是打上 'latest' 标签
# - 额外打上 'sha-xxxxxxx' (基于当前 commit 的哈希)
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=sha,format=short
# 6. 构建并推送
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
# 开启推送
push: true
# 使用上面生成的标签
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# 缓存加速
cache-from: type=gha
cache-to: type=gha,mode=max
# 同时构建 PC (amd64) 和 Mac/树莓派 (arm64) 版本
platforms: linux/amd64,linux/arm64