Runtime images: install production dependencies only #250
Labels
No labels
dependencies
major
security-pin
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
trails-cool/trails#250
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 journal and planner runtime images install all dependencies, including dev dependencies. Each image is about 1.7 GB. The runtime images contain build tools that the apps do not use at runtime (Vite, React Router dev, Tailwind, Vitest, and others).
Two side effects:
esbuildbinaries. They give 146 Go standard-library advisories per image in the image scan (#249). The dashboard ignores these advisories now (IGNORED_IN_IMAGESin.forgejo/scripts/vuln-dashboard.py).package.jsondeclares, as dev dependencies. These imports work because Node searches up to/app/node_modules. An image with production dependencies only crashes at startup.Found on 2026-10-11:
apps/journalpostgres(server.ts),fit-file-parser,react-i18next,leaflet,react-leafletapps/plannerpostgres(server.ts),i18next,react-i18next,leaflet,react-leafletapps/plannerleaflet.markerclusterpackages/i18ni18next-browser-languagedetectorConstraint:
drizzle-kitin the journal imagecd-apps.ymlandcd-staging.ymlrunnpx drizzle-kit pushinside the journal image. So the journal image must keepdrizzle-kit, and with it bothesbuildbinaries.packages/db/drizzle.config.tsimportsdrizzle-kitas a value, and that import resolves frompackages/db/.Plan
dependenciesof the package that imports it.import-x/no-extraneous-dependenciestoeslint.config.jsfor app and package source, so that new undeclared imports fail lint.drizzle-kita dependency ofapps/journal. Changedrizzle.config.tsto a type-only import, so that the config does not resolvedrizzle-kitfrompackages/db/.prod-depsstage (pnpm install --frozen-lockfile --prod) to both Dockerfiles, and copy the runtimenode_modulesfrom that stage.drizzle-kit pushandmigrate-data.tsin the journal image, start both apps against a test database, and request their health and main pages.Later, optionally: move
drizzle-kitto a separate migration image. Then the journal image also losesesbuild, and theIGNORED_IN_IMAGESfilter can go.Status
Work is in progress on branch
prod-only-images.Implemented in #251. During the tests I found two more things:
@trails-cool/i18nand@trails-cool/gpxinto each app's server build, but leaves their dependencies as external imports. The app must declare them too. Lint cannot see this, soscripts/check-server-externals.mjsnow checks it in the Docker build.expo-sqlite,react-native,hermes-compiler, …) get installed. pnpm resolvesdrizzle-orm(optional peerexpo-sqlite) andreact-i18next(optional peerreact-native) with the mobile app's peers across the whole workspace. Possible fixes: separate peer resolution forapps/mobile, ordedupe-peer-dependents=false. This needs its own investigation.