diff --git a/Dockerfile b/Dockerfile index 51cbf889..e7895887 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,19 +3,26 @@ FROM node:20-alpine AS base # Install dependencies only when needed FROM base AS dev # 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 +# libc6-compat & gcompat are needed for native modules (e.g. esbuild) on alpine. +# openssl is required for HTTPS requests (Octokit). +# git is required for husky, lint-staged, and metadata scripts. +RUN apk add --no-cache libc6-compat gcompat openssl git WORKDIR /docs ENV NODE_ENV=development ENV NEXT_TELEMETRY_DISABLED=1 -COPY . . +# Install dependencies separately to leverage Docker cache +COPY package.json package-lock.json ./ +# Bypass postinstall since it requires source code which isn't copied yet +RUN npm pkg delete scripts.postinstall && npm install -RUN npm install +# Copy source code +COPY . . -CMD ["npm", "run", "dev"] +# Generate search-meta at runtime so it populates the mounted volume, then start dev +CMD ["sh", "-c", "npm run search-meta:gen && npm run dev"] # Rebuild the source code only when needed FROM dev AS builder @@ -41,6 +48,7 @@ ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 RUN set -xe; \ + apk add --no-cache openssl; \ addgroup --system --gid 1001 nodejs; \ adduser --system --uid 1001 nextjs diff --git a/README.md b/README.md index d211cbde..02434020 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ It is deployed on the [Unikraft website](https://unikraft.org/) It provides information for the latest version of [Unikraft](https://github.com/unikraft/unikraft) and [KraftKit](https://kraftkit.sh). Documentation is written in [MDX](https://mdxjs.com/) format. -Building and deploying it requires Node and NPM. +Building and deploying it requires Node and npm. You can build and run either natively or using Docker. ## Building and Testing Natively @@ -29,7 +29,7 @@ For local development: ```console docker build -t ghcr.io/unikraft/docs:dev --target dev . -docker run -it --rm -v $(pwd):/docs -w /docs -p 3000:3000 ghcr.io/unikraft/docs:dev +docker run -it --rm -v $(pwd):/docs -v unikraft_modules:/docs/node_modules -w /docs -p 3000:3000 ghcr.io/unikraft/docs:dev ``` For production deployment: