-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (146 loc) · 4.8 KB
/
Copy pathcd.yml
File metadata and controls
175 lines (146 loc) · 4.8 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
name: 企业级 CD
on:
push:
branches: ["main", "master"]
tags: ["v*.*.*"]
workflow_dispatch:
concurrency:
group: cd-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
packages: write
id-token: write
security-events: write
env:
REGISTRY: ghcr.io
BACKEND_IMAGE: ghcr.io/${{ github.repository }}-backend
FRONTEND_IMAGE: ghcr.io/${{ github.repository }}-frontend
jobs:
backend-gate:
name: 发布前后端门禁(后端)
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: 配置 JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
cache: maven
- name: 执行后端测试
run: ./mvnw -B -ntp clean verify
frontend-gate:
name: 发布前后端门禁(前端)
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
defaults:
run:
working-directory: frontend
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: 配置 Node.js 20
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: 安装依赖
run: npm ci
- name: 构建前端
run: npm run build
publish-backend:
name: 发布后端镜像
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
needs: [backend-gate, frontend-gate]
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 登录 GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 生成镜像元数据
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.BACKEND_IMAGE }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: 构建并推送后端镜像
uses: docker/build-push-action@v6
with:
context: .
file: docker/backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: true
sbom: true
- name: Trivy 扫描后端镜像配置
uses: aquasecurity/trivy-action@0.28.0
with:
scan-type: config
format: sarif
output: trivy-backend.sarif
- name: 上传后端 SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy-backend.sarif
publish-frontend:
name: 发布前端镜像
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
needs: [backend-gate, frontend-gate]
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 登录 GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 生成镜像元数据
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.FRONTEND_IMAGE }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: 构建并推送前端镜像
uses: docker/build-push-action@v6
with:
context: .
file: docker/frontend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: true
sbom: true
- name: Trivy 扫描前端镜像配置
uses: aquasecurity/trivy-action@0.28.0
with:
scan-type: config
format: sarif
output: trivy-frontend.sarif
- name: 上传前端 SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy-frontend.sarif