docs: 完善 README 与全栈 Docker 生产编排,交付收尾
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
# 后端 API 生产镜像(多阶段构建)。构建上下文为仓库根目录。
|
||||
FROM node:20-slim AS builder
|
||||
RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||
RUN corepack enable
|
||||
WORKDIR /app
|
||||
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
|
||||
COPY packages/shared/package.json ./packages/shared/
|
||||
COPY apps/api/package.json ./apps/api/
|
||||
RUN pnpm install --frozen-lockfile
|
||||
COPY packages/shared ./packages/shared
|
||||
COPY apps/api ./apps/api
|
||||
RUN pnpm --filter @artveris/shared build \
|
||||
&& pnpm --filter @artveris/api exec prisma generate \
|
||||
&& pnpm --filter @artveris/api build
|
||||
|
||||
FROM node:20-slim AS runner
|
||||
RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/packages ./packages
|
||||
COPY --from=builder /app/apps/api ./apps/api
|
||||
WORKDIR /app/apps/api
|
||||
ENV NODE_ENV=production
|
||||
EXPOSE 3000
|
||||
# 启动前应用数据库迁移,再运行服务
|
||||
CMD ["sh", "-c", "node ../../node_modules/prisma/build/index.js migrate deploy --schema prisma/schema.prisma && node dist/main.js"]
|
||||
@@ -0,0 +1,66 @@
|
||||
# 全栈生产编排参考。使用前先在仓库根执行 pnpm -r build 生成前端 dist。
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root123}
|
||||
MYSQL_DATABASE: ${MYSQL_DATABASE:-artveris}
|
||||
MYSQL_USER: ${MYSQL_USER:-artveris}
|
||||
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-artveris123}
|
||||
command: >-
|
||||
--character-set-server=utf8mb4 --collation-server=utf8mb4_0900_ai_ci
|
||||
volumes:
|
||||
- artveris_mysql:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-p${MYSQL_ROOT_PASSWORD:-root123}"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 30
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- artveris_redis:/data
|
||||
|
||||
api:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile.api
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
API_PORT: 3000
|
||||
DATABASE_URL: "mysql://${MYSQL_USER:-artveris}:${MYSQL_PASSWORD:-artveris123}@mysql:3306/${MYSQL_DATABASE:-artveris}"
|
||||
REDIS_HOST: redis
|
||||
REDIS_PORT: 6379
|
||||
JWT_SECRET: ${JWT_SECRET:-please_change_in_prod}
|
||||
BASE_URL: ${BASE_URL:-http://localhost}
|
||||
H5_ORIGIN: ${H5_ORIGIN:-http://localhost:8080}
|
||||
STORAGE_DRIVER: ${STORAGE_DRIVER:-local}
|
||||
BLOCKCHAIN_DRIVER: ${BLOCKCHAIN_DRIVER:-mock}
|
||||
GEO_DRIVER: mock
|
||||
volumes:
|
||||
- artveris_storage:/app/apps/api/storage
|
||||
|
||||
web:
|
||||
image: nginx:alpine
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- api
|
||||
ports:
|
||||
- "80:80"
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ../apps/admin/dist:/usr/share/nginx/html/admin:ro
|
||||
- ../apps/h5/dist:/usr/share/nginx/html/h5:ro
|
||||
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
|
||||
volumes:
|
||||
artveris_mysql:
|
||||
artveris_redis:
|
||||
artveris_storage:
|
||||
@@ -0,0 +1,45 @@
|
||||
# 管理后台(默认 80 端口)
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html/admin;
|
||||
index index.html;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://api:3000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
client_max_body_size 120m;
|
||||
}
|
||||
location /uploads/ {
|
||||
proxy_pass http://api:3000;
|
||||
}
|
||||
location /t/ {
|
||||
proxy_pass http://api:3000;
|
||||
}
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
|
||||
# C 端移动溯源页(8080 端口)
|
||||
server {
|
||||
listen 8080;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html/h5;
|
||||
index index.html;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://api:3000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
location /uploads/ {
|
||||
proxy_pass http://api:3000;
|
||||
}
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user