Skip to content

Commit 40602bd

Browse files
committed
better dockerfile
1 parent 44a7290 commit 40602bd

File tree

3 files changed

+1107
-23
lines changed

3 files changed

+1107
-23
lines changed

Dockerfile

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1+
# Base stage
12
FROM node:22.21-alpine AS base
2-
3-
# Install Bun
43
RUN apk --no-cache add curl bash
54
RUN curl -fsSL https://bun.com/install | bash
65
ENV PATH="/root/.bun/bin:${PATH}"
7-
8-
FROM base AS builder
9-
106
WORKDIR /app
117

12-
COPY package.json bun.lockb ./
138

14-
COPY apps/server/package.json ./apps/server/
15-
COPY apps/client/package.json ./apps/client/
9+
FROM base AS install
1610

17-
RUN bun install
11+
# Development dependencies
12+
COPY package.json bun.lock /temp/dev/
13+
COPY apps/server/package.json /temp/dev/apps/server/
14+
COPY apps/client/package.json /temp/dev/apps/client/
15+
RUN cd /temp/dev && bun install --frozen-lockfile
1816

19-
COPY . .
17+
# Production dependencies
18+
COPY package.json bun.lock /temp/prod/
19+
COPY apps/server/package.json /temp/prod/apps/server/
20+
COPY apps/client/package.json /temp/prod/apps/client/
21+
RUN cd /temp/prod && bun install --frozen-lockfile --production --filter "server"
2022

23+
FROM base as prerelease
24+
COPY --from=install /temp/dev/node_modules node_modules
25+
COPY --from=install /temp/dev/apps/server/node_modules apps/server/node_modules
26+
COPY --from=install /temp/dev/apps/client/node_modules apps/client/node_modules
27+
COPY . .
28+
ENV NODE_ENV=production
2129
RUN bun run build
2230

23-
24-
31+
# Build stage
2532
FROM base
26-
27-
WORKDIR /app
28-
29-
COPY --from=builder /app/apps/server/dist ./apps/server/dist
30-
COPY --from=builder /app/apps/server/src/dbschema ./apps/server/src/dbschema
31-
COPY --from=builder /app/apps/server/gel.toml ./apps/server/gel.toml
32-
COPY --from=builder /app/apps/client/dist ./apps/client/dist
33-
34-
# CD into server app and run gel project initial setup
35-
36-
33+
COPY --from=install /temp/prod/node_modules node_modules
34+
COPY --from=install /temp/prod/apps/server/node_modules apps/server/node_modules
35+
COPY --from=prerelease /app/apps/server/dist ./apps/server/dist
36+
COPY --from=prerelease /app/apps/server/src/dbschema ./apps/server/src/dbschema
37+
COPY --from=prerelease /app/apps/server/gel.toml ./apps/server/gel.toml
38+
COPY --from=prerelease /app/apps/client/dist ./apps/client/dist
3739

3840
ENV NODE_ENV=production
3941
ENV PUBLIC_DIR=/app/apps/client/dist

0 commit comments

Comments
 (0)