This commit is contained in:
21
Dockerfile
21
Dockerfile
@@ -15,7 +15,6 @@ RUN apk add --no-cache imagemagick libwebp libwebp-tools ghostscript
|
|||||||
|
|
||||||
# Copy only the necessary files for installing dependencies
|
# Copy only the necessary files for installing dependencies
|
||||||
COPY package.json pnpm-lock.yaml ./
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
|
||||||
# Install ALL dependencies (including devDependencies needed for `next build`)
|
# Install ALL dependencies (including devDependencies needed for `next build`)
|
||||||
# This leverages the Docker cache effectively.
|
# This leverages the Docker cache effectively.
|
||||||
RUN pnpm install --frozen-lockfile
|
RUN pnpm install --frozen-lockfile
|
||||||
@@ -25,10 +24,10 @@ COPY . .
|
|||||||
|
|
||||||
# --- Asset Generation & Build ---
|
# --- Asset Generation & Build ---
|
||||||
RUN chmod +x ./scripts/*.sh && ./scripts/first_page_image.sh
|
RUN chmod +x ./scripts/*.sh && ./scripts/first_page_image.sh
|
||||||
|
# The build command creates the .next/standalone directory
|
||||||
RUN pnpm build
|
RUN pnpm build
|
||||||
|
|
||||||
# Stage 3: Runner (Production)
|
# Stage 3: Runner (Production)
|
||||||
# This is the final, lean image that runs the application.
|
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -39,25 +38,21 @@ ENV NODE_ENV=production
|
|||||||
RUN addgroup --system --gid 1001 nodejs
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
RUN adduser --system --uid 1001 nextjs
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
# Copy only the files needed for production from the builder stage
|
# Copy the standalone output from the builder
|
||||||
COPY --from=builder /app/package.json /app/pnpm-lock.yaml ./
|
COPY --from=builder /app/.next/standalone ./
|
||||||
|
|
||||||
# Install ONLY production dependencies.
|
# Copy the public and static assets
|
||||||
# The pnpm CLI is already available from the 'base' stage.
|
|
||||||
RUN pnpm install --prod --frozen-lockfile
|
|
||||||
|
|
||||||
# Copy the built Next.js application and public assets
|
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
COPY --from=builder /app/.next ./.next
|
COPY --from=builder /app/.next/static ./.next/static
|
||||||
|
|
||||||
# Change ownership to the non-root user
|
# Change ownership to the non-root user
|
||||||
RUN chown -R nextjs:nodejs /app
|
RUN chown -R nextjs:nodejs /app
|
||||||
|
|
||||||
# Switch to the non-root user
|
# Switch to the non-root user
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
|
|
||||||
# The command to start the Next.js server
|
# --- FINAL CMD CHANGED ---
|
||||||
CMD ["pnpm", "start"]
|
# Directly run the standalone server.
|
||||||
|
CMD ["node", "server.js"]
|
||||||
Reference in New Issue
Block a user