Spaces:
Running
Running
github-actions[bot]
commited on
Commit
·
57e6cdf
1
Parent(s):
b51f54a
Update from GitHub Actions
Browse files
.cnb.yml
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
main:
|
2 |
+
push:
|
3 |
+
- docker:
|
4 |
+
image: node:18
|
5 |
+
imports: https://cnb.cool/godgodgame/oci-private-key/-/blob/main/envs.yml
|
6 |
+
stages:
|
7 |
+
- name: 环境检查
|
8 |
+
script: echo $GITHUB_TOKEN_GK && echo $GITHUB_TOKEN && node -v && npm -v
|
9 |
+
- name: 构建并打包
|
10 |
+
script: |
|
11 |
+
mkdir archive
|
12 |
+
tar --exclude='./archive' --exclude='.git' -zcvf archive/release.tar.gz .
|
13 |
+
- name: ansible发布
|
14 |
+
image: plugins/ansible
|
15 |
+
settings:
|
16 |
+
private_key: $SERVER_PRIVATE_KEY
|
17 |
+
inventory: hosts
|
18 |
+
playbook: playbook.yml
|
19 |
+
|
.env
CHANGED
@@ -1 +1,2 @@
|
|
|
|
1 |
API_KEYS={}
|
|
|
1 |
+
PORT=7860
|
2 |
API_KEYS={}
|
hosts
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# hosts
|
2 |
+
# 这里填写主机分组名
|
3 |
+
[hostgroup]
|
4 |
+
# 这里填写部署主机的ip
|
5 |
+
8.130.88.130
|
playbook.yml
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
- name: My first play
|
2 |
+
hosts: hostgroup
|
3 |
+
remote_user: root
|
4 |
+
vars:
|
5 |
+
app_name: cursor2api
|
6 |
+
app_port: 7860
|
7 |
+
deploy_path: /root/workspace/cursor2api
|
8 |
+
|
9 |
+
tasks:
|
10 |
+
- name: 停止特定应用服务
|
11 |
+
shell: |
|
12 |
+
pid=$(ps -ef | grep "npm run start" | grep "{{ app_port }}" | grep -v grep | awk '{print $2}')
|
13 |
+
if [ -n "$pid" ]; then
|
14 |
+
echo "Stopping {{ app_name }} process with PID: $pid"
|
15 |
+
kill -15 $pid
|
16 |
+
sleep 3
|
17 |
+
if ps -p $pid > /dev/null 2>&1; then
|
18 |
+
echo "Force killing process with PID: $pid"
|
19 |
+
kill -9 $pid
|
20 |
+
fi
|
21 |
+
else
|
22 |
+
echo "No running {{ app_name }} process found"
|
23 |
+
fi
|
24 |
+
args:
|
25 |
+
executable: /bin/bash
|
26 |
+
ignore_errors: yes
|
27 |
+
|
28 |
+
- name: 确认服务已停止
|
29 |
+
wait_for:
|
30 |
+
port: "{{ app_port }}"
|
31 |
+
state: stopped
|
32 |
+
timeout: 30
|
33 |
+
|
34 |
+
- name: 复制到远程服务器
|
35 |
+
copy:
|
36 |
+
src: archive/release.tar.gz
|
37 |
+
dest: /root/deploy/{{ app_name }}.tar.gz
|
38 |
+
|
39 |
+
- name: 解压文件
|
40 |
+
shell: |
|
41 |
+
rm -rf {{ deploy_path }}
|
42 |
+
mkdir -p {{ deploy_path }}
|
43 |
+
tar -zxvf /root/deploy/{{ app_name }}.tar.gz -C {{ deploy_path }}
|
44 |
+
args:
|
45 |
+
executable: /bin/bash
|
46 |
+
|
47 |
+
- name: 构建并运行
|
48 |
+
shell: |
|
49 |
+
cd {{ deploy_path }}
|
50 |
+
pip install --no-cache-dir -r requirements.txt
|
51 |
+
echo '#!/bin/bash
|
52 |
+
cd {{ deploy_path }}
|
53 |
+
test -f $HOME/.nvm/nvm.sh && source $HOME/.nvm/nvm.sh
|
54 |
+
exec npm run start
|
55 |
+
' > {{ deploy_path }}/start.sh
|
56 |
+
chmod +x {{ deploy_path }}/start.sh
|
57 |
+
nohup {{ deploy_path }}/start.sh > {{ deploy_path }}/nohup.log 2>&1 &
|
58 |
+
args:
|
59 |
+
executable: /bin/bash
|
60 |
+
|
61 |
+
- name: 等待服务启动
|
62 |
+
wait_for:
|
63 |
+
port: "{{ app_port }}"
|
64 |
+
timeout: 30
|