更新 .gitea/workflows/deploy.yml
Some checks failed
构建并部署 Spring Boot 应用 / build-and-deploy (push) Failing after 0s

gitea
This commit is contained in:
2025-09-26 05:41:05 +00:00
parent 88a2b3f799
commit c2a2d57161

View File

@@ -5,29 +5,29 @@ jobs:
build-and-deploy:
runs-on: ubuntu-24.04
steps:
# 1. 检出代码 - 使用完整的GitHub URL
# 1. 检出代码 - 使用 Gitea.com 的镜像
- name: 检出代码
uses: https://gitea.com/actions/checkout
uses: https://gitea.com/actions/checkout # 使用完整 URL:cite[3]:cite[9]
with:
fetch-depth: 1
# 2. 设置 Java 环境 - 使用完整的GitHub URL
# 2. 设置 Java 环境 - 使用 Gitea.com 的镜像
- name: 设置 JDK 17
uses: https://gitea.com/actions/setup-java
uses: https://gitea.com/actions/setup-java # 使用完整 URL:cite[3]:cite[9]
with:
java-version: '17'
distribution: 'temurin'
# 3. 设置 Node.js 环境 - 使用完整的GitHub URL
# 3. 设置 Node.js 环境 - 使用 Gitea.com 的镜像
- name: 设置 Node.js 环境
uses: https://gitea.com/actions/setup-node
uses: https://gitea.com/actions/setup-node # 使用完整 URL:cite[3]:cite[9]
with:
node-version: '20'
cache: 'npm'
# 4. 缓存 Maven 依赖项 - 使用完整的GitHub URL
# 4. 缓存 Maven 依赖项 - 使用 Gitea.com 的镜像
- name: 缓存 Maven 依赖
uses: https://gitea.com/actions/cache
uses: https://gitea.com/actions/cache # 使用完整 URL:cite[3]:cite[9]
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
@@ -44,48 +44,21 @@ jobs:
docker build -t light-delivery-app:latest .
docker images
# 7. 登录到 Docker Registry如果需要推送到镜像仓库
# - name: 登录到 Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
# 8. 推送 Docker 镜像(可选)
# - name: 推送 Docker 镜像
# run: |
# docker tag light-delivery-app:latest yourusername/light-delivery-app:latest
# docker push yourusername/light-delivery-app:latest
# 9. 部署到服务器
# 7. 部署到服务器
- name: 部署到服务器
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_IP: ${{ secrets.SERVER_IP }} # 建议将IP地址也存储在secrets中
SERVER_IP: ${{ secrets.SERVER_IP }}
run: |
# 设置SSH
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
# 禁用主机密钥检查(生产环境应谨慎使用)
echo -e "Host *\n\tStrictHostKeyChecking no\n\tUserKnownHostsFile /dev/null" > ~/.ssh/config
# 传输Docker镜像到服务器如果需要
# docker save light-delivery-app:latest | ssh -i ~/.ssh/deploy_key root@$SERVER_IP 'docker load'
# 在服务器上执行部署命令
ssh -i ~/.ssh/deploy_key root@$SERVER_IP '
echo "开始部署应用..."
# 停止并删除现有容器
docker stop light-delivery-container || true
docker rm light-delivery-container || true
# 拉取最新镜像(如果使用了镜像仓库)
# docker pull yourusername/light-delivery-app:latest
# 运行新容器
docker run -d \
--name light-delivery-container \
--restart unless-stopped \
@@ -98,11 +71,10 @@ jobs:
echo "部署完成,清理旧镜像..."
docker image prune -f
'
echo "✅ 应用部署成功!"
# 10. 健康检查(可选)
# 8. 健康检查(可选)
- name: 健康检查
run: |
sleep 30 # 等待应用启动
curl -f http://${{ secrets.SERVER_IP }}/api/health || echo "健康检查失败,但继续流程"
sleep 30
curl -f http://$SERVER_IP/api/health || echo "健康检查失败,但继续流程"