mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-09 18:23:49 +08:00
26
.github/workflows/backend-ci-cd.yml
vendored
26
.github/workflows/backend-ci-cd.yml
vendored
@@ -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
|
||||
34
.github/workflows/frontend-ci-cd.yml
vendored
34
.github/workflows/frontend-ci-cd.yml
vendored
@@ -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
|
||||
|
||||
@@ -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;"]
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;"]
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user