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`
|
2024-08-28 01:03:18 +03:00
|
|
|
FROM node:20-alpine@sha256:66f7f89199daea88a6b5d5aadaa6d20f7a16a90fc35274deda8e901e267d4bd7 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
|
|
|
|
# ---------------
|
2024-08-28 01:03:18 +03:00
|
|
|
FROM base AS all_deps
|
2021-05-25 01:40:50 +03:00
|
|
|
|
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
|
|
|
|
# ---------------
|
2024-08-28 01:03:18 +03:00
|
|
|
FROM all_deps AS prod_deps
|
2021-05-25 01:40:50 +03:00
|
|
|
|
|
|
|
RUN npm prune --production
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------
|
|
|
|
# BUILDER
|
|
|
|
# ---------------
|
2024-08-28 01:03:18 +03:00
|
|
|
FROM all_deps AS builder
|
2021-05-25 01:40:50 +03:00
|
|
|
|
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
|
2024-01-05 18:21:00 +03:00
|
|
|
# The star is because it's an optional file
|
2024-01-10 01:10:46 +03:00
|
|
|
COPY .pageinfo-cache.json.br* ./.pageinfo-cache.json.br
|
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
|
|
|
|
2024-08-28 01:03:18 +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
|
2024-08-28 01:03:18 +03:00
|
|
|
ENV NODE_ENV=production
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2022-07-26 20:53:23 +03:00
|
|
|
# Preferred port for server.js
|
2024-08-28 01:03:18 +03:00
|
|
|
ENV PORT=4000
|
2021-02-02 01:25:49 +03:00
|
|
|
|
2024-08-28 01:03:18 +03:00
|
|
|
ENV ENABLED_LANGUAGES="en"
|
2023-01-13 20:52:48 +03:00
|
|
|
|
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
|
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
|
2024-01-10 21:33:19 +03:00
|
|
|
COPY --chown=node:node .pageinfo-cache.json.br* ./.pageinfo-cache.json.br
|
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 ./
|
2024-05-06 23:07:34 +03:00
|
|
|
COPY --chown=node:node tsconfig.json ./
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2021-11-13 21:17:47 +03:00
|
|
|
EXPOSE $PORT
|
|
|
|
|
2024-03-28 21:18:57 +03:00
|
|
|
CMD ["node_modules/.bin/tsx", "src/frame/server.ts"]
|
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
|
|
|
# --------------------------------------------------------------------------------
|
2024-08-28 01:03:18 +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
|
2023-11-03 01:46:32 +03:00
|
|
|
# Make this match the default of `Object.keys(languages)` in src/languages/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
|