Files
light/.gitea/workflows/deploy.yml
Doubleyin 6a826e565d
Some checks failed
构建并部署 Spring Boot 应用 / build-and-deploy (push) Failing after 3m28s
fix: 添加 Node.js 设置步骤以解决 PATH 问题
2025-09-26 01:51:56 +08:00

57 lines
1.8 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:
# --- 新增的关键步骤 ---
- name: 为 Gitea Actions 设置 Node.js 环境
uses: actions/setup-node@v4
with:
node-version: '20' # 选择一个稳定的 LTS 版本,如 18 或 20
cache: 'npm' # 可选:缓存依赖以加速后续运行
# 步骤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 "✅ 部署完成!"
'