-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;"] |