Commit Graph
5 Commits
Author SHA1 Message Date
dsantillan 7271dadbee The deploy path's nginx: re-resolve the api on every request
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
A plain `proxy_pass http://api:3000` is resolved once, when nginx starts, and the
address stays pinned for the life of the container. Recreate the api — a deploy that
changes its configuration, a --force-recreate, any restart that hands it a new IP — and
the web container keeps talking to a dead address: every /api call answers 502, including
/api/config, so the app cannot even boot. That is not hypothetical: it is what happened on
gym.dploy.lol, where restarting the api to pick up new code produced 502 on every endpoint
until the web container was restarted too.

The generated config now asks Docker's embedded DNS again on every request instead:
`resolver 127.0.0.11` plus `set $api_upstream http://api:3000` and `proxy_pass
$api_upstream`. This is the same fix web/nginx.conf.template has carried for the
registry-image shape (with a comment explaining issue #16), and comment 4 at the top of
this file now records why the deploy path needs it too.

Verified by rendering the command exactly as the container runs it and passing the result
through an nginx config parser: both body limits in place, both locations on the variable,
and the upstream still resolved through the embedded resolver.
2026-09-23 11:01:01 -04:00
dsantillan 5eb0a5298a The deploy path's api container now keeps itself on the clone's revision
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
gym.dploy.lol runs deploy/compose-build-at-deploy.yml, and that stack has an asymmetry
that has now cost two deploys: `web` serves the frontend build out of a shared volume, so
every deploy refreshes the app by itself, while `api` copies the clone INTO its container
at start-up. Compose recreates a service only when its configuration or image changed, and
the clone is a volume, so neither does — the api kept running the previous revision while
the frontend moved on.

That is invisible from the outside except as a route that answers 404 although the screen
that calls it is already deployed and visibly new, which is exactly what "Crear clave de
ingesta → not found" was: POST /api/vitals/key hitting last week's server.

The api's command is now a small loop instead of a one-liner: it syncs /app from the
clone whenever the clone's revision changes, restarts the server on it, and starts it
again if it ever exits (the old one-liner left that to the container restart policy, which
also meant a full re-copy every time). Dependencies are reinstalled only when
package.json itself changed, so a deploy costs a couple of seconds of downtime rather
than a minute of npm install.

It is careful about the window a deploy opens: `source` does `rm -rf /work/repo` before it
re-clones, and the loop tests for api/server.js — a file a fresh clone writes and that
rm removes — so a deploy caught mid-clone is waited out instead of half-copied.

Two things this file has to get right, both verified rather than assumed. Every `$` in the
container's script is written `$$`, because compose interpolates `$VAR` in block scalars
too and an unescaped `$src` would have arrived empty (this is the same reason the web
service writes `$$host`). And the loop's control flow was simulated before pushing: first
start, a new clone, a package.json change, a server that dies, and a clone that disappears
mid-deploy and comes back — five paths, all as intended.
2026-09-23 10:44:49 -04:00
dsantillan ba37ef8a44 Deploy path: give the health ingest 32 MB, and stop appending to X-Forwarded-For
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
gym.dploy.lol does not run docker-compose.yml. It runs deploy/compose-build-at-deploy.yml,
where nginx is generated inline by the web service from a printf in its command, with a
single global `client_max_body_size 5m`. The per-route 32 MB added for the Apple Health
ingest lives in web/nginx.conf.template, which belongs to the registry-image path and is
never read here — so a first export of more than 5 MB came back as nginx's own 413 HTML
before the API saw a byte of it.

That path now has a second location for /api/vitals/ingest with 32m; nginx picks the
longest matching prefix, so that one route takes the bigger body and everything else
keeps matching the API's MAX_BODY. Both limits are spelled out in comment 3 at the top,
with a note that the two deployment shapes have to be changed together.

Also fixes a smaller thing found while reading it: X-Forwarded-For was
$proxy_add_x_forwarded_for, which APPENDS to whatever the client sent, and the API reads
the first entry — so a caller could choose the address recorded about it. It is now
$remote_addr, which is what web/nginx.conf.template already does and for the same reason
documented there. Audit IPs are off by default, so nothing was being recorded; this
matters the day somebody sets AUDIT_IP=net.

Comment 3 also now records the two things that make a deploy confusing rather than
broken: the api service copies the clone into /app at container start, so an api that was
not recreated keeps serving the previous revision while web-build serves the new frontend
(exactly the 404-on-a-new-route symptom), and web resolves api's IP once at start-up, so
recreating api without web leaves nginx pointing at a dead address and every /api call
answering 502.
2026-09-23 10:32:24 -04:00
dsantillan 40959de0a2 Forward the COACH_* variables to the api container in the deploy compose
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
The api service lists its environment explicitly, and that list is an allowlist:
a variable set in the host's .env reaches the container only when it is named
there. Everything else in the panel is used solely to substitute ${…} in the
compose file — which is how COACH_PROVIDER can sit in Dokploy looking applied
while the api never sees it, the Coach stays off, and no screen anywhere shows a
button. That is exactly what happened on this instance.

The `:-` defaults keep an instance that sets none of them byte-for-byte as it
was: an empty value reads as unset in coach/config.js.
2026-09-21 15:24:28 -04:00
dsantillan 1a48efdbcc Add deploy/compose-build-at-deploy.yml for hosts that build at deploy time
Tests / test (pull_request) Canceled after 0s
The instance at gym.dploy.lol runs a five-service stack that clones the source
and builds it on every deploy, rather than pulling the images
docker-compose.yml names. That shape has three requirements nothing in the
repository stated, and getting any of them wrong costs a deploy:

- web-build has to copy the whole repository and build from frontend/. The
  frontend imports the Coach's core from ../../../api/coach/core/, so a build
  stage holding only frontend/ fails with nine UNRESOLVED_IMPORT errors — the
  reason web/Dockerfile copies api/coach/core/ into its build stage.
- The volume names have to be pinned with `name:`. Unpinned, a restyled stack
  silently creates empty volumes and the profiles and training history look
  gone.
- nginx needs client_max_body_size. Its default request limit is 1 MB while the
  app PUTs the whole profile to /api/data and the API accepts 5 MB — the sync
  starts failing with a 413 the UI cannot explain once a history grows past 1 MB.
  web/nginx.conf.template already sets 5m; this matches it.

The file is the shape that instance runs, with its volume names filled in.
2026-09-21 14:38:38 -04:00