From 2baad14c9efb7a4ebf28868dce376d7b8a02d405 Mon Sep 17 00:00:00 2001 From: ipanghu Date: Mon, 25 Nov 2024 11:15:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20dockerfile=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BC=93=E5=AD=98=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/Dockerfile | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/web/Dockerfile b/web/Dockerfile index 89a1066757..af4464ea19 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,15 +1,25 @@ -FROM node:20 +# 如果需要用 cicd ,请设置环境变量: +# variables: +# DOCKER_BUILDKIT: 1 -WORKDIR /gva_web/ -COPY . . +FROM node:20-slim AS base +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN corepack enable +COPY . /app +WORKDIR /app -RUN yarn && yarn build -FROM nginx:alpine -LABEL MAINTAINER="SliverHorn@sliver_horn@qq.com" +FROM base AS prod-deps +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod + +FROM base AS build +COPY --from=prod-deps /app/node_modules /app/node_modules +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install && pnpm run build -COPY .docker-compose/nginx/conf.d/my.conf /etc/nginx/conf.d/my.conf -COPY --from=0 /gva_web/dist /usr/share/nginx/html -RUN cat /etc/nginx/nginx.conf -RUN cat /etc/nginx/conf.d/my.conf + +FROM nginx:alpine +LABEL MAINTAINER="bypanghu@163.com" +COPY --from=base /app/.docker-compose/nginx/conf.d/my.conf /etc/nginx/conf.d/my.conf +COPY --from=build /app/dist /usr/share/nginx/html RUN ls -al /usr/share/nginx/html