Files
perler-lab/.gitea/workflows/deploy-prod.yml
T

74 lines
3.1 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.
# =============================================================================
# PERLER LAB 拼豆图纸库 —— Gitea Actions 生产环境流水线
# 触发:手动 workflow_dispatch + confirm=yes
# 流程:本机构建镜像 → 部署到 prod(runner=hostexecutor 直接本机执行)→
# 成功后清理 test 环境(test2)
# =============================================================================
name: deploy-perler-lab-prod
on:
workflow_dispatch:
inputs:
confirm:
description: '确认部署拼豆到生产环境? 输入 yes'
required: true
default: 'no'
jobs:
deploy-prod:
runs-on: ubuntu-latest
if: github.event.inputs.confirm == 'yes'
steps:
- name: Checkout
uses: actions/checkout@v4
# runner 为 hostexecutor 模式跑在 prod 宿主机(156.233.226.46)上,
# 直接本机执行 docker 命令,不要 SSH 到自己。
- name: Build backend image
run: |
cd perler-lab-server
docker build -t perler-lab-server:latest .
echo "后端镜像构建完成"
- name: Build frontend image
run: |
cd perler-lab
docker build -t perler-lab-frontend:latest .
echo "前端镜像构建完成"
- name: Deploy to prod
run: |
set -e
docker stop perler-lab-server perler-lab-frontend 2>/dev/null || true
docker rm perler-lab-server perler-lab-frontend 2>/dev/null || true
docker network create perler-net 2>/dev/null || true
docker run -d --name perler-lab-server \
--restart unless-stopped \
--network perler-net \
--network-alias server \
-e PORT=8788 \
-e DATABASE_URL='postgres://pgsql:XGYnJPysCNJsLeea@postgres:5432/perler_lab' \
-p 8788:8788 \
perler-lab-server:latest
# 后端需连 prod 主库(middleware-postgres),接入 middleware 网络以解析 postgres 别名
docker network connect middleware perler-lab-server
docker run -d --name perler-lab-frontend \
--restart unless-stopped \
--network perler-net \
-p 8080:80 \
perler-lab-frontend:latest
echo '容器已启动,等待健康检查...'
sleep 12
echo '--- 后端健康检查 ---'
curl -sf http://localhost:8788/health && echo '后端 OK'
echo '--- 前端健康检查 ---'
curl -s -o /dev/null -w '前端 HTTP %{http_code}\n' http://localhost:8080/ || echo '前端未就绪'
echo '? 生产部署完成'
# 版本已上生产,清理 test2 环境对应版本(新规则)
- name: Cleanup test2 env (version now in production)
run: |
ssh -o StrictHostKeyChecking=no -p 47222 root@171.80.10.85 "
docker stop perler-lab-server perler-lab-frontend 2>/dev/null && docker rm perler-lab-server perler-lab-frontend 2>/dev/null && echo '? test1 容器已清理(版本已上生产)' || echo '?? test1 清理失败或已不存在'
"
continue-on-error: true