Add production compose stack and stop idle load in containers #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Grovy311/leistungsbilanz-ts:fix/production-deployment"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The development stack had been running permanently on a server. After five days the web container held 10.3 GB RSS, the API container burned a steady 12% CPU with nobody using the application, and the host had 13 GB of swap in use at load average 4.85.
Four causes combined:
CHOKIDAR_USEPOLLINGandWATCHPACK_POLLINGmadetsx watchwalk the source tree continuously./every 5 s./isredirect("/projects")and Node'sfetchfollows redirects, so every probe server-rendered the project list -- roughly 16,000 times a day.next devkeeps compilation state and grew unbounded; thenext-serverprocess had already been replaced once and was back at 10 GB within 12 hours.compose.yamlwas namedleistungsbilanz, the same as the production project, sodocker compose downin the development directory targeted the production stack.Changes
compose.prod.yaml: compiled output, separate api/web services, no bind mounts, no watchersDockerfilewithdevandprodtargets; the runtime image drops devDependencies and runs asnodeinstead of root/healthevery 30 s instead of/every 5 smem_limiton every service, plusmemswap_limitin production so a leak kills the container instead of the hostleistungsbilanz-dev, development ports bound to127.0.0.1SIGTERM/SIGINTnow close the HTTP server and the SQLite handle and exit, instead of only logging the signalscripts/docker-start.shexits when either supervised process dies, instead of leaving a container marked up while serving a dead APIdrizzle.config.js(a compiled copy drizzle-kit never reads) and the pre-Nextindex.html/styles.cssLatent bug found while verifying
Next.js resolves
next.config.mjsrewrites at build time and writes the literal destination into.next/routes-manifest.json.API_INTERNAL_URLset at runtime is therefore ignored bynext start-- the manifest contained a hardcodedhttp://localhost:3000. Server components read the variable correctly at runtime, but every browser call to/api/*goes through the baked rewrite. The single-container deployment only worked because both processes shared a localhost. Splitting the services would have broken all client-side writes.API_INTERNAL_URLis now a build argument;docs/deployment.mddocumented the previous behaviour incorrectly and has been corrected.Verification
npm test: 412/412 passbuild:api,build:web,typecheck:scripts,tsc --noEmit -p tsconfig.next.json: all cleannode,/health200,/api/projects200 through the rewritedocker stopcompletes in 392 ms with exit code 0, previously a 10 s timeout ending in SIGKILLA note for whoever deploys this: the production image runs as
node, so a data volume written by an earlier root container needs a one-timechown. The command is indocs/deployment.md.🤖 Generated with Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.