Skip to content

fix: dockerize backend reliably and optimization - #11

Merged
AlexKalll merged 3 commits into
iCog-Labs-Dev:devfrom
AlexKalll:fix/backend-docker-setup
Aug 15, 2026
Merged

AlexKalll merged 3 commits into
iCog-Labs-Dev:devfrom
AlexKalll:fix/backend-docker-setup

Conversation

@AlexKalll

Copy link
Copy Markdown
Collaborator

What & Why

The backend couldn't run reliably in Docker: it crashed on startup,
demo users couldn't be seeded, and login from the frontend failed.
This PR fixes all three and slims down the build.

Fixes

  • App crash on startup - pinned @nestjs/swagger to 11.2.6
    (11.4.x breaks nestjs-zodERR_PACKAGE_PATH_NOT_EXPORTED).
  • Seeding in production - added seed:prod script that runs the
    compiled seeders from dist/ (plain seed needs ts-node, which is
    pruned from the production image). Seed is now idempotent + logs the
    created count; added a hint when ENABLE_DEMO_USERS_SEED is off.
  • Stale role - removed the unused Admin role from the role seed.
  • Regenerated package-lock.json with npm 11 (lockfileVersion 3).

Optimization (build time ~9 min → ~3s)

  • Dockerfile pins npm to 11.5.2 (matches lockfile).
  • Single npm ci in the builder stage + BuildKit cache mounts for the
    npm cache and the TypeScript incremental cache → near-instant rebuilds.
  • npm prune --omit=dev in the builder; pruned node_modules is copied
    into the runtime stage (no second full install).
  • app service: added healthcheck, init: true, and log-rotation
    limits.

How to test

cd <path-to-hyperdata-backend>
docker compose down -v --rmi all
docker compose build app
docker compose up -d
docker compose exec app npm run seed:prod

# login: via frontend 

- Pin @nestjs/swagger to 11.2.6 to fix ERR_PACKAGE_PATH_NOT_EXPORTED
  crash on startup (nestjs-zod incompatibility with 11.4.x)
- Pin npm to 11.5.2 in Dockerfile and add BuildKit cache mounts for
  npm and tsc so rebuilds are near-instant
- Prune dev deps in the builder stage and copy node_modules into the
  runtime stage instead of a second npm ci
- Add healthcheck, init, and log rotation limits for the app service
- Add seed:prod script that runs the compiled seeders (plain seed
  requires ts-node which is pruned from the production image)
- Make the demo-user seed idempotent and log how many users were
  created (skips existing users by email)
- Log a hint when ENABLE_DEMO_USERS_SEED is not enabled
- Remove the stale 'Admin' role from the role seed
- Regenerate package-lock.json (npm 11, lockfileVersion 3)
@AlexKalll
AlexKalll merged commit 8efb2a3 into iCog-Labs-Dev:dev Aug 15, 2026
2 checks passed
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