11# Base image with Bun
22FROM oven/bun:1.2.22 AS base
33
4- # Install turbo CLI globally using Bun (cache this layer)
4+ # Install turbo CLI globally using Bun
55FROM base AS turbo-cli
6677
88# Builder stage
99FROM turbo-cli AS builder
1010WORKDIR /app
11- # Copy all files for turbo prune
11+ # Copy all files
1212COPY . .
1313# Use turbo CLI from Bun global install to prune workspaces
1414RUN turbo prune @midday/api --docker
1515
16- # Installer stage with build dependencies
16+ # Installer stage
1717FROM base AS installer
1818WORKDIR /app
1919
2020# Install build dependencies for native modules (canvas, etc.)
21- # This layer is cached unless build dependencies change
2221RUN apt-get update && apt-get install -y \
2322 python3 \
2423 python3-pip \
@@ -30,39 +29,20 @@ RUN apt-get update && apt-get install -y \
3029 librsvg2-dev \
3130 && rm -rf /var/lib/apt/lists/*
3231
33- # Copy only JSON files first (package.json files) for better layer caching
34- # This allows Docker to cache dependency installation layer separately
32+ # First install the dependencies (as they change less often)
3533COPY --from=builder /app/out/json/ .
36-
37- # Install dependencies with Bun cache mount (BuildKit feature)
38- # Cache this layer - only rebuilds when dependencies change
39- # Build dependencies (python3, build-essential, node-gyp) are already installed above
34+ # Don't copy the lockfile, allow Bun to generate a fresh one
4035RUN --mount=type=cache,target=/root/.bun/install/cache \
4136 bun install
4237
43- # Copy the full source code (this invalidates cache when code changes)
38+ # Copy the full source code
4439COPY --from=builder /app/out/full/ .
4540
4641# Copy the prebuilt engine dist from the build context (assumes CI built it)
4742COPY apps/engine/dist /app/apps/engine/dist
4843
49- # Runner stage - final runtime image (remove build dependencies)
50- FROM base AS runner
51- WORKDIR /app
52-
53- # Install only runtime libraries needed for canvas (not build tools)
54- RUN apt-get update && apt-get install -y --no-install-recommends \
55- libcairo2 \
56- libpango-1.0-0 \
57- libjpeg62-turbo \
58- libgif7 \
59- librsvg2-2 \
60- && rm -rf /var/lib/apt/lists/*
61-
62- # Copy only runtime files from installer
63- COPY --from=installer /app/node_modules ./node_modules
64- COPY --from=installer /app/apps ./apps
65- COPY --from=installer /app/packages ./packages
44+ # Runner stage (same as installer to avoid another copy)
45+ FROM installer AS runner
6646
6747# Set the API directory as working directory
6848WORKDIR /app/apps/api
0 commit comments