Skip to content

Commit

Permalink
feat : updated dockerfile for pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
surajhub255 committed Oct 25, 2024
1 parent 2c3c760 commit c085fec
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
# Run the server
CMD ["node", "server.js"]

0 comments on commit c085fec

Please sign in to comment.