更新 .gitea/workflows/push.yml
This commit is contained in:
@@ -7,30 +7,38 @@ on:
|
|||||||
env: # 全局环境变量
|
env: # 全局环境变量
|
||||||
COMPOSE_PROJECT_NAME: nasrobot # 定义 compose 项目名称
|
COMPOSE_PROJECT_NAME: nasrobot # 定义 compose 项目名称
|
||||||
|
|
||||||
jobs:
|
build:
|
||||||
build:
|
runs-on: ubuntu-latest
|
||||||
name: Build Docker Image
|
steps:
|
||||||
runs-on: ubuntu-latest # 必须与 runner 的标签匹配 (如 GITEA_RUNNER_LABELS: "docker")
|
- 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:
|
steps:
|
||||||
- name: Checkout code # ✅ 必须添加代码检出
|
- uses: https://github.com/actions/checkout@v4
|
||||||
uses: addnab/docker-run-action@v3
|
- name: Set up Docker Buildx
|
||||||
|
uses: https://github.com/docker/setup-buildx-action@v3
|
||||||
- name: Cleanup old containers
|
with:
|
||||||
run: |
|
config-inline: |
|
||||||
docker compose -p $COMPOSE_PROJECT_NAME down || true
|
[registry."<my-private-unsecure-git-repository-ip-address>:5000"]
|
||||||
docker rmi ${{ env.COMPOSE_PROJECT_NAME }} || true
|
http = true
|
||||||
|
insecure = true
|
||||||
- name: Build new image
|
- name: Build and push Docker image
|
||||||
run: docker build -t ${{ env.COMPOSE_PROJECT_NAME }} .
|
uses: https://github.com/docker/build-push-action@v5
|
||||||
|
with:
|
||||||
deploy:
|
context: .
|
||||||
name: Deploy to Production
|
file: ./Dockerfile
|
||||||
runs-on: ubuntu-22.04
|
push: true
|
||||||
needs: build # ⚠️ 确保在 build 任务完成后执行
|
tags: "<my-private-unsecure-git-repository-ip-address>:5000/<my-docker-image>:$,<my-private-unsecure-git-repository-ip-address>:5000/<my-docker-image>:latest"
|
||||||
environment: production # 需要先在 Gitea 仓库设置中创建环境
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Start containers
|
|
||||||
run: docker compose -p $COMPOSE_PROJECT_NAME up -d
|
|
||||||
|
|||||||
Reference in New Issue
Block a user