Skip to content

Commit b802f31

Browse files
authored
Merge pull request #11 from yyyCode/dev
2 parents 13203e1 + 51a58ff commit b802f31

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# OpenBlog:push 到 master 时编译后端、打包前端,并将静态资源与 Docker 相关文件同步到阿里云,在服务器执行 docker.sh 更新 Nginx 容器。
2+
# 后端部署到内网自托管 Runner。
3+
#
24
# 需在仓库 Settings → Secrets and variables → Actions 中配置:
35
# SERVER_SSH_KEY 服务器 SSH 私钥(完整 PEM)
46
# SERVER_REMOTE_HOST 公网 IP 或域名
@@ -61,6 +63,60 @@ jobs:
6163
- name: Build backend (Maven)
6264
run: mvn -B -ntp package -DskipTests -pl OpenBlog-business -am
6365

66+
- name: Upload backend JAR
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: backend-jar
70+
path: OpenBlog-business/target/OpenBlog-business-*.jar
71+
retention-days: 1
72+
73+
deploy-backend:
74+
needs: build-backend
75+
if: ${{ needs.build-backend.result == 'success' }}
76+
runs-on: openblog-backend
77+
78+
steps:
79+
- name: Download backend JAR
80+
uses: actions/download-artifact@v4
81+
with:
82+
name: backend-jar
83+
84+
- name: Deploy to internal server
85+
run: |
86+
JAR_FILE=$(ls OpenBlog-business-*.jar | head -1)
87+
TARGET_DIR="/www/wwwroot/java/openblog"
88+
TARGET_JAR="$TARGET_DIR/OpenBlog-business-1.0.0-SNAPSHOT.jar"
89+
JAVA_HOME="/www/server/java/jdk-17.0.8"
90+
91+
# 停止旧进程
92+
OLD_PID=$(ps aux | grep 'OpenBlog-business' | grep -v grep | awk '{print $2}')
93+
if [ -n "$OLD_PID" ]; then
94+
echo "Stopping old process (PID: $OLD_PID)..."
95+
kill $OLD_PID
96+
sleep 5
97+
# 如果还没停,强制 kill
98+
if kill -0 $OLD_PID 2>/dev/null; then
99+
kill -9 $OLD_PID
100+
sleep 2
101+
fi
102+
fi
103+
104+
# 备份旧 jar
105+
if [ -f "$TARGET_JAR" ]; then
106+
cp "$TARGET_JAR" "$TARGET_DIR/backup/OpenBlog-business-$(date +%Y%m%d-%H%M%S).jar" 2>/dev/null || true
107+
fi
108+
109+
# 复制新 jar
110+
mkdir -p "$TARGET_DIR/backup"
111+
cp "$JAR_FILE" "$TARGET_JAR"
112+
113+
# 启动新进程
114+
cd "$TARGET_DIR"
115+
nohup $JAVA_HOME/bin/java -jar -Xmx1024M -Xms256M "$TARGET_JAR" > app.log 2>&1 &
116+
117+
echo "Deployed $JAR_FILE → $TARGET_JAR"
118+
echo "New PID: $!"
119+
64120
build-frontend:
65121
needs: changes
66122
if: ${{ needs.changes.outputs.frontend == 'true' }}

0 commit comments

Comments
 (0)