Skip to content

Commit 671afd6

Browse files
fix: improve server dockerfile for monorepo build
1 parent b3135b8 commit 671afd6

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

packages/server/Dockerfile

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1-
FROM node:18-alpine
1+
FROM node:18-alpine AS base
2+
RUN corepack enable && corepack prepare pnpm@latest --activate
23

4+
FROM base AS builder
35
WORKDIR /app
46

5-
# Install pnpm
6-
RUN corepack enable && corepack prepare pnpm@latest --activate
7+
# Copy root files
8+
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml turbo.json ./
79

8-
# Copy everything
9-
COPY . .
10+
# Copy all package.json files first
11+
COPY packages/server/package.json ./packages/server/
12+
COPY packages/types/package.json ./packages/types/
13+
COPY packages/typescript-config/package.json ./packages/typescript-config/
1014

1115
# Install dependencies
1216
RUN pnpm install --frozen-lockfile
1317

18+
# Copy source code
19+
COPY packages/server ./packages/server
20+
COPY packages/types ./packages/types
21+
COPY packages/typescript-config ./packages/typescript-config
22+
1423
# Build
15-
WORKDIR /app/packages/server
16-
RUN pnpm build
24+
RUN pnpm --filter server build
25+
26+
FROM base AS runner
27+
WORKDIR /app
28+
29+
# Copy built files
30+
COPY --from=builder /app/packages/server/dist ./dist
31+
COPY --from=builder /app/packages/server/package.json ./package.json
32+
COPY --from=builder /app/node_modules ./node_modules
1733

18-
# Set environment
1934
ENV NODE_ENV=production
2035
ENV PORT=4000
2136

2237
EXPOSE 4000
2338

24-
# Run
2539
CMD ["node", "dist/index.js"]

0 commit comments

Comments
 (0)