Fix Docker build: compile TypeScript packages before runtime stage
The API Docker image was copying raw .ts source files for @groombook/db and @groombook/types into the runtime stage, but tsx (the TS loader) is a devDependency stripped by --prod install. Node.js cannot load .ts files natively, causing ERR_UNKNOWN_FILE_EXTENSION at startup. - Add build scripts to db and types packages - Add outDir to types tsconfig - Update package.json main fields to point to compiled dist/ - Build packages in dependency order in Dockerfile - Copy only dist output to runtime stage Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
+7
-3
@@ -14,7 +14,9 @@ RUN pnpm install --frozen-lockfile
|
|||||||
FROM deps AS builder
|
FROM deps AS builder
|
||||||
COPY packages/ packages/
|
COPY packages/ packages/
|
||||||
COPY apps/api/ apps/api/
|
COPY apps/api/ apps/api/
|
||||||
RUN pnpm --filter @groombook/api build
|
RUN pnpm --filter @groombook/types build && \
|
||||||
|
pnpm --filter @groombook/db build && \
|
||||||
|
pnpm --filter @groombook/api build
|
||||||
|
|
||||||
# Runtime
|
# Runtime
|
||||||
FROM node:20-alpine AS runner
|
FROM node:20-alpine AS runner
|
||||||
@@ -29,8 +31,10 @@ COPY packages/types/package.json packages/types/
|
|||||||
RUN pnpm install --frozen-lockfile --prod
|
RUN pnpm install --frozen-lockfile --prod
|
||||||
|
|
||||||
COPY --from=builder /app/apps/api/dist apps/api/dist
|
COPY --from=builder /app/apps/api/dist apps/api/dist
|
||||||
COPY --from=builder /app/packages/db packages/db
|
COPY --from=builder /app/packages/db/dist packages/db/dist
|
||||||
COPY --from=builder /app/packages/types packages/types
|
COPY --from=builder /app/packages/db/package.json packages/db/package.json
|
||||||
|
COPY --from=builder /app/packages/types/dist packages/types/dist
|
||||||
|
COPY --from=builder /app/packages/types/package.json packages/types/package.json
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["node", "apps/api/dist/index.js"]
|
CMD ["node", "apps/api/dist/index.js"]
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
"name": "@groombook/db",
|
"name": "@groombook/db",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "./src/index.ts",
|
"main": "./dist/index.js",
|
||||||
"types": "./src/index.ts",
|
"types": "./src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
"generate": "drizzle-kit generate",
|
"generate": "drizzle-kit generate",
|
||||||
"migrate": "drizzle-kit migrate",
|
"migrate": "drizzle-kit migrate",
|
||||||
"seed": "tsx src/seed.ts",
|
"seed": "tsx src/seed.ts",
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
"name": "@groombook/types",
|
"name": "@groombook/types",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "./src/index.ts",
|
"main": "./dist/index.js",
|
||||||
"types": "./src/index.ts",
|
"types": "./src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noUncheckedIndexedAccess": true,
|
"noUncheckedIndexedAccess": true,
|
||||||
"skipLibCheck": true
|
"skipLibCheck": true,
|
||||||
|
"outDir": "./dist"
|
||||||
},
|
},
|
||||||
"include": ["src"]
|
"include": ["src"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user