Files
rent/.gitea/workflows/deploy.yml
T
xiaoquan 147a25614f fix: 使用包含 Docker 的容器镜像运行 CI/CD
## 修改内容
- 添加 container 配置
- 使用 catthehacker/ubuntu:act-latest 镜像
- 该镜像预装了 docker、docker-compose 等工具

## 优点
- 不需要在 Runner 容器中安装工具
- 使用标准的 GitHub Actions 兼容镜像
- 更稳定可靠

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-10 19:02:57 +08:00

84 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.
name: Deploy
on:
push:
branches:
- prod
- test
env:
NODE_ENV: production
jobs:
deploy:
runs-on: [self-hosted, rent-deploy]
container:
image: catthehacker/ubuntu:act-latest
options: --privileged -v /var/run/docker.sock:/var/run/docker.sock
steps:
- name: Clone or update code
run: |
WORK_DIR="/workspace/rent-deploy"
REPO_URL="https://gitea.pinzhuhui.com/xiaoquan/rent.git"
echo "准备代码..."
if [ -d "$WORK_DIR/.git" ]; then
echo "代码目录已存在,更新代码..."
cd $WORK_DIR
git fetch origin
git checkout ${{ github.ref_name }}
git pull origin ${{ github.ref_name }}
else
echo "首次克隆代码..."
git clone $REPO_URL $WORK_DIR
cd $WORK_DIR
git checkout ${{ github.ref_name }}
fi
echo "✅ 代码准备完成"
echo "当前分支: $(git branch --show-current)"
echo "最新提交: $(git log -1 --oneline)"
- name: Deploy to test
if: github.ref == 'refs/heads/test'
run: |
echo "部署到测试环境..."
cd /workspace/rent-deploy/deploy/docker
export TEST_DB_PASSWORD="${{ secrets.TEST_DB_PASSWORD }}"
export TEST_JWT_SECRET="${{ secrets.TEST_JWT_SECRET }}"
export ENCRYPTION_KEY="${{ secrets.ENCRYPTION_KEY }}"
# 使用 docker composeV2 版本,空格分隔)
docker compose -f docker-compose.test.yml down --remove-orphans || docker-compose -f docker-compose.test.yml down --remove-orphans
docker compose -f docker-compose.test.yml build --parallel || docker-compose -f docker-compose.test.yml build --parallel
docker compose -f docker-compose.test.yml up -d || docker-compose -f docker-compose.test.yml up -d
docker image prune -f
echo "等待服务启动..."
sleep 10
docker compose -f docker-compose.test.yml ps || docker-compose -f docker-compose.test.yml ps
echo "✅ 测试环境部署完成"
- name: Deploy to production
if: github.ref == 'refs/heads/prod'
run: |
echo "部署到生产环境..."
cd /workspace/rent-deploy/deploy/docker
export PROD_DB_PASSWORD="${{ secrets.PROD_DB_PASSWORD }}"
export PROD_JWT_SECRET="${{ secrets.PROD_JWT_SECRET }}"
export ENCRYPTION_KEY="${{ secrets.ENCRYPTION_KEY }}"
# 使用 docker composeV2 版本,空格分隔)
docker compose -f docker-compose.prod.yml down --remove-orphans || docker-compose -f docker-compose.prod.yml down --remove-orphans
docker compose -f docker-compose.prod.yml build --parallel || docker-compose -f docker-compose.prod.yml build --parallel
docker compose -f docker-compose.prod.yml up -d || docker-compose -f docker-compose.prod.yml up -d
docker image prune -f
echo "等待服务启动..."
sleep 10
docker compose -f docker-compose.prod.yml ps || docker-compose -f docker-compose.prod.yml ps
echo "✅ 生产环境部署完成"