48 lines
1.2 KiB
Docker
48 lines
1.2 KiB
Docker
# 阶段1: 构建前端
|
|
FROM node:20-alpine AS frontend-builder
|
|
WORKDIR /app/frontend
|
|
COPY frontend/package*.json ./
|
|
RUN npm ci
|
|
COPY frontend/ ./
|
|
RUN npm run build
|
|
|
|
# 阶段2: 构建后端
|
|
FROM node:20-alpine AS backend-builder
|
|
WORKDIR /app/backend
|
|
COPY backend/package*.json ./
|
|
RUN npm ci
|
|
COPY backend/ ./
|
|
RUN npx prisma generate
|
|
|
|
# 阶段3: 生产环境
|
|
FROM node:20-alpine AS production
|
|
WORKDIR /app
|
|
|
|
# 安装nginx和sqlite
|
|
RUN apk add --no-cache nginx sqlite
|
|
|
|
# 复制后端
|
|
COPY --from=backend-builder /app/backend ./backend
|
|
RUN cd backend && npm ci --only=production
|
|
|
|
# 复制前端构建
|
|
COPY --from=frontend-builder /app/frontend/.next ./frontend/.next
|
|
COPY --from=frontend-builder /app/frontend/package*.json ./frontend/
|
|
COPY --from=frontend-builder /app/frontend/public ./frontend/public
|
|
COPY --from=frontend-builder /app/frontend/next.config.ts ./frontend/
|
|
COPY --from=frontend-builder /app/frontend/tsconfig.json ./frontend/
|
|
RUN cd frontend && npm ci --only=production
|
|
|
|
# 复制nginx配置
|
|
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
|
|
|
# 复制启动脚本
|
|
COPY docker/start.sh /app/start.sh
|
|
RUN chmod +x /app/start.sh
|
|
|
|
# 暴露端口
|
|
EXPOSE 3000
|
|
|
|
# 启动服务
|
|
CMD ["/app/start.sh"]
|