2022-02-11 02:36:07 +03:00
|
|
|
# This Dockerfile is used for docker-based deployments to Azure for both preview environments and production
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
# --------------------------------------------------------------------------------
|
2021-05-25 01:40:50 +03:00
|
|
|
# BASE IMAGE
|
|
|
|
# --------------------------------------------------------------------------------
|
2023-01-23 19:00:25 +03:00
|
|
|
# To update the sha, run `docker pull node:$VERSION-alpine`
|
|
|
|
# look for something like: `Digest: sha256:0123456789abcdef`
|
2023-05-05 18:41:18 +03:00
|
|
|
FROM node:18.16-alpine@sha256:1ccc70acda680aa4ba47f53e7c40b2d4d6892de74817128e0662d32647dd7f4d as base
|
2021-05-25 01:40:50 +03:00
|
|
|
|
2022-01-24 20:35:52 +03:00
|
|
|
# This directory is owned by the node user
|
|
|
|
ARG APP_HOME=/home/node/app
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2022-01-24 20:35:52 +03:00
|
|
|
# Make sure we don't run anything as the root user
|
|
|
|
USER node
|
|
|
|
|
|
|
|
WORKDIR $APP_HOME
|
2021-05-25 01:40:50 +03:00
|
|
|
|
|
|
|
|
|
|
|
# ---------------
|
|
|
|
# ALL DEPS
|
|
|
|
# ---------------
|
|
|
|
FROM base as all_deps
|
|
|
|
|
2022-02-02 03:26:22 +03:00
|
|
|
COPY --chown=node:node package.json package-lock.json ./
|
2021-05-25 01:40:50 +03:00
|
|
|
|
2022-02-10 23:14:40 +03:00
|
|
|
RUN npm ci --no-optional --registry https://registry.npmjs.org/
|
2021-05-25 01:40:50 +03:00
|
|
|
|
2022-01-11 23:37:24 +03:00
|
|
|
# For Next.js v12+
|
2023-01-23 19:00:25 +03:00
|
|
|
# This the appropriate necessary extra for node:VERSION-alpine
|
2022-01-07 21:34:10 +03:00
|
|
|
# Other options are https://www.npmjs.com/search?q=%40next%2Fswc
|
2023-01-24 22:03:42 +03:00
|
|
|
RUN npm i @next/swc-linux-x64-musl --no-save || npm i @next/swc-linux-arm64-musl --no-save
|
2022-01-07 21:34:10 +03:00
|
|
|
|
2021-05-25 01:40:50 +03:00
|
|
|
|
|
|
|
# ---------------
|
|
|
|
# PROD DEPS
|
|
|
|
# ---------------
|
|
|
|
FROM all_deps as prod_deps
|
|
|
|
|
|
|
|
RUN npm prune --production
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------
|
|
|
|
# BUILDER
|
|
|
|
# ---------------
|
|
|
|
FROM all_deps as builder
|
|
|
|
|
2020-09-27 15:10:11 +03:00
|
|
|
COPY stylesheets ./stylesheets
|
2021-05-25 01:40:50 +03:00
|
|
|
COPY pages ./pages
|
|
|
|
COPY components ./components
|
2020-09-27 15:10:11 +03:00
|
|
|
COPY lib ./lib
|
2023-02-11 03:38:27 +03:00
|
|
|
COPY src ./src
|
2023-05-02 14:41:43 +03:00
|
|
|
# The star is because it's an optional directory
|
|
|
|
COPY .remotejson-cache* ./.remotejson-cache
|
2022-06-28 15:57:38 +03:00
|
|
|
# Certain content is necessary for being able to build
|
2021-05-25 01:40:50 +03:00
|
|
|
COPY content/index.md ./content/index.md
|
2022-06-28 15:57:38 +03:00
|
|
|
COPY content/rest ./content/rest
|
|
|
|
COPY data ./data
|
2021-05-25 01:40:50 +03:00
|
|
|
|
|
|
|
COPY next.config.js ./next.config.js
|
|
|
|
COPY tsconfig.json ./tsconfig.json
|
|
|
|
|
2021-02-02 01:25:49 +03:00
|
|
|
RUN npm run build
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
# --------------------------------------------------------------------------------
|
2022-02-03 00:05:20 +03:00
|
|
|
# PREVIEW IMAGE - no translations
|
2021-05-25 01:40:50 +03:00
|
|
|
# --------------------------------------------------------------------------------
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2022-02-03 00:05:20 +03:00
|
|
|
FROM base as preview
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2022-02-03 00:05:20 +03:00
|
|
|
# Copy just prod dependencies
|
2022-01-24 20:35:52 +03:00
|
|
|
COPY --chown=node:node --from=prod_deps $APP_HOME/node_modules $APP_HOME/node_modules
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
# Copy our front-end code
|
2022-01-24 20:35:52 +03:00
|
|
|
COPY --chown=node:node --from=builder $APP_HOME/.next $APP_HOME/.next
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
# We should always be running in production mode
|
|
|
|
ENV NODE_ENV production
|
|
|
|
|
2022-07-26 20:53:23 +03:00
|
|
|
# Preferred port for server.js
|
2021-12-17 19:51:47 +03:00
|
|
|
ENV PORT 4000
|
2021-02-02 01:25:49 +03:00
|
|
|
|
2023-01-13 20:52:48 +03:00
|
|
|
ENV ENABLED_LANGUAGES "en"
|
|
|
|
|
2022-05-11 22:14:30 +03:00
|
|
|
# This makes it possible to set `--build-arg BUILD_SHA=abc123`
|
|
|
|
# and it then becomes available as an environment variable in the docker run.
|
|
|
|
ARG BUILD_SHA
|
|
|
|
ENV BUILD_SHA=$BUILD_SHA
|
|
|
|
|
2020-09-27 15:10:11 +03:00
|
|
|
# Copy only what's needed to run the server
|
2022-01-05 18:42:53 +03:00
|
|
|
COPY --chown=node:node package.json ./
|
2020-09-27 15:10:11 +03:00
|
|
|
COPY --chown=node:node assets ./assets
|
2021-12-17 19:51:47 +03:00
|
|
|
COPY --chown=node:node content ./content
|
2020-09-27 15:10:11 +03:00
|
|
|
COPY --chown=node:node lib ./lib
|
2023-02-11 03:38:27 +03:00
|
|
|
COPY --chown=node:node src ./src
|
2023-05-02 14:41:43 +03:00
|
|
|
COPY --chown=node:node .remotejson-cache* ./.remotejson-cache
|
2020-09-27 15:10:11 +03:00
|
|
|
COPY --chown=node:node middleware ./middleware
|
2021-12-17 19:51:47 +03:00
|
|
|
COPY --chown=node:node data ./data
|
2021-07-21 16:54:07 +03:00
|
|
|
COPY --chown=node:node next.config.js ./
|
2022-07-26 20:53:23 +03:00
|
|
|
COPY --chown=node:node server.js ./server.js
|
|
|
|
COPY --chown=node:node start-server.js ./start-server.js
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2021-11-13 21:17:47 +03:00
|
|
|
EXPOSE $PORT
|
|
|
|
|
2022-07-26 20:53:23 +03:00
|
|
|
CMD ["node", "server.js"]
|
2021-09-03 19:34:48 +03:00
|
|
|
|
|
|
|
# --------------------------------------------------------------------------------
|
2022-02-03 00:05:20 +03:00
|
|
|
# PRODUCTION IMAGE - includes all translations
|
2021-09-03 19:34:48 +03:00
|
|
|
# --------------------------------------------------------------------------------
|
2022-02-03 00:05:20 +03:00
|
|
|
FROM preview as production
|
2021-09-03 19:34:48 +03:00
|
|
|
|
2023-01-13 20:52:48 +03:00
|
|
|
# Override what was set for previews
|
|
|
|
# Make this match the default of `Object.keys(languages)` in lib/languages.js
|
2023-03-14 23:30:58 +03:00
|
|
|
ENV ENABLED_LANGUAGES "en,zh,es,pt,ru,ja,fr,de,ko"
|
2023-01-13 20:52:48 +03:00
|
|
|
|
2022-02-03 00:05:20 +03:00
|
|
|
# Copy in all translations
|
|
|
|
COPY --chown=node:node translations ./translations
|