Skip to content

Commit

Permalink
Switch to nextjs dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
SevLG committed Oct 22, 2024
1 parent db88bf5 commit c35d5a4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 66 deletions.
63 changes: 47 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
FROM node:21-alpine as builder
# Add a work directory
FROM node:18-alpine AS base

# 1. 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

# Install dependencies based on the preferred package manager
COPY ./next-app/package.json ./
COPY ./next-app/package-lock.json ./
RUN \
if [ -f package-lock.json ]; then npm ci; \
else echo "Lockfile not found." && exit 1; \
fi


# 2. Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
RUN chown -R node:node /app
USER node
# Cache and Install dependencies
COPY ./pmp-frontend-app/package.json .
COPY ./pmp-frontend-app/package-lock.json .
RUN npm ci
# Copy app files
COPY ./pmp-frontend-app/ .
COPY --from=deps /app/node_modules ./node_modules
COPY ./next-app/ .
# This will do the trick, use the corresponding env file for each environment.
RUN npm run build

FROM nginxinc/nginx-unprivileged:stable-alpine
USER 101
COPY ./conf/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
# 3. Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

COPY --from=builder /app/public ./public

# 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

CMD HOSTNAME="0.0.0.0" node server.js
50 changes: 0 additions & 50 deletions _nextjs_Dockerfile

This file was deleted.

19 changes: 19 additions & 0 deletions _vite_Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:21-alpine as builder
# Add a work directory
WORKDIR /app
RUN chown -R node:node /app
USER node
# Cache and Install dependencies
COPY ./pmp-frontend-app/package.json .
COPY ./pmp-frontend-app/package-lock.json .
RUN npm ci
# Copy app files
COPY ./pmp-frontend-app/ .
RUN npm run build

FROM nginxinc/nginx-unprivileged:stable-alpine
USER 101
COPY ./conf/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]

0 comments on commit c35d5a4

Please sign in to comment.