2024-02-27 17:22:27 +08:00
|
|
|
|
|
|
|
# https://stackoverflow.com/questions/53681522/share-variable-in-multi-stage-dockerfile-arg-before-from-not-substituted
|
|
|
|
ARG PROJECT_DIR=/huaxin-base-frontend
|
|
|
|
|
|
|
|
FROM node:20-slim as builder
|
|
|
|
ARG PROJECT_DIR
|
|
|
|
WORKDIR $PROJECT_DIR
|
|
|
|
|
|
|
|
# 安装pnpm
|
|
|
|
RUN npm install -g pnpm
|
|
|
|
|
|
|
|
COPY . ./
|
|
|
|
# 安装依赖
|
|
|
|
# 若网络不通,可以使用淘宝源
|
|
|
|
# RUN pnpm config set registry https://registry.npmmirror.com
|
2024-03-01 17:23:37 +08:00
|
|
|
# see https://pnpm.io/docker
|
|
|
|
FROM builder AS prod-deps
|
|
|
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
|
|
|
|
|
|
|
|
FROM builder AS build
|
|
|
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
|
|
|
RUN pnpm run build
|
|
|
|
|
|
|
|
|
|
|
|
# mirror acceleration
|
|
|
|
# RUN npm config set registry https://registry.npmmirror.com
|
|
|
|
# RUN pnpm config set registry https://registry.npmmirror.com
|
|
|
|
# RUN npm config rm proxy && npm config rm https-proxy
|
|
|
|
|
|
|
|
FROM builder
|
|
|
|
COPY --from=prod-deps $PROJECT_DIR/node_modules $PROJECT_DIR/node_modules
|
|
|
|
COPY --from=build $PROJECT_DIR/dist $PROJECT_DIR/dist
|
2024-02-27 17:22:27 +08:00
|
|
|
|
|
|
|
# 构建项目
|
|
|
|
ENV VITE_BASE_URL=/
|
|
|
|
RUN pnpm build
|
|
|
|
|
|
|
|
|
|
|
|
FROM nginx:alpine as production
|
|
|
|
ARG PROJECT_DIR
|
|
|
|
|
|
|
|
COPY --from=builder $PROJECT_DIR/dist/ /usr/share/nginx/html
|
2024-02-28 10:51:39 +08:00
|
|
|
COPY --from=builder $PROJECT_DIR/nginx.conf /etc/nginx/nginx.conf
|
2024-02-27 17:22:27 +08:00
|
|
|
|
|
|
|
EXPOSE 80
|