Skip to content

Conversation

@MODSetter
Copy link
Owner

@MODSetter MODSetter commented Oct 24, 2025

Description

feat: frontend docker to use nextjs production build

Motivation and Context

To make docker useable and fast

Screenshots

API Changes

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

High-level PR Summary

This PR migrates the frontend Docker setup from development mode to a production build configuration for Next.js. The key change is transforming the Dockerfile to use a multi-stage build process that produces an optimized standalone production bundle instead of running pnpm dev. The PR updates the Docker Compose configuration to pass NEXT_PUBLIC_* environment variables as build arguments (required for Next.js static builds), removes volume mounts for the frontend, updates environment variable names for consistency (NEXT_PUBLIC_API_URLNEXT_PUBLIC_FASTAPI_BACKEND_URL), and documents these changes in the installation guide. Additionally, the backend Docker entrypoint service startup order is adjusted, and volume mounts are refined for better separation.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_web/next.config.ts
2 surfsense_web/Dockerfile
3 surfsense_web/.dockerignore
4 docker-compose.yml
5 .env.example
6 surfsense_web/content/docs/docker-installation.mdx
7 surfsense_backend/scripts/docker/entrypoint.sh
⚠️ Inconsistent Changes Detected
File Path Warning
surfsense_backend/scripts/docker/entrypoint.sh Changes to backend service startup order (moving FastAPI to start before Celery workers and adding sleep delays) seems unrelated to the main PR purpose of converting frontend to production build

Need help? Join our Discord

Analyze latest changes

Summary by CodeRabbit

  • Chores

    • Refactored frontend environment configuration to use build-time variables for improved Docker deployments
    • Optimized Docker setup with reorganized service volumes and startup sequence
    • Enhanced frontend Docker image build process with multi-stage optimization for better performance
  • Documentation

    • Updated Docker installation guide to reflect new configuration requirements

@vercel
Copy link

vercel bot commented Oct 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
surf-sense-frontend Ready Ready Preview Comment Oct 24, 2025 3:42am

@coderabbitai
Copy link

coderabbitai bot commented Oct 24, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Replaced NEXT_PUBLIC_API_URL with three new frontend environment variables (NEXT_PUBLIC_FASTAPI_BACKEND_URL, NEXT_PUBLIC_FASTAPI_BACKEND_AUTH_TYPE, NEXT_PUBLIC_ETL_SERVICE). Refactored docker-compose to pass these as build-time args. Reordered backend startup sequence, introduced multi-stage Dockerfile with pnpm and standalone output mode, and updated documentation.

Changes

Cohort / File(s) Summary
Environment Configuration
.env.example
Replaced NEXT_PUBLIC_API_URL with three new frontend vars: NEXT_PUBLIC_FASTAPI_BACKEND_URL, NEXT_PUBLIC_FASTAPI_BACKEND_AUTH_TYPE, NEXT_PUBLIC_ETL_SERVICE
Docker Compose
docker-compose.yml
Backend volumes split into targeted mounts (./surfsense_backend/app:/app/app, ./surfsense_backend/scripts:/app/scripts:ro). Frontend service switched from image reference to build block with args for three new env vars; removed volumes and environment sections
Frontend Docker Build
surfsense_web/Dockerfile
Complete rewrite: multi-stage setup (base, deps, builder, runner) using pnpm with corepack, frozen-lockfile install, build-time arg injection, dedicated runtime user, standalone Next.js output, and server.js entry point
Frontend Docker Config
surfsense_web/.dockerignore
Removed .env* patterns; added Dockerfile, .dockerignore, node_modules, README.md
Frontend Next.js Config
surfsense_web/next.config.ts
Added output: "standalone" configuration
Backend Startup
surfsense_backend/scripts/docker/entrypoint.sh
Reordered startup: FastAPI backend first with pid capture and 5s wait, followed by Celery Worker and Beat; added final wait handler for process exit
Documentation
surfsense_web/content/docs/docker-installation.mdx
Updated frontend env var names and added note on build-time embedding; replaced table with bulleted list and Docker-focused guidance

Sequence Diagram

sequenceDiagram
    actor Start as Entrypoint
    participant FastAPI as FastAPI Backend
    participant CeleryW as Celery Worker
    participant CeleryB as Celery Beat
    
    Start->>FastAPI: python main.py (capture PID)
    FastAPI->>FastAPI: Initialize
    Start->>Start: sleep 5 (wait for backend ready)
    Start->>CeleryW: Start Celery Worker
    Start->>Start: sleep 3 (settle)
    Start->>CeleryB: Start Celery Beat
    Start->>Start: wait -n (monitor all PIDs)
    
    Note over FastAPI,CeleryB: New sequence: backend first, then workers
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Multi-stage Dockerfile requires careful validation of build stages and output handling. Docker-compose build-args flow and entrypoint sequencing need verification. Changes span multiple domains (build, runtime, configuration) but follow consistent patterns.

Possibly related PRs

Poem

🐰 Docker containers, multi-staged with care,
Build args and standalone, a cleaner affair,
Environment variables in layers so neat,
FastAPI leads the startup beat,
Next.js runs standalone—oh, what a treat! 🎉

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc4fe71 and 99ab6af.

📒 Files selected for processing (7)
  • .env.example (1 hunks)
  • docker-compose.yml (2 hunks)
  • surfsense_backend/scripts/docker/entrypoint.sh (1 hunks)
  • surfsense_web/.dockerignore (1 hunks)
  • surfsense_web/Dockerfile (1 hunks)
  • surfsense_web/content/docs/docker-installation.mdx (2 hunks)
  • surfsense_web/next.config.ts (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@MODSetter MODSetter merged commit 1be9c34 into main Oct 24, 2025
5 of 8 checks passed
Copy link

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by RecurseML

🔍 Review performed on dc4fe71..99ab6af

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (7)

.env.example
docker-compose.yml
surfsense_backend/scripts/docker/entrypoint.sh
surfsense_web/.dockerignore
surfsense_web/Dockerfile
surfsense_web/content/docs/docker-installation.mdx
surfsense_web/next.config.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants