Files
one-pipe-system/.gitea/workflows/deploy.yaml
luo 9a3a764120
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 35m56s
fix: git branch
2026-09-17 14:35:31 +08:00

123 lines
3.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: 构建并部署前端到测试环境
on:
push:
branches:
- main
- dev
- test
- iteration/august
env:
REGISTRY: registry.boss160.cn
IMAGE_NAME: registry.boss160.cn/junhong/cmp-admin-web
DEPLOY_DIR: /opt/junhong_cmp_web
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: 检出代码
run: |
export PATH="$HOME/.nix-profile/bin:/usr/local/bin:/usr/bin:/bin:$PATH"
export GIT_SSL_NO_VERIFY=1
git clone https://git.boss160.cn/luo/one-pipe-system.git .
git checkout ${{ github.sha }}
- name: 设置镜像标签
id: tag
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "tag=latest" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/dev" ]; then
echo "tag=dev" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/test" ]; then
echo "tag=test" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/iteration/august" ]; then
echo "tag=test" >> $GITHUB_OUTPUT
else
echo "tag=unknown" >> $GITHUB_OUTPUT
fi
- name: 登录 Docker Registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login "${{ env.REGISTRY }}" \
--username "${{ secrets.REGISTRY_USERNAME }}" \
--password-stdin
- name: 构建前端镜像
run: |
docker build -t ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }} .
docker tag ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }} \
${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: 推送镜像到 Registry
run: |
docker push ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }}
docker push ${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: 部署到测试环境iteration/august
if: github.ref == 'refs/heads/iteration/august'
run: |
# 确保部署目录存在
mkdir -p ${{ env.DEPLOY_DIR }}
echo "当前工作目录: $(pwd)"
echo "当前目录内容:"
ls -la
# 更新 docker-compose.prod.yml
echo "更新部署配置文件..."
cp -v docker-compose.prod.yml ${{ env.DEPLOY_DIR }}/
cd ${{ env.DEPLOY_DIR }}
echo "拉取最新镜像..."
docker compose -f docker-compose.prod.yml pull
echo "重启服务..."
docker compose -f docker-compose.prod.yml up -d
echo "等待服务启动..."
sleep 5
echo "部署完成!"
docker compose -f docker-compose.prod.yml ps
- name: 部署到生产环境main
if: github.ref == 'refs/heads/main'
run: |
mkdir -p ${{ env.DEPLOY_DIR }}
echo "当前工作目录: $(pwd)"
echo "当前目录内容:"
ls -la
echo "更新部署配置文件..."
cp -v docker-compose.prod.yml ${{ env.DEPLOY_DIR }}/
cd ${{ env.DEPLOY_DIR }}
echo "拉取最新镜像..."
docker compose -f docker-compose.prod.yml pull
echo "重启服务..."
docker compose -f docker-compose.prod.yml up -d
echo "等待服务启动..."
sleep 5
echo "部署完成!"
docker compose -f docker-compose.prod.yml ps
- name: 构建结果通知
if: always()
run: |
if [ "${{ job.status }}" = "success" ]; then
echo "构建成功: ${{ steps.tag.outputs.tag }}"
echo "镜像标签: ${{ github.sha }}"
else
echo "构建失败"
fi