Files
hzhub/hzhub-portal-dealer/Dockerfile

48 lines
1.0 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:22-alpine AS builder
# 接收构建参数
ARG VITE_API_URL
ARG VITE_APP_ENV=production
# 设置环境变量
ENV VITE_API_URL=${VITE_API_URL}
ENV VITE_APP_ENV=${VITE_APP_ENV}
# 设置工作目录
WORKDIR /app
# 复制 package 文件
COPY package.json pnpm-lock.yaml ./
# 安装 pnpm 并安装依赖
RUN npm install -g pnpm && \
pnpm install --frozen-lockfile
# 复制源代码
COPY . .
# 构建生产版本(使用 production 模式)
RUN pnpm build
# 生产阶段
FROM nginx:alpine
# 安装 envsubst
RUN apk add --no-cache gettext
# 复制构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
# 设置后端地址环境变量(默认指向 hzhub-ai 服务)
ENV UPSTREAM_URL=http://hzhub-ai:6039
# 复制 Nginx 配置模板
COPY nginx.conf /etc/nginx/templates/default.conf.template
# 暴露端口
EXPOSE 5138
# 启动 Nginx使用 envsubst 替换环境变量)
CMD /bin/sh -c "envsubst '\$UPSTREAM_URL' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"