Files
light/.gitea/workflows/deploy.yml
Doubleyin aa3c1b8590
Some checks failed
构建并部署 Spring Boot 应用 / build-and-deploy (push) Failing after 14s
更新工作流以使用SSH密钥部署
2025-09-26 01:42:49 +08:00

51 lines
1.6 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: 构建并部署 Spring Boot 应用
on: [push]
jobs:
build-and-deploy:
runs-on: ubuntu-24.04
steps:
# 步骤1获取最新的代码
- name: 检出代码
uses: actions/checkout@v4
# 步骤2设置 Java 环境
- name: 设置 JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# 步骤3使用 Maven 打包应用
- name: 使用 Maven 打包
run: mvn clean package -DskipTests
# 步骤4构建 Docker 镜像
- name: 构建 Docker 镜像
run: |
docker build -t light-delivery-app:latest .
# 步骤5部署到应用服务器
- name: 部署到服务器
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
# 配置SSH环境
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
echo -e "Host *\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
# 部署到服务器
ssh -i ~/.ssh/deploy_key root@115.190.121.151 '
echo "🚀 开始部署应用..."
docker rm -f light-delivery-container || true
docker run -d \
--name light-delivery-container \
-p 443:443 \
-p 80:80 \
-v /etc/ssl/certs:/etc/ssl/certs \
-e KEY_STORE_PASSWORD="$(cat /etc/ssl/certs/keyStorePass.txt)" \
light-delivery-app:latest
echo "✅ 部署完成!"
'