diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..90e4911 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +docker-entrypoint.sh text eol=lf diff --git a/Dockerfile b/Dockerfile index 0afda28..f64e202 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,15 @@ -# Build context: this repository root (gregWiki). -# Runs the Docusaurus dev server with hot reload. +# Build context MUST be this repository root (directory containing package.json). +# Correct: docker build -t gregwiki . +# Wrong: docker build -f gregWiki/Dockerfile .. → COPY fails or image has no package.json +# Dev server with hot reload. For production static files use: npm run build + any static host. FROM node:20-alpine WORKDIR /app ENV NODE_OPTIONS="--max-old-space-size=4096" +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +RUN chmod +x /usr/local/bin/docker-entrypoint.sh COPY package.json package-lock.json ./ RUN npm ci --ignore-scripts COPY . . EXPOSE 3000 +ENTRYPOINT ["docker-entrypoint.sh"] CMD ["npm", "run", "start", "--", "--host", "0.0.0.0", "--port", "3000"] diff --git a/README.md b/README.md index 174e914..af6fe74 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,11 @@ Optional: refresh the legacy GitHub Wiki mirror from a sibling `../.wiki/` clone ## Docker -Build context is this repository root: +Build context **must** be this repository root (the folder that contains `package.json`): ```bash +docker compose up --build +# or docker build -t gregwiki-docs . docker run --rm -p 3000:3000 gregwiki-docs ``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cf1ee0a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +# Run from this directory (gregWiki repo root): docker compose up --build +# Wrong context (e.g. monorepo parent) causes: ENOENT /app/package.json +services: + wiki: + build: + context: . + dockerfile: Dockerfile + ports: + - '3000:3000' + environment: + CHOKIDAR_USEPOLLING: 'true' diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 50dbaf9..6b931fc 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,14 +1,12 @@ #!/bin/sh set -e -# Prefer wiki subfolder when the repo root is mounted at /app (root also has package.json). -# Otherwise use /app when only ./wiki is bound there (compose: ./wiki:/app). -if [ -f /app/wiki/package.json ]; then - cd /app/wiki -elif [ -f /app/package.json ]; then - cd /app -else - echo "docker-entrypoint: no package.json under /app or /app/wiki." >&2 - echo "Run docker compose from the repository root so ./wiki is mounted, then: docker compose build --no-cache docs" >&2 +if [ ! -f /app/package.json ]; then + echo "docker-entrypoint: ERROR: /app/package.json not found." >&2 + echo " Build context must be the gregWiki repo root (the folder that contains package.json)." >&2 + echo " Example: cd path/to/gregWiki && docker build -t gregwiki ." >&2 + echo " Not: docker build -f gregWiki/Dockerfile .. (wrong context)" >&2 + echo " Compose: run from gregWiki so build.context is '.' — see docker-compose.yml." >&2 + echo " If you use a volume on /app, it must map to that repo root, not an empty dir." >&2 exit 1 fi exec "$@" diff --git a/package.json b/package.json index f64f0c2..1f48dd8 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "wiki:sync": "node ./scripts/sync-wiki-to-docs.mjs", "wiki:normalize-i18n": "node ./scripts/normalize-wiki-import-i18n.mjs", "wiki:refresh": "node ./scripts/sync-wiki-to-docs.mjs && node ./scripts/normalize-wiki-import-i18n.mjs", - "format": "prettier --write src scripts docusaurus.config.js sidebars.js README.md docs/README.md package.json .prettierrc.json", - "format:check": "prettier --check src scripts docusaurus.config.js sidebars.js README.md docs/README.md package.json .prettierrc.json" + "format": "prettier --write src scripts docusaurus.config.js sidebars.js README.md docs/README.md package.json .prettierrc.json docker-compose.yml", + "format:check": "prettier --check src scripts docusaurus.config.js sidebars.js README.md docs/README.md package.json .prettierrc.json docker-compose.yml" }, "dependencies": { "@docusaurus/core": "3.9.2",