From 703b2a5d9560408df7ba49a443be2165875bba85 Mon Sep 17 00:00:00 2001 From: suncheng Date: Wed, 5 Mar 2025 18:54:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/push.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/push.yml | 60 ++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/.gitea/workflows/push.yml b/.gitea/workflows/push.yml index 9b51964..9564285 100644 --- a/.gitea/workflows/push.yml +++ b/.gitea/workflows/push.yml @@ -7,30 +7,38 @@ on: env: # 全局环境变量 COMPOSE_PROJECT_NAME: nasrobot # 定义 compose 项目名称 -jobs: - build: - name: Build Docker Image - runs-on: ubuntu-latest # 必须与 runner 的标签匹配 (如 GITEA_RUNNER_LABELS: "docker") +build: + runs-on: ubuntu-latest + steps: + - uses: https://github.com/actions/checkout@v4 + - name: Use Node.js + uses: https://github.com/actions/setup-node@v3 + with: + node-version: '18.17' + - run: npm ci + - run: npm run lint + - run: npm run test + - run: npm run build:prod + env: + NODE_OPTIONS: --max_old_space_size=4096 + + publish: + runs-on: cth-ubuntu-latest + needs: build + if: gitea.ref == 'refs/heads/main' steps: - - name: Checkout code # ✅ 必须添加代码检出 - uses: addnab/docker-run-action@v3 - - - name: Cleanup old containers - run: | - docker compose -p $COMPOSE_PROJECT_NAME down || true - docker rmi ${{ env.COMPOSE_PROJECT_NAME }} || true - - - name: Build new image - run: docker build -t ${{ env.COMPOSE_PROJECT_NAME }} . - - deploy: - name: Deploy to Production - runs-on: ubuntu-22.04 - needs: build # ⚠️ 确保在 build 任务完成后执行 - environment: production # 需要先在 Gitea 仓库设置中创建环境 - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Start containers - run: docker compose -p $COMPOSE_PROJECT_NAME up -d + - uses: https://github.com/actions/checkout@v4 + - name: Set up Docker Buildx + uses: https://github.com/docker/setup-buildx-action@v3 + with: + config-inline: | + [registry.":5000"] + http = true + insecure = true + - name: Build and push Docker image + uses: https://github.com/docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ":5000/:$,:5000/:latest"