Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to nextjs dockerfile #76

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;"]
Loading