Dockerfile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. FROM node:22-slim AS base
  11. ENV PNPM_HOME="/pnpm"
  12. ENV PATH="$PNPM_HOME:$PATH"
  13. # Fixes issues with Sentry CLI and SSL certificates during build
  14. # TODO: Git is added because it's needed to build libpg, remove it once they publish a binary on the S3 bucket
  15. RUN apt-get update -qq && \
  16. apt-get install -y --no-install-recommends \
  17. git \
  18. python3 \
  19. ca-certificates \
  20. build-essential && \
  21. rm -rf /var/lib/apt/lists/* && \
  22. update-ca-certificates
  23. RUN npm install -g pnpm@10.24.0
  24. WORKDIR /app
  25. # Prune unneeded dependencies with turbo (from apps/ for example)
  26. FROM base AS turbo
  27. COPY . .
  28. RUN pnpm dlx turbo@2.9.3 prune studio --docker
  29. # Install dev dependencies (only if needed)
  30. FROM base AS deps
  31. COPY --from=turbo /app/out/json ./
  32. COPY --from=turbo /app/out/pnpm-lock.yaml ./
  33. COPY ./patches/ ./patches
  34. # No need to clean cache because production uses standalone build
  35. RUN pnpm install --frozen-lockfile
  36. # dev contains dependencies and source code not compiled
  37. FROM deps AS dev
  38. COPY --from=turbo /app/out/full ./
  39. ENTRYPOINT ["docker-entrypoint.sh"]
  40. EXPOSE 8082
  41. CMD ["pnpm", "dev:studio"]
  42. # Compile Next.js
  43. FROM dev AS builder
  44. # Bound build heap so a runaway build OOMs itself instead of swap-killing the host (kvm4 16GB).
  45. # Studio is Supabase-derived and genuinely heavy, so it gets a higher ceiling than the 4096 default.
  46. ENV NODE_OPTIONS="--max-old-space-size=6144"
  47. RUN pnpm --filter studio exec next build
  48. # Copy only compiled code and dependencies
  49. FROM base AS production
  50. COPY --from=builder /app/apps/studio/public ./apps/studio/public
  51. COPY --from=builder /app/apps/studio/.next/standalone ./
  52. COPY --from=builder /app/apps/studio/.next/static ./apps/studio/.next/static
  53. EXPOSE 3000
  54. ENTRYPOINT ["docker-entrypoint.sh"]
  55. 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)})"
  56. CMD ["node", "apps/studio/server.js"]