From c207a202b86dc2978826a75df6120ef793830213 Mon Sep 17 00:00:00 2001 From: huertian Date: Wed, 8 Jan 2025 18:30:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95Actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yml | 49 +++++++++++++++++++++++++++++++++++++ .gitignore | 3 +++ 2 files changed, 52 insertions(+) create mode 100644 .gitea/workflows/deploy.yml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..1b40891 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -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 diff --git a/.gitignore b/.gitignore index 549e00a..cf1c9c8 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ build/ ### VS Code ### .vscode/ + +# 忽略 .DS_Store 文件 +.DS_Store \ No newline at end of file