From c085fec1a7f9f60c12bddf55bac40f2ae103662f Mon Sep 17 00:00:00 2001 From: Suraj Mahto Date: Fri, 25 Oct 2024 22:19:12 +0530 Subject: [PATCH] feat : updated dockerfile for pnpm --- dockerfile | 54 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/dockerfile b/dockerfile index 426d39a..f307947 100644 --- a/dockerfile +++ b/dockerfile @@ -1,58 +1,70 @@ # Install dependencies only when needed FROM node:16-alpine AS deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. + +# Install libc6-compat if needed RUN apk add --no-cache libc6-compat + +# Install pnpm globally +RUN npm install -g pnpm + WORKDIR /app -# COPY package.json yarn.lock ./ -# RUN yarn install --frozen-lockfile -# If using npm with a `package-lock.json` comment out above and use below instead -COPY package.json package-lock.json ./ -RUN npm ci +# Copy package.json and pnpm-lock.yaml +COPY package.json pnpm-lock.yaml ./ + +# Install dependencies with pnpm +RUN pnpm install --frozen-lockfile # Rebuild the source code only when needed FROM node:16-alpine AS builder WORKDIR /app + +# Install pnpm globally +RUN npm install -g pnpm + +# Copy dependencies from the deps stage COPY --from=deps /app/node_modules ./node_modules COPY . . -# Next.js collects completely anonymous telemetry data about general usage. -# Learn more here: https://nextjs.org/telemetry -# Uncomment the following line in case you want to disable telemetry during the build. +# Optional: Disable Next.js telemetry during the build # ENV NEXT_TELEMETRY_DISABLED 1 -# RUN yarn build - -# If using npm comment out above and use below instead -RUN npm run build +# Build the Next.js application with pnpm +RUN pnpm run build -# Production image, copy all the files and run next +# Production image, copy all the files and run Next.js FROM node:16-alpine AS runner WORKDIR /app +# Install pnpm globally +RUN npm install -g pnpm + +# Set environment to production ENV NODE_ENV production -# Uncomment the following line in case you want to disable telemetry during runtime. + +# Optional: Disable telemetry during runtime # ENV NEXT_TELEMETRY_DISABLED 1 +# Create a non-root user and group RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs -# You only need to copy next.config.js if you are NOT using the default configuration -# COPY --from=builder /app/next.config.js ./ +# Copy only necessary files for production COPY --from=builder /app/public ./public COPY --from=builder /app/package.json ./package.json -# Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing +# Leverage output traces to reduce image size COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +# Ensure permissions for the public directory RUN chmod -R 777 ./public USER nextjs +# Expose port and set it in environment EXPOSE 3000 - ENV PORT 3000 -CMD ["node", "server.js"] \ No newline at end of file +# Run the server +CMD ["node", "server.js"]