From bd0fef361b9001da2d2330e51842a9888e9c06c4 Mon Sep 17 00:00:00 2001 From: gnehs Date: Mon, 13 May 2024 22:23:27 +0800 Subject: [PATCH] updated dockerfile ref: lovell/sharp/issues/3967 --- Dockerfile | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index a0b6733..3af9f08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,25 +2,42 @@ FROM node:22-alpine as base ENV PNPM_HOME="/var/lib/pnpm" ENV PATH="$PNPM_HOME:$PATH" + RUN corepack enable RUN apk add --no-cache tzdata ENV TZ=Asia/Taipei WORKDIR /app +# Install dependencies based on the preferred package manager +FROM base AS deps COPY package.json pnpm-lock.yaml ./ +RUN pnpm i --frozen-lockfile -RUN pnpm install --frozen-lockfile +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules COPY . . +RUN pnpm run build +RUN pnpm dlx prisma generate -RUN npx prisma generate -RUN pnpm build -RUN addgroup --system --gid 1001 nodejs && \ - adduser --system --uid 1001 nextjs +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app +ENV NODE_ENV production +RUN mkdir .next + +RUN chown nextjs:nodejs .next +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static USER nextjs EXPOSE 3000 ENV PORT 3000 +ENV HOSTNAME "0.0.0.0" -CMD pnpm start \ No newline at end of file +CMD ["node", "server.js"] \ No newline at end of file