diff --git a/.gitea/workflows/push.yml b/.gitea/workflows/push.yml new file mode 100644 index 0000000..e639bcb --- /dev/null +++ b/.gitea/workflows/push.yml @@ -0,0 +1,33 @@ +name: Docker Build & Deploy +on: [push] # 触发条件:代码推送时触发 + +env: # 全局环境变量 + COMPOSE_PROJECT_NAME: nasrobot # 定义 compose 项目名称 + +jobs: + build: + name: Build Docker Image + runs-on: docker # 必须与 runner 的标签匹配 (如 GITEA_RUNNER_LABELS: "docker") + steps: + - name: Checkout code # ✅ 必须添加代码检出 + uses: actions/checkout@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: docker + 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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f42680c..e639bcb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,34 +1,33 @@ -# This file is a template, and might need editing before it works on your project. -# This is a sample GitLab CI/CD configuration file that should run without any modifications. -# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts, -# it uses echo commands to simulate the pipeline execution. -# -# A pipeline is composed of independent jobs that run scripts, grouped into stages. -# Stages run in sequential order, but jobs within stages run in parallel. -# -# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages -# -# You can copy and paste this template into a new `.gitlab-ci.yml` file. -# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword. -# -# To contribute improvements to CI/CD templates, please follow the Development guide at: -# https://docs.gitlab.com/ee/development/cicd/templates.html -# This specific template is located at: -# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml +name: Docker Build & Deploy +on: [push] # 触发条件:代码推送时触发 -stages: # List of stages for jobs, and their order of execution - - build - - deploy +env: # 全局环境变量 + COMPOSE_PROJECT_NAME: nasrobot # 定义 compose 项目名称 -build-job: # This job runs in the build stage, which runs first. - stage: build - script: - - docker compose down || true - - docker rmi nasrobot-nas_robot || true - - docker build -t nasrobot . +jobs: + build: + name: Build Docker Image + runs-on: docker # 必须与 runner 的标签匹配 (如 GITEA_RUNNER_LABELS: "docker") + steps: + - name: Checkout code # ✅ 必须添加代码检出 + uses: actions/checkout@v3 -deploy-job: # This job runs in the deploy stage. - stage: deploy # It only runs when *both* jobs in the test stage complete successfully. - environment: production - script: - - docker compose up -d + - 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: docker + 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 diff --git a/NasRobot.sln b/NasRobot.sln index a10c299..5467d08 100644 --- a/NasRobot.sln +++ b/NasRobot.sln @@ -14,7 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution docker-compose.yml = docker-compose.yml Dockerfile = Dockerfile .dockerignore = .dockerignore - .gitlab-ci.yml = .gitlab-ci.yml EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "src\Interface\Interface.csproj", "{204D20C6-39DE-4F64-8392-C8032F3FA417}"