-
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.
Merge pull request #166 from AutomatingSciencePipeline/frontend-hot-r…
…eload Frontend hot reload + frontend real™ actual™ production server
- Loading branch information
Showing
7 changed files
with
80 additions
and
27 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
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,27 +1,71 @@ | ||
FROM node:14-alpine | ||
FROM node:14-alpine AS base | ||
|
||
# TODO find a way to toggle between dev and prod | ||
# ENV NODE_ENV=production | ||
ENV NODE_ENV=development | ||
|
||
# Retain installed node modules | ||
VOLUME [ "/home/node/app/node_modules" ] | ||
ARG FRONTEND_WEBSERVER_PORT | ||
ENV FRONTEND_WEBSERVER_PORT=$FRONTEND_WEBSERVER_PORT | ||
|
||
# Expose port | ||
# TODO switch to ${FRONTEND_WEBSERVER_PORT} | ||
EXPOSE 3000 | ||
# Retain installed node modules between runs. Production always installs them fresh anyways (npm ci). | ||
# We can't use the deps from a host because windows and linux deps are different | ||
# VOLUME [ "/home/node/app/node_modules" ] | ||
|
||
WORKDIR /home/node/app | ||
WORKDIR /app | ||
|
||
# Install node modules | ||
# Copy in node requirements definitions | ||
COPY ["package.json", "package-lock.json*", "./"] | ||
# TODO find a way to toggle between dev and prod | ||
RUN npm install | ||
# RUN npm install --production | ||
|
||
|
||
|
||
# ===================================================================================================== | ||
# Only reinstall dependencies when needed | ||
FROM base as build_deps | ||
WORKDIR /app | ||
|
||
RUN npm ci | ||
|
||
|
||
|
||
# ===================================================================================================== | ||
FROM build_deps AS development | ||
WORKDIR /app | ||
|
||
# The source code will be bind monuted in via docker compose, so we don't need to copy it in here | ||
|
||
ENV NODE_ENV=development | ||
# Enable hot reload functionality https://github.com/vercel/next.js/issues/36774#issuecomment-1444286244 | ||
ENV WATCHPACK_POLLING=true | ||
CMD npm run dev | ||
|
||
|
||
# ===================================================================================================== | ||
# Below based on https://github.com/vercel/next.js/blob/7fde79a9e840f3c73b60b49dd7df6849d332d07d/examples/with-docker/Dockerfile | ||
FROM base AS builder | ||
WORKDIR /app | ||
|
||
COPY --from=build_deps /app/node_modules ./node_modules | ||
# Copy the rest of the source files over | ||
COPY [".", "./"] | ||
|
||
# TODO find a way to toggle between dev and normal npm run (env var?) | ||
# ENTRYPOINT [ "npm", "run", "start" ] | ||
ENTRYPOINT [ "npm", "run", "dev" ] | ||
RUN npm run build | ||
|
||
|
||
# ===================================================================================================== | ||
# Below based on https://github.com/vercel/next.js/blob/7fde79a9e840f3c73b60b49dd7df6849d332d07d/examples/with-docker/Dockerfile | ||
FROM base AS runner | ||
WORKDIR /app | ||
|
||
ENV NODE_ENV=production | ||
|
||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
|
||
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 | ||
|
||
ENV PORT=$FRONTEND_WEBSERVER_PORT | ||
|
||
CMD ["node", "server.js"] |
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
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
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
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