diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 00000000..277cc0bd --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,22 @@ +# Local development override for the React app. +# +# The base docker-compose.yml serves the production build (so the PWA service worker ships). This override runs +# the Create React App dev server instead, restoring hot reload. The dev server does not emit a service worker — +# that is expected; offline/PWA support is a production concern and is verified against a production build. +# +# Usage: +# docker compose -f docker-compose.yml -f docker-compose.dev.yml up +# +# (Production / end users just run `docker compose up`, which serves the built PWA.) +services: + app: + command: 'npm run start' + stdin_open: true + volumes: + - './app/public:/app/public' + - './app/src:/app/src' + - './app/package.json:/app/package.json' + - '.env:/app/.env' + environment: + # Force React to use the Caddy port for its dev-server websocket. + - WDS_SOCKET_PORT=0 diff --git a/docker-compose.yml b/docker-compose.yml index a0927dcc..e84133d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -92,20 +92,13 @@ services: build: context: . dockerfile: docker/app/Dockerfile - volumes: - - './app/public:/app/public' - - './app/src:/app/src' - - './app/package.json:/app/package.json' - - '.env:/app/.env' - command: 'npm run start' - stdin_open: true + # The image builds the production bundle and serves it (see docker/app/Dockerfile), so the PWA service worker + # ships. Rebuild the image (`docker compose build app`) to pick up code changes. For local development with + # hot reload, layer on docker-compose.dev.yml (runs the CRA dev server instead). healthcheck: test: [ 'CMD-SHELL', 'curl http://127.0.0.1:3000' ] interval: 1m user: '${UID-1000}:${GID-1000}' - environment: - # Force React to use Caddy port to connect to it's websocket. - - WDS_SOCKET_PORT=0 web: # Caddy reverse proxy - handles HTTPS for all services. depends_on: diff --git a/docker/README.md b/docker/README.md index d34b6c2f..06c81ead 100644 --- a/docker/README.md +++ b/docker/README.md @@ -13,11 +13,25 @@ docker volume create --name=openstreetmap-data docker volume create --name=openstreetmap-rendered-tiles docker-compose up -d db docker-compose run --rm api db upgrade -docker-compose up +# Development (React dev server, hot reload): +docker compose -f docker-compose.yml -f docker-compose.dev.yml up ``` Browse to https://localhost:8443 +### Production vs. development + +The base `docker-compose.yml` serves the **production** React build, which is what ships the installable PWA +and its offline service worker — this is what end users run: + +```bash +docker compose up # serves the built PWA (no hot reload; rebuild the app image to update) +``` + +For day-to-day frontend work, layer on `docker-compose.dev.yml` (as in the Quick Start above) to run the CRA +dev server with hot reload instead. The dev server does not emit a service worker, which is expected — verify +PWA/offline behavior against the production build. + ## Services | Service | Port(s) | Description | diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile index 46272c30..28788d11 100644 --- a/docker/app/Dockerfile +++ b/docker/app/Dockerfile @@ -9,7 +9,7 @@ USER root RUN npm install -g serve COPY app/public /app/public COPY app/src /app/src -COPY app/package.json app/package-lock.json app/tsconfig.json /app/ +COPY app/package.json app/package-lock.json app/tsconfig.json app/serve.json /app/ # "node" user will run the app after build. RUN chown -R node:node /app @@ -17,5 +17,9 @@ RUN chown -R node:node /app USER node RUN npm install -# Run the production build -CMD ["npm", "run", "start"] +# Build the production bundle (emits the PWA service worker; the dev server does not). +RUN npm run build + +# Serve the production build, matching the native wrolpi-app.service. serve.json keeps the SPA fallback while +# serving real files (service-worker.js, epub.html) directly. +CMD ["serve", "build", "-l", "3000", "-c", "/app/serve.json"]