ForcePilot/docker/web.Dockerfile

57 lines
1.3 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 开发阶段
FROM node:20-alpine AS development
WORKDIR /app
ENV TZ=Asia/Shanghai
# 安装 pnpm
RUN npm install -g pnpm@latest
# 复制 package.json 和 pnpm-lock.yaml
COPY ./web/package*.json ./
COPY ./web/pnpm-lock.yaml* ./
# 安装依赖
RUN pnpm install --registry=https://registry.npmmirror.com
# 复制源代码
COPY ./web .
# 暴露端口
EXPOSE 5173
# 启动开发服务器的命令在 docker-compose 文件中定义
# 生产阶段
FROM node:20-alpine AS build-stage
WORKDIR /app
# 安装 pnpm
RUN npm install -g pnpm@latest
# 构建阶段注入前端环境变量Vite 在 build 时读取)
ARG VITE_API_URL=http://api:5050
ARG VITE_USE_RUNS_API=false
ARG VITE_ENABLE_KNOWLEDGE_GRAPH=true
ENV VITE_API_URL=${VITE_API_URL}
ENV VITE_USE_RUNS_API=${VITE_USE_RUNS_API}
ENV VITE_ENABLE_KNOWLEDGE_GRAPH=${VITE_ENABLE_KNOWLEDGE_GRAPH}
# 复制依赖文件
COPY ./web/package*.json ./
COPY ./web/pnpm-lock.yaml* ./
# 安装依赖
RUN pnpm install --frozen-lockfile --registry=https://registry.npmmirror.com
# 复制源代码并构建
COPY ./web .
RUN pnpm run build
# 生产环境运行阶段
FROM nginx:alpine AS production
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]