From 95439c29483694724aab0a1649b692f599f50898 Mon Sep 17 00:00:00 2001 From: yokowu <18836617@qq.com> Date: Tue, 1 Jul 2025 11:03:23 +0800 Subject: [PATCH] chore: modify ci --- .github/workflows/backend-ci-cd.yml | 26 +++++---------------- .github/workflows/frontend-ci-cd.yml | 34 ++++++++++++++++++++++++---- backend/build/Dockerfile.nginx | 7 ------ backend/build/nginx.conf | 29 ------------------------ ui/.Dockerfile | 6 +---- ui/nginx.conf | 19 +++++++++++++++- 6 files changed, 54 insertions(+), 67 deletions(-) delete mode 100644 backend/build/Dockerfile.nginx delete mode 100644 backend/build/nginx.conf diff --git a/.github/workflows/backend-ci-cd.yml b/.github/workflows/backend-ci-cd.yml index 74fa8f2..073f535 100644 --- a/.github/workflows/backend-ci-cd.yml +++ b/.github/workflows/backend-ci-cd.yml @@ -4,11 +4,15 @@ on: push: tags: - "v[0-9]+.[0-9]+.[0-9]+*" + paths: + - 'backend/**' + - '.github/workflows/backend-ci-cd.yml' pull_request: branches: - main paths: - 'backend/**' + - '.github/workflows/backend-ci-cd.yml' env: REGISTRY: chaitin-registry.cn-hangzhou.cr.aliyuncs.com/monkeycode @@ -54,15 +58,10 @@ jobs: exit 1 fi - - name: Run wire generation - run: make wire - - - name: Generate swagger docs - run: make swag - build: needs: test runs-on: ubuntu-latest + if: github.event_name != 'pull_request' defaults: run: working-directory: ./backend @@ -96,7 +95,7 @@ jobs: with: context: . file: ./build/Dockerfile - push: ${{ github.event_name != 'pull_request' }} + push: true platforms: linux/amd64, linux/arm64 tags: | ${{ env.REGISTRY }}/backend:v${{ steps.get_version.outputs.VERSION }} @@ -106,17 +105,4 @@ jobs: GOMODCACHE=/tmp/go-mod REPO_COMMIT=${{ github.sha }} cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build and push nginx image - uses: docker/build-push-action@v5 - with: - context: . - file: ./build/Dockerfile.nginx - push: ${{ github.event_name != 'pull_request' }} - platforms: linux/amd64, linux/arm64 - tags: | - ${{ env.REGISTRY }}/nginx:v${{ steps.get_version.outputs.VERSION }} - ${{ env.REGISTRY }}/nginx:latest - cache-from: type=gha cache-to: type=gha,mode=max \ No newline at end of file diff --git a/.github/workflows/frontend-ci-cd.yml b/.github/workflows/frontend-ci-cd.yml index 0c2395c..2629ab8 100644 --- a/.github/workflows/frontend-ci-cd.yml +++ b/.github/workflows/frontend-ci-cd.yml @@ -2,16 +2,21 @@ name: Frontend CI/CD on: push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+*" paths: - 'ui/**' - '.github/workflows/frontend-ci-cd.yml' + pull_request: branches: - main - pull_request: paths: - 'ui/**' - '.github/workflows/frontend-ci-cd.yml' +env: + REGISTRY: chaitin-registry.cn-hangzhou.cr.aliyuncs.com/monkeycode + jobs: build: runs-on: ubuntu-latest @@ -34,6 +39,16 @@ jobs: with: version: 8 + - name: Get version + id: get_version + run: | + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + else + VERSION=$(git describe --tags --always --dirty) + fi + echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT + - name: Get pnpm store directory shell: bash run: | @@ -43,16 +58,23 @@ jobs: run: pnpm install - name: Build frontend - run: + run: | echo "VITE_APP_VERSION=${{ steps.get_version.outputs.VERSION }}" >> .env.production pnpm run build - name: 'Tar files' run: tar -cvf dist.tar dist + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: frontend-build + path: ./ui/dist.tar + package: needs: build runs-on: ubuntu-latest + if: github.event_name != 'pull_request' steps: - name: Checkout code uses: actions/checkout@v4 @@ -81,7 +103,7 @@ jobs: - name: Login to Aliyun Container Registry uses: docker/login-action@v3 with: - registry: chaitin-registry.cn-hangzhou.cr.aliyuncs.com + registry: ${{ env.REGISTRY }} username: ${{ secrets.CT_ALIYUN_USER }} password: ${{ secrets.CT_ALIYUN_PASS }} @@ -89,9 +111,11 @@ jobs: uses: docker/build-push-action@v5 with: context: ./ui - file: ./ui/Dockerfile + file: ./ui/.Dockerfile push: true platforms: linux/amd64, linux/arm64 - tags: chaitin-registry.cn-hangzhou.cr.aliyuncs.com/chaitin/monkey-code-frontend:v${{ needs.build.outputs.version }} + tags: | + ${{ env.REGISTRY }}/frontend:v${{ needs.build.outputs.version }} + ${{ env.REGISTRY }}/frontend:latest cache-from: type=gha cache-to: type=gha,mode=max diff --git a/backend/build/Dockerfile.nginx b/backend/build/Dockerfile.nginx deleted file mode 100644 index 23ea460..0000000 --- a/backend/build/Dockerfile.nginx +++ /dev/null @@ -1,7 +0,0 @@ -FROM nginx:1.27.5-alpine3.21 - -COPY ./build/nginx.conf /etc/nginx/conf.d/default.conf - -EXPOSE 80 - -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/backend/build/nginx.conf b/backend/build/nginx.conf deleted file mode 100644 index a883e03..0000000 --- a/backend/build/nginx.conf +++ /dev/null @@ -1,29 +0,0 @@ -upstream backend { - server monkeycode-server:8888; -} - -upstream frontend { - server monkeycode-frontend:80; -} - -server { - listen 80; - server_name _; - - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - - location / { - proxy_pass http://frontend; - } - - location /api { - proxy_pass http://backend; - } - - location /v1 { - proxy_pass http://backend; - } -} \ No newline at end of file diff --git a/ui/.Dockerfile b/ui/.Dockerfile index b982cd2..c3dd1a7 100644 --- a/ui/.Dockerfile +++ b/ui/.Dockerfile @@ -1,13 +1,9 @@ -FROM nginx:alpine +FROM nginx:1.27.5-alpine3.21 -# 将构建好的 React 应用静态文件复制到 Nginx 的服务目录 COPY dist /usr/share/nginx/html -# 将自定义 Nginx 配置文件复制到容器中 COPY nginx.conf /etc/nginx/nginx.conf -# 暴露 80 端口 EXPOSE 80 -# 启动 Nginx CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/ui/nginx.conf b/ui/nginx.conf index 94c066f..d41c7b4 100644 --- a/ui/nginx.conf +++ b/ui/nginx.conf @@ -1,4 +1,4 @@ -worker_processes 1; +worker_processes auto; user nginx nginx; events { worker_connections 4096; @@ -23,15 +23,32 @@ http { gzip on; gzip_types applicaiton/javascript text/css image/png image/jpeg image/gif; + upstream backend { + server monkeycode-server:8888; + } + server { listen 80; listen [::]:80; server_name _; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + location / { root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; } + + location /api { + proxy_pass http://backend; + } + + location /v1 { + proxy_pass http://backend; + } } } \ No newline at end of file