This commit is contained in:
parent
4f645c6e78
commit
c207a202b8
49
.gitea/workflows/deploy.yml
Normal file
49
.gitea/workflows/deploy.yml
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
name: 自动部署 Spring Boot 项目到 CentOS 🚀
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main # 当代码推送到 main 分支时触发部署
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# 1️⃣ 检出代码
|
||||||
|
- name: 🛠️ 检出代码
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# 2️⃣ 设置 Java 环境
|
||||||
|
- name: ☕ 设置 Java 环境
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
java-version: "17" # 替换为您的 Java 版本
|
||||||
|
distribution: "temurin"
|
||||||
|
|
||||||
|
# 3️⃣ 构建 Spring Boot 项目
|
||||||
|
- name: 📦 构建 Spring Boot 项目
|
||||||
|
run: |
|
||||||
|
./mvnw clean package -DskipTests
|
||||||
|
ls target/*.jar
|
||||||
|
|
||||||
|
# 4️⃣ 部署到服务器
|
||||||
|
- name: 🚀 部署到服务器
|
||||||
|
env:
|
||||||
|
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} # SSH 私钥
|
||||||
|
run: |
|
||||||
|
# 配置 SSH 🔑
|
||||||
|
echo "$DEPLOY_KEY" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
ssh-keyscan -H $server_ip >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
# 上传 JAR 包到服务器 📤
|
||||||
|
scp target/*.jar $user@$server_ip:/jinduguanli/app.jar
|
||||||
|
|
||||||
|
# 在服务器上重启应用 🔄
|
||||||
|
ssh $user@$server_ip << 'EOF'
|
||||||
|
cd /jinduguanli
|
||||||
|
pkill -f 'java -jar' || true
|
||||||
|
nohup java -jar app.jar --spring.config.location=/huertian/application.yml> /huertian/log/app.log 2>&1 &
|
||||||
|
exit
|
||||||
|
EOF
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -31,3 +31,6 @@ build/
|
|||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
# 忽略 .DS_Store 文件
|
||||||
|
.DS_Store
|
Loading…
Reference in New Issue
Block a user