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 | |
| 11 | FROM node:22-slim AS base |
| 12 | ENV PNPM_HOME="/pnpm" |
| 13 | ENV 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 |
| 17 | RUN 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 | |
| 26 | RUN npm install -g pnpm@10.24.0 |
| 27 | |
| 28 | WORKDIR /app |
| 29 | |
| 30 | # Prune unneeded dependencies with turbo (from apps/ for example) |
| 31 | FROM base AS turbo |
| 32 | COPY . . |
| 33 | |
| 34 | RUN pnpm dlx turbo@2.9.3 prune studio --docker |
| 35 | |
| 36 | # Install dev dependencies (only if needed) |
| 37 | FROM base AS deps |
| 38 | COPY --from=turbo /app/out/json ./ |
| 39 | COPY --from=turbo /app/out/pnpm-lock.yaml ./ |
| 40 | COPY ./patches/ ./patches |
| 41 | |
| 42 | # No need to clean cache because production uses standalone build |
| 43 | RUN pnpm install --frozen-lockfile |
| 44 | |
| 45 | # dev contains dependencies and source code not compiled |
| 46 | FROM deps AS dev |
| 47 | COPY --from=turbo /app/out/full ./ |
| 48 | ENTRYPOINT ["docker-entrypoint.sh"] |
| 49 | EXPOSE 8082 |
| 50 | CMD ["pnpm", "dev:studio"] |
| 51 | |
| 52 | # Compile Next.js |
| 53 | FROM 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. |
| 57 | ENV NODE_OPTIONS="--max-old-space-size=6144" |
| 58 | |
| 59 | RUN pnpm --filter studio exec next build |
| 60 | |
| 61 | # Copy only compiled code and dependencies |
| 62 | FROM base AS production |
| 63 | COPY --from=builder /app/apps/studio/public ./apps/studio/public |
| 64 | COPY --from=builder /app/apps/studio/.next/standalone ./ |
| 65 | COPY --from=builder /app/apps/studio/.next/static ./apps/studio/.next/static |
| 66 | EXPOSE 3000 |
| 67 | ENTRYPOINT ["docker-entrypoint.sh"] |
| 68 | HEALTHCHECK --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)})" |
| 69 | CMD ["node", "apps/studio/server.js"] |