-
Notifications
You must be signed in to change notification settings - Fork 27
138 lines (127 loc) · 4.6 KB
/
Copy pathdeploy.yaml
File metadata and controls
138 lines (127 loc) · 4.6 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
name: Deploy to Cloud Server
on:
workflow_dispatch: # 手动触发
inputs:
api:
description: 'Deploy api'
required: false
type: boolean
default: false
user:
description: 'Deploy user'
required: false
type: boolean
default: false
classroom:
description: 'Deploy classroom'
required: false
type: boolean
default: false
course:
description: 'Deploy course'
required: false
type: boolean
default: false
launch_screen:
description: 'Deploy launch_screen'
required: false
type: boolean
default: false
paper:
description: 'Deploy paper'
required: false
type: boolean
default: false
academic:
description: 'Deploy academic'
required: false
type: boolean
default: false
version:
description: 'Deploy version'
required: false
type: boolean
default: false
common:
description: 'Deploy common'
required: false
type: boolean
default: false
oa:
description: 'Deploy oa'
required: false
type: boolean
default: false
captcha:
description: 'Deploy captcha'
required: false
type: boolean
default: false
permissions:
contents: read
jobs:
setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
services='[]'
[ "${{ github.event.inputs.api }}" = "true" ] && services=$(echo $services | jq -c '. += ["api"]')
[ "${{ github.event.inputs.user }}" = "true" ] && services=$(echo $services | jq -c '. += ["user"]')
[ "${{ github.event.inputs.classroom }}" = "true" ] && services=$(echo $services | jq -c '. += ["classroom"]')
[ "${{ github.event.inputs.course }}" = "true" ] && services=$(echo $services | jq -c '. += ["course"]')
[ "${{ github.event.inputs.launch_screen }}" = "true" ] && services=$(echo $services | jq -c '. += ["launch_screen"]')
[ "${{ github.event.inputs.paper }}" = "true" ] && services=$(echo $services | jq -c '. += ["paper"]')
[ "${{ github.event.inputs.academic }}" = "true" ] && services=$(echo $services | jq -c '. += ["academic"]')
[ "${{ github.event.inputs.version }}" = "true" ] && services=$(echo $services | jq -c '. += ["version"]')
[ "${{ github.event.inputs.common }}" = "true" ] && services=$(echo $services | jq -c '. += ["common"]')
[ "${{ github.event.inputs.oa }}" = "true" ] && services=$(echo $services | jq -c '. += ["oa"]')
[ "${{ github.event.inputs.captcha }}" = "true" ] && services=$(echo $services | jq -c '. += ["captcha"]')
echo "matrix={\"service\":$(echo $services | jq -c .)}" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: setup
if: ${{ needs.setup.outputs.matrix != '{"service":[]}' }}
strategy:
matrix:
service: ${{ fromJson(needs.setup.outputs.matrix).service }}
max-parallel: 1 # 串行执行,见Makefile:149
steps:
- name: Check out the code
uses: actions/checkout@v7
- name: Log in to Alibaba Cloud Docker Registry
uses: docker/login-action@v4
with:
registry: ${{ secrets.ALIYUN_DOCKER_REGISTRY }}
username: ${{ secrets.ALIYUN_DOCKER_USER }}
password: ${{ secrets.ALIYUN_DOCKER_PASSWORD }}
- name: Build and Push Docker Image
run: |
cd $GITHUB_WORKSPACE && bash ./hack/image-build-and-push.sh ${{ matrix.service }}
deploy:
runs-on: ubuntu-latest
needs: [build, setup] # 确保在 build 和 setup 作业完成后再执行
if: ${{ needs.setup.outputs.matrix != '{"service":[]}' }}
concurrency:
group: global-deployment-workflow
cancel-in-progress: false # 后续的 workflow 处于 pending
steps:
- name: SSH and deploy on server
uses: appleboy/ssh-action@v1.2.5
env:
SERVICES: ${{ needs.setup.outputs.matrix }}
with:
port: ${{ secrets.SERVER_PORT }}
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
envs: SERVICES
script: |
# 解析 JSON 并提取 service 数组
services=$(echo "$SERVICES" | jq -r '.service[]')
for service in $services; do
cd /home/srv/hack
bash docker-run.sh $service
done