Files
Prerender-PM2-FSCache-Server/docker-compose.yml
T

60 lines
2.3 KiB
YAML

# prerender server with pm2 and prerender-plugin-fscache (file system based so
# resolves caching issues with pm2 and prerender-memory-cache)
#
# docker compose exec prerender pm2 monit
services:
prerender:
build: .
image: ${IMAGE:-prerender}
container_name: ${CONTAINER_NAME:-prerender}
user: node
restart: unless-stopped
init: true # makes all the difference, no more timeout (not always) / restarts without chrome alive
expose:
- "3000"
- "9222"
environment:
- PATH=/home/node/node_modules/pm2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- VIRTUAL_PORT=3000
- VIRTUAL_HOST=${LETSENCRYPT_HOST}
- LETSENCRYPT_HOST=${LETSENCRYPT_HOST}
- LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL}
- LETSENCRYPT_TEST=${LETSENCRYPT_TEST:-false}
- CHROME_LOCATION=/usr/bin/chromium
- PAGE_LOAD_TIMEOUT=${PAGE_LOAD_TIMEOUT:-15000} # was 3000: too tight for a cold SPA, prerender gave up with splash/empty DOM and (with TIMEOUT_STATUS_CODE unset) cached those partial renders as 200 for 24h
# a timed-out render must NOT look like a success: 504 is not in CACHE_STATUS_CODES,
# so partial snapshots are never written to the cache
- TIMEOUT_STATUS_CODE=${TIMEOUT_STATUS_CODE:-504}
- NODE_ENV=production
- PHANTOM_WORKERS=${PHANTOM_WORKERS} # legacy, ignored: instances is fixed to 1 (see ecosystem.config.js)
# prerender-plugin-fscache to the rescue
# only cache clean results, and only for 1h so any bad entry self-heals quickly
# (404 was removed: a transient 404 used to be frozen for a full day)
- CACHE_STATUS_CODES=${CACHE_STATUS_CODES:-200,301,302}
- CACHE_TTL=${CACHE_TTL:-3600}
- CACHE_PATH=/home/node/prerender-cache
- CACHE_VOLUME=${CACHE_VOLUME:-prerender-cache}
networks:
letsencrypt:
default:
entrypoint: ["pm2-runtime", "start", "ecosystem.config.js"]
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
volumes:
- ./ecosystem.config.js:/home/node/ecosystem.config.js
- ./server.js:/home/node/server.js
- prerender-cache:/home/node/prerender-cache
networks:
letsencrypt:
external: true
volumes:
prerender-cache:
name: ${CACHE_VOLUME}