Skip to content

Commit

Permalink
Update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Munkkeli authored Jan 7, 2025
1 parent 07973d1 commit e7a3e96
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
FROM node:18-alpine AS base

# This will be set by the GitHub action to the folder containing this component.
ARG FOLDER=.

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY . .
WORKDIR ${FOLDER}

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
Expand All @@ -17,9 +21,9 @@ RUN \

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
WORKDIR ${FOLDER}
COPY --from=deps ${FOLDER}/node_modules ./node_modules

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
Expand All @@ -38,7 +42,12 @@ RUN mkdir -p ./public

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
COPY . .

# Clear the Next.js component folder as it will be populated by the build output.
RUN rm -rf -- ${FOLDER}

WORKDIR ${FOLDER}

# NOTE! We default to this now, production needs to be solved later
ENV NODE_ENV=development
Expand All @@ -49,7 +58,7 @@ ENV NODE_ENV=development
#RUN addgroup --system --gid 1001 nodejs
#RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public
COPY --from=builder ${FOLDER}/public ./public

# Set the correct permission for prerender cache
#RUN mkdir .next
Expand All @@ -59,8 +68,8 @@ COPY --from=builder /app/public ./public
# 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
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder ${FOLDER}/.next/standalone ./
COPY --from=builder ${FOLDER}/.next/static ./.next/static


USER node
Expand Down

0 comments on commit e7a3e96

Please sign in to comment.