Skip to content

Commit 002f494

Browse files
authored
Merge pull request #18 from yokowu/main
chore: modify ci
2 parents ba14bbf + 95439c2 commit 002f494

File tree

6 files changed

+54
-67
lines changed

6 files changed

+54
-67
lines changed

.github/workflows/backend-ci-cd.yml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ on:
44
push:
55
tags:
66
- "v[0-9]+.[0-9]+.[0-9]+*"
7+
paths:
8+
- 'backend/**'
9+
- '.github/workflows/backend-ci-cd.yml'
710
pull_request:
811
branches:
912
- main
1013
paths:
1114
- 'backend/**'
15+
- '.github/workflows/backend-ci-cd.yml'
1216

1317
env:
1418
REGISTRY: chaitin-registry.cn-hangzhou.cr.aliyuncs.com/monkeycode
@@ -54,15 +58,10 @@ jobs:
5458
exit 1
5559
fi
5660
57-
- name: Run wire generation
58-
run: make wire
59-
60-
- name: Generate swagger docs
61-
run: make swag
62-
6361
build:
6462
needs: test
6563
runs-on: ubuntu-latest
64+
if: github.event_name != 'pull_request'
6665
defaults:
6766
run:
6867
working-directory: ./backend
@@ -96,7 +95,7 @@ jobs:
9695
with:
9796
context: .
9897
file: ./build/Dockerfile
99-
push: ${{ github.event_name != 'pull_request' }}
98+
push: true
10099
platforms: linux/amd64, linux/arm64
101100
tags: |
102101
${{ env.REGISTRY }}/backend:v${{ steps.get_version.outputs.VERSION }}
@@ -106,17 +105,4 @@ jobs:
106105
GOMODCACHE=/tmp/go-mod
107106
REPO_COMMIT=${{ github.sha }}
108107
cache-from: type=gha
109-
cache-to: type=gha,mode=max
110-
111-
- name: Build and push nginx image
112-
uses: docker/build-push-action@v5
113-
with:
114-
context: .
115-
file: ./build/Dockerfile.nginx
116-
push: ${{ github.event_name != 'pull_request' }}
117-
platforms: linux/amd64, linux/arm64
118-
tags: |
119-
${{ env.REGISTRY }}/nginx:v${{ steps.get_version.outputs.VERSION }}
120-
${{ env.REGISTRY }}/nginx:latest
121-
cache-from: type=gha
122108
cache-to: type=gha,mode=max

.github/workflows/frontend-ci-cd.yml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@ name: Frontend CI/CD
22

33
on:
44
push:
5+
tags:
6+
- "v[0-9]+.[0-9]+.[0-9]+*"
57
paths:
68
- 'ui/**'
79
- '.github/workflows/frontend-ci-cd.yml'
10+
pull_request:
811
branches:
912
- main
10-
pull_request:
1113
paths:
1214
- 'ui/**'
1315
- '.github/workflows/frontend-ci-cd.yml'
1416

17+
env:
18+
REGISTRY: chaitin-registry.cn-hangzhou.cr.aliyuncs.com/monkeycode
19+
1520
jobs:
1621
build:
1722
runs-on: ubuntu-latest
@@ -34,6 +39,16 @@ jobs:
3439
with:
3540
version: 8
3641

42+
- name: Get version
43+
id: get_version
44+
run: |
45+
if [[ $GITHUB_REF == refs/tags/* ]]; then
46+
VERSION=${GITHUB_REF#refs/tags/}
47+
else
48+
VERSION=$(git describe --tags --always --dirty)
49+
fi
50+
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
51+
3752
- name: Get pnpm store directory
3853
shell: bash
3954
run: |
@@ -43,16 +58,23 @@ jobs:
4358
run: pnpm install
4459

4560
- name: Build frontend
46-
run:
61+
run: |
4762
echo "VITE_APP_VERSION=${{ steps.get_version.outputs.VERSION }}" >> .env.production
4863
pnpm run build
4964
5065
- name: 'Tar files'
5166
run: tar -cvf dist.tar dist
5267

68+
- name: Upload build artifacts
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: frontend-build
72+
path: ./ui/dist.tar
73+
5374
package:
5475
needs: build
5576
runs-on: ubuntu-latest
77+
if: github.event_name != 'pull_request'
5678
steps:
5779
- name: Checkout code
5880
uses: actions/checkout@v4
@@ -81,17 +103,19 @@ jobs:
81103
- name: Login to Aliyun Container Registry
82104
uses: docker/login-action@v3
83105
with:
84-
registry: chaitin-registry.cn-hangzhou.cr.aliyuncs.com
106+
registry: ${{ env.REGISTRY }}
85107
username: ${{ secrets.CT_ALIYUN_USER }}
86108
password: ${{ secrets.CT_ALIYUN_PASS }}
87109

88110
- name: Package and push
89111
uses: docker/build-push-action@v5
90112
with:
91113
context: ./ui
92-
file: ./ui/Dockerfile
114+
file: ./ui/.Dockerfile
93115
push: true
94116
platforms: linux/amd64, linux/arm64
95-
tags: chaitin-registry.cn-hangzhou.cr.aliyuncs.com/chaitin/monkey-code-frontend:v${{ needs.build.outputs.version }}
117+
tags: |
118+
${{ env.REGISTRY }}/frontend:v${{ needs.build.outputs.version }}
119+
${{ env.REGISTRY }}/frontend:latest
96120
cache-from: type=gha
97121
cache-to: type=gha,mode=max

backend/build/Dockerfile.nginx

Lines changed: 0 additions & 7 deletions
This file was deleted.

backend/build/nginx.conf

Lines changed: 0 additions & 29 deletions
This file was deleted.

ui/.Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
FROM nginx:alpine
1+
FROM nginx:1.27.5-alpine3.21
22

3-
# 将构建好的 React 应用静态文件复制到 Nginx 的服务目录
43
COPY dist /usr/share/nginx/html
54

6-
# 将自定义 Nginx 配置文件复制到容器中
75
COPY nginx.conf /etc/nginx/nginx.conf
86

9-
# 暴露 80 端口
107
EXPOSE 80
118

12-
# 启动 Nginx
139
CMD ["nginx", "-g", "daemon off;"]

ui/nginx.conf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
worker_processes 1;
1+
worker_processes auto;
22
user nginx nginx;
33
events {
44
worker_connections 4096;
@@ -23,15 +23,32 @@ http {
2323
gzip on;
2424
gzip_types applicaiton/javascript text/css image/png image/jpeg image/gif;
2525

26+
upstream backend {
27+
server monkeycode-server:8888;
28+
}
29+
2630
server {
2731
listen 80;
2832
listen [::]:80;
2933
server_name _;
3034

35+
proxy_set_header Host $host;
36+
proxy_set_header X-Real-IP $remote_addr;
37+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
38+
proxy_set_header X-Forwarded-Proto $scheme;
39+
3140
location / {
3241
root /usr/share/nginx/html;
3342
index index.html index.htm;
3443
try_files $uri $uri/ /index.html;
3544
}
45+
46+
location /api {
47+
proxy_pass http://backend;
48+
}
49+
50+
location /v1 {
51+
proxy_pass http://backend;
52+
}
3653
}
3754
}

0 commit comments

Comments
 (0)