forked from ljxi/NetworkPanel
-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (82 loc) · 2.46 KB
/
docker-build-push.yml
File metadata and controls
95 lines (82 loc) · 2.46 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
name: Build and Push Docker Image
# 触发条件
on:
# 当推送到 main 分支时触发
push:
branches:
- main
- master
# 当创建标签时触发
tag:
- 'v*'
# 允许手动触发
workflow_dispatch:
# 环境变量
env:
REGISTRY: docker.io
IMAGE_NAME: network-panel
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# 检出代码
- name: Checkout code
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 10
run_install: false
# 安装依赖
- name: Install dependencies
run: pnpm install --frozen-lockfile
# 构建项目
- name: Build project
run: pnpm run build
# 部署到 GitHub Pages
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
# 可选:自定义域名文件
# cname: your-domain.com
# 设置 Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 登录到 Docker Hub
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# 提取元数据(标签、标签等)
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}
tags: |
# 为分支创建标签
type=ref,event=branch
# 为标签创建版本标签
type=ref,event=tag
# 为主分支创建 latest 标签
type=raw,value=latest,enable={{is_default_branch}}
# # 使用 Git SHA 创建标签
# type=sha,prefix={{branch}}-
# 构建并推送 Docker 镜像
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# 输出镜像摘要
- name: Image digest
run: echo ${{ steps.build.outputs.digest }}