From 177050fb28105f449565533c913f4d4120c9ed10 Mon Sep 17 00:00:00 2001 From: tobias Date: Thu, 6 Jun 2024 08:05:16 +0200 Subject: [PATCH] 'Refine' dockerfile --- Dockerfile | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index aef24da..0f7abda 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,38 @@ FROM node:lts as base +# Set environment variables for pnpm ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable WORKDIR /base COPY package.json pnpm-lock.yaml ./ -RUN pnpm install --prod --frozen-lockfile +RUN pnpm install --frozen-lockfile COPY . . -FROM base AS dev -ENV NODE_ENV=development -EXPOSE 3001 -CMD ["pnpm","dev"] - -FROM base AS build +# Build stage: build the Next.js application +FROM base as build ENV NODE_ENV=production -WORKDIR /build -COPY --from=base /base . +WORKDIR /base RUN pnpm build -FROM build as prod +# Production stage: serve the application +FROM node:lts as prod ENV NODE_ENV=production -WORKDIR /prod -COPY package*.json . +WORKDIR /app + +# Copy package files and install production dependencies +COPY package.json pnpm-lock.yaml ./ RUN pnpm install --production -COPY --from=build /build/tsconfig.json ./tsconfig.json -COPY --from=build /build/dist ./dist -COPY --from=build /build/build ./build +# Copy build artifacts from the build stage +COPY --from=build /base/.next ./.next +COPY --from=build /base/public ./public +COPY --from=build /base/next.config.js ./ + EXPOSE 3000 COPY docker-entrypoint.sh /docker-entrypoint.sh +RUN chmod +x /docker-entrypoint.sh ENTRYPOINT ["/docker-entrypoint.sh"] -CMD ["pnpm", "serve"] + +CMD ["pnpm", "start"]