Dockerfile69 lines · main
1# To be run in the root of the turbo monorepo
2# NOTE: It's highly recommended to use the new builder, Buildkit. https://docs.docker.com/build/buildkit/
3## USAGE:
4# Build: docker build . -f apps/studio/Dockerfile --target production -t studio:latest
5# Run: docker run -p 3000:3000 briven/studio
6# Deploy: docker push briven/studio:latest
7# Clean build:
8# docker builder prune
9# docker build . -f apps/studio/Dockerfile --target production -t studio:latest --no-cache
10
11FROM node:22-slim AS base
12ENV PNPM_HOME="/pnpm"
13ENV PATH="$PNPM_HOME:$PATH"
14
15# Fixes issues with Sentry CLI and SSL certificates during build
16# TODO: Git is added because it's needed to build libpg, remove it once they publish a binary on the S3 bucket
17RUN apt-get update -qq && \
18 apt-get install -y --no-install-recommends \
19 git \
20 python3 \
21 ca-certificates \
22 build-essential && \
23 rm -rf /var/lib/apt/lists/* && \
24 update-ca-certificates
25
26RUN npm install -g pnpm@10.24.0
27
28WORKDIR /app
29
30# Prune unneeded dependencies with turbo (from apps/ for example)
31FROM base AS turbo
32COPY . .
33
34RUN pnpm dlx turbo@2.9.3 prune studio --docker
35
36# Install dev dependencies (only if needed)
37FROM base AS deps
38COPY --from=turbo /app/out/json ./
39COPY --from=turbo /app/out/pnpm-lock.yaml ./
40COPY ./patches/ ./patches
41
42# No need to clean cache because production uses standalone build
43RUN pnpm install --frozen-lockfile
44
45# dev contains dependencies and source code not compiled
46FROM deps AS dev
47COPY --from=turbo /app/out/full ./
48ENTRYPOINT ["docker-entrypoint.sh"]
49EXPOSE 8082
50CMD ["pnpm", "dev:studio"]
51
52# Compile Next.js
53FROM dev AS builder
54
55# Bound build heap so a runaway build OOMs itself instead of swap-killing the host (kvm4 16GB).
56# Studio is Supabase-derived and genuinely heavy, so it gets a higher ceiling than the 4096 default.
57ENV NODE_OPTIONS="--max-old-space-size=6144"
58
59RUN pnpm --filter studio exec next build
60
61# Copy only compiled code and dependencies
62FROM base AS production
63COPY --from=builder /app/apps/studio/public ./apps/studio/public
64COPY --from=builder /app/apps/studio/.next/standalone ./
65COPY --from=builder /app/apps/studio/.next/static ./apps/studio/.next/static
66EXPOSE 3000
67ENTRYPOINT ["docker-entrypoint.sh"]
68HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD node -e "fetch('http://localhost:3000/api/platform/profile').then((r) => {if (r.status !== 200) throw new Error(r.status)})"
69CMD ["node", "apps/studio/server.js"]