Skip to content

build(api): reproducible Railway API image with pnpm --frozen-lockfile - #759

Merged
unjica merged 3 commits into
developfrom
codex/api-frozen-lockfile
Oct 9, 2026
Merged

unjica merged 3 commits into
developfrom
codex/api-frozen-lockfile

Conversation

@unjica

@unjica unjica commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The production api service (plus retention-cron, alert-rules-evaluator, alert-webhook-worker) builds with Railpack using Root Directory /apps/api. There's no lockfile in that directory, so Railpack falls back to npm. Railway build log, Oct 6 08:30 UTC: npm install → added 193 packages → npm run build. Railway config, read-only: builder: RAILPACK, rootDirectory: /apps/api, no build or start command overrides. As a result:

  • pnpm-lock.yaml and the root pnpm.overrides don't describe what runs, so Dependabot alerts for the API are misleading.
  • Every deploy re-resolves versions, so builds aren't reproducible (prod has Prisma 6.19.3, the lockfile has 6.19.2).

There's no railway.json/railway.toml/nixpacks.toml/Procfile. The repo-root Dockerfile is the dashboard image and already uses --frozen-lockfile.

Change

  • New apps/api/Dockerfile with the repo root as build context. It uses node:22-slim plus openssl, pins pnpm 9.15.9 via corepack (matches packageManager), runs pnpm install --frozen-lockfile --filter api..., then pnpm --filter api build (api-version, prisma generate, tsc) and pnpm --filter api deploy --prod, copies dist, and runs prisma generate. The runtime is /app, running node dist/index.js. The entrypoint and the prisma migrate deploy-before-listen behavior are unchanged. Cron/worker start commands (node dist/jobs/...) work as they are.
  • apps/api fastify ^5.8.5 → ^5.12.5. Root overrides: find-my-way ^9.9.0, fast-uri@3 ^3.1.8, fast-uri@4 ^4.2.1. Without these, the frozen lockfile would downgrade prod from the patched versions npm currently resolves to the vulnerable lockfile versions (fastify GHSA-p68q-wchp-6fh7 and others, find-my-way GHSA-c96f-x56v-gq3h, the fast-uri SSRF/host confusion advisories). The lockfile diff is limited to those packages, plus process-warning 5.1.0 and a deduplicated fast-json-stringify.
  • docs/RAILWAY.md is updated with the new API settings.

Verification (MacBook, Docker linux/amd64)

  • docker build --platform linux/amd64 -f apps/api/Dockerfile . succeeds.
  • The container ran against a throwaway Postgres 16 with dummy env: migrations applied, it listened on 0.0.0.0:8080, and GET /health returned 200 {"ok":true,"database":"ok"}. node dist/jobs/run-retention.js --dry-run returned ok.
  • Locally: pnpm install --frozen-lockfile is clean, pnpm --filter api build passes, pnpm lint passes, and API tests show 1044 passed / 128 skipped (DB integration tests).

Version diff (prod today via npm, inferred → this image)

pkg lockfile on develop prod today (npm, inferred) this image
fastify 5.8.5 5.12.5 5.12.5
find-my-way 9.6.0 9.9.0 9.9.0
fast-uri 3.1.3 / 4.1.0 3.1.8 / 4.2.1 3.1.8 / 4.2.1
prisma / @prisma/client 6.19.2 6.19.3 (build log) 6.19.3 (6.19.3 only bumps effect for a security fix)
Node — v22.23.3 (railway ssh api) 22.23.3

Rollout: Railway settings to change (nothing has been changed)

Merging alone changes nothing about how Railway builds, because it stays on Railpack. Per service (api first, then retention-cron, alert-rules-evaluator, alert-webhook-worker):

  1. Settings → Source → Root Directory: empty (currently /apps/api).
  2. Settings → Build → Builder: Dockerfile, then set the variable RAILWAY_DOCKERFILE_PATH=apps/api/Dockerfile. Without it, Railway would pick up the repo-root dashboard Dockerfile.
  3. Leave no custom build command, and keep the start command empty for api. Cron/worker services keep node dist/jobs/....
  4. Watch paths: /apps/api/**, /pnpm-lock.yaml, /package.json. The current /apps/api/** would skip lockfile-only changes.
  5. Check that the deploy log shows pnpm install --frozen-lockfile, that GET https://api.telemetry-tracker.com/health is ok, and that the cron runs succeed.

Rollback

Switch the service back to Root Directory /apps/api and Builder Railpack, delete RAILWAY_DOCKERFILE_PATH, and redeploy. Or redeploy the last successful deployment. The Dockerfile has no effect while the service uses Railpack.

Update after the v1.18.4 sync

Merged the current develop. Prisma is aligned to 6.19.3. The image was re-verified against a throwaway pg16: migrate deploy and status, API /health 200 with database ok, retention --dry-run ok, the alert-rules-evaluator sweep ok (warns that email isn't configured with dummy env), and alert-webhook-worker --once ok (idle, exit 0). The image includes OpenSSL 3.0, libquery_engine-debian-openssl-3.0.x, all dist/jobs entrypoints, prisma/schema and 50 migrations, and assets/email-logo.png.

unjica added 3 commits October 9, 2026 20:12
Add apps/api/Dockerfile (repo-root context, corepack [email protected],
pnpm install --frozen-lockfile --filter api..., pnpm deploy --prod).
Bump fastify to ^5.12.5 and override find-my-way/fast-uri so the
locked build is at least as patched as the current npm-resolved prod.
Update docs/RAILWAY.md.
@unjica
unjica merged commit 7f48bea into develop Oct 9, 2026
7 checks passed
@unjica unjica mentioned this pull request Oct 9, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant