|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | + |
| 3 | +## Modified version of https://docusaurus.community/knowledge/deployment/docker/ |
| 4 | + |
| 5 | +# Stage 1: Base image. |
| 6 | +## Start with a base image containing NodeJS so we can build Docusaurus. |
| 7 | +FROM node:23.3.0-slim AS base |
| 8 | +## Disable colour output from yarn to make logs easier to read. |
| 9 | + |
| 10 | +## https://pnpm.io/docker |
| 11 | +ENV PNPM_HOME="/pnpm" |
| 12 | +ENV PATH="$PNPM_HOME:$PATH" |
| 13 | + |
| 14 | +ENV FORCE_COLOR=0 |
| 15 | +## Enable corepack. |
| 16 | +RUN corepack enable |
| 17 | +## Set the working directory to `/opt/docusaurus`. |
| 18 | +WORKDIR /opt/docusaurus |
| 19 | + |
| 20 | +## Required by docusaurus: [ERROR] Loading of version failed for version current |
| 21 | +RUN apt-get update && apt-get install -y git |
| 22 | + |
| 23 | +FROM base AS dev |
| 24 | +## Set the working directory to `/opt/docusaurus`. |
| 25 | +WORKDIR /opt/docusaurus |
| 26 | +## Expose the port that Docusaurus will run on. |
| 27 | +EXPOSE 3000 |
| 28 | +## Run the development server. |
| 29 | +CMD [ -d "node_modules" ] && npm run start -- --host 0.0.0.0 --poll 1000 || pnpm install && pnpm run start -- --host 0.0.0.0 --poll 1000 |
| 30 | + |
| 31 | +# Stage 2b: Production build mode. |
| 32 | +FROM base AS prod |
| 33 | +## Set the working directory to `/opt/docusaurus`. |
| 34 | +WORKDIR /opt/docusaurus |
| 35 | + |
| 36 | +COPY docs/package.json /opt/docusaurus/package.json |
| 37 | +COPY docs/package-lock.json /opt/docusaurus/package-lock.json |
| 38 | + |
| 39 | +## Install dependencies with `--immutable` to ensure reproducibility. |
| 40 | +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install |
| 41 | + |
| 42 | +## Copy over the source code. |
| 43 | +COPY docs/ /opt/docusaurus/ |
| 44 | +COPY packages/ /opt/packages/ |
| 45 | + |
| 46 | +## Required buy docusaurus [ERROR] Loading of version failed for version current |
| 47 | +COPY .git/ /opt/.git/ |
| 48 | + |
| 49 | +# Build from sources |
| 50 | +RUN pnpm run build |
| 51 | + |
| 52 | +# Stage 3a: Serve with `docusaurus serve`. |
| 53 | +FROM prod AS serve |
| 54 | +## Expose the port that Docusaurus will run on. |
| 55 | +EXPOSE 3000 |
| 56 | +## Run the production server. |
| 57 | +CMD ["npm", "run", "serve", "--", "--host", "0.0.0.0", "--no-open"] |
| 58 | + |
0 commit comments