diff --git a/deploy/compose-build-at-deploy.yml b/deploy/compose-build-at-deploy.yml index 5cdba13..0855ee2 100644 --- a/deploy/compose-build-at-deploy.yml +++ b/deploy/compose-build-at-deploy.yml @@ -36,6 +36,14 @@ # the registry-image path (docker-compose.yml) and is NOT read here. A change to the limits # has to be made in both, or the two deployment shapes diverge. # +# 4. nginx resolves `api` through a VARIABLE, not by name. A plain `proxy_pass http://api:3000` +# is resolved once, when nginx starts, and the address is then pinned for the life of the +# container: recreate the api — a deploy that changes its configuration, a `--force-recreate`, +# a manual restart that gives it a new IP — and every /api call answers 502 until the web +# container is restarted too, including /api/config, so the app cannot even load. The +# `resolver` + `set $api_upstream` pair below makes nginx ask again on every request, which is +# the same fix web/nginx.conf.template carries (and explains at length) for the other shape. +# # To deploy a change to the code, force the one-shot services to run again — `source` and # `web-build` have `restart: "no"`, so compose leaves them alone when their configuration has not # changed: @@ -192,7 +200,7 @@ services: command: - /bin/sh - -c - - "printf 'server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; client_max_body_size 5m; location /api/vitals/ingest { client_max_body_size 32m; proxy_pass http://api:3000; proxy_http_version 1.1; proxy_set_header Host $$host; proxy_set_header X-Real-IP $$remote_addr; proxy_set_header X-Forwarded-For $$remote_addr; proxy_set_header X-Forwarded-Proto $$scheme; } location /api/ { proxy_pass http://api:3000; proxy_http_version 1.1; proxy_set_header Host $$host; proxy_set_header X-Real-IP $$remote_addr; proxy_set_header X-Forwarded-For $$remote_addr; proxy_set_header X-Forwarded-Proto $$scheme; } location / { try_files $$uri $$uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'" + - "printf 'server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; client_max_body_size 5m; resolver 127.0.0.11 valid=10s ipv6=off; set $$api_upstream http://api:3000; location /api/vitals/ingest { client_max_body_size 32m; proxy_pass $$api_upstream; proxy_http_version 1.1; proxy_set_header Host $$host; proxy_set_header X-Real-IP $$remote_addr; proxy_set_header X-Forwarded-For $$remote_addr; proxy_set_header X-Forwarded-Proto $$scheme; } location /api/ { proxy_pass $$api_upstream; proxy_http_version 1.1; proxy_set_header Host $$host; proxy_set_header X-Real-IP $$remote_addr; proxy_set_header X-Forwarded-For $$remote_addr; proxy_set_header X-Forwarded-Proto $$scheme; } location / { try_files $$uri $$uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'" restart: unless-stopped volumes: