ci: add test environment client deployment
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
.git
|
||||
.playwright-cli
|
||||
.impeccable
|
||||
dist
|
||||
node_modules
|
||||
node_modules.broken-by-path
|
||||
.env.local
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
# 构建 Vue 静态文件
|
||||
FROM node:22-alpine AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Corepack 与 pnpm 依赖均通过 npmmirror 下载,避免构建时访问 npm 官方源过慢。
|
||||
ENV COREPACK_NPM_REGISTRY=https://registry.npmmirror.com
|
||||
ENV NPM_CONFIG_REGISTRY=https://registry.npmmirror.com
|
||||
RUN corepack enable
|
||||
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
COPY shared/package.json ./shared/package.json
|
||||
|
||||
# package.json 和 lock 文件未变化时,这一层会由 Docker 自动复用。
|
||||
RUN pnpm config set registry https://registry.npmmirror.com && \
|
||||
pnpm install --frozen-lockfile
|
||||
|
||||
COPY . .
|
||||
RUN pnpm test && pnpm build
|
||||
|
||||
# 运行阶段仅保留构建产物与 Nginx。
|
||||
FROM nginx:1.27-alpine
|
||||
|
||||
COPY nginx/default.conf.template /etc/nginx/templates/default.conf.template
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
|
||||
EXPOSE 80
|
||||
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
options {
|
||||
timestamps()
|
||||
disableConcurrentBuilds()
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('确认提交版本') {
|
||||
steps {
|
||||
sh 'echo "Jenkins 已拉取 release/test 分支代码"'
|
||||
sh 'git log -1 --oneline'
|
||||
}
|
||||
}
|
||||
|
||||
stage('构建并部署测试前端') {
|
||||
steps {
|
||||
sh '''
|
||||
set -eu
|
||||
docker compose -f docker-compose.test.yml build --pull=false
|
||||
docker compose -f docker-compose.test.yml up -d --remove-orphans
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('部署检查') {
|
||||
steps {
|
||||
sh '''
|
||||
set -eu
|
||||
docker compose -f docker-compose.test.yml ps
|
||||
docker compose -f docker-compose.test.yml exec -T client-web wget -qO- http://127.0.0.1/healthz
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
failure {
|
||||
sh 'docker compose -f docker-compose.test.yml logs --tail=100 || true'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
services:
|
||||
client-web:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: client-web-test:local
|
||||
container_name: client-web-test
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "${HOST_PORT:-9002}:80"
|
||||
environment:
|
||||
# 测试环境 Gateway;迁移环境时可由 Jenkins 环境变量覆盖。
|
||||
API_UPSTREAM: "${API_UPSTREAM:-http://8.163.30.128:9000}"
|
||||
@@ -0,0 +1,28 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
location = /healthz {
|
||||
default_type text/plain;
|
||||
return 200 "ok\n";
|
||||
}
|
||||
|
||||
# 前端统一请求 /api,保持原始路径转发给 Gateway。
|
||||
location /api/ {
|
||||
proxy_pass ${API_UPSTREAM};
|
||||
proxy_http_version 1.1;
|
||||
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;
|
||||
}
|
||||
|
||||
# 支持 Vue Router history 路由直接刷新。
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user