Backend Dockerfile
The backend uses a lightweight Python 3.11 slim image for optimal performance.Dockerfile Overview
Key Configuration Details
Base Image
The
python:3.11-slim image provides a minimal Python environment, reducing the container size while maintaining compatibility with all required dependencies.Environment Variables
PYTHONDONTWRITEBYTECODE=1- Prevents Python from writing.pycfilesPYTHONUNBUFFERED=1- Ensures logs are sent directly to stdout without buffering
The
--proxy-headers flag is crucial for Cloud Run deployments to properly handle X-Forwarded-* headers.Backend Dependencies
The backend requires the following key dependencies:Frontend Dockerfile
The frontend uses a multi-stage build with Node.js 20 Alpine for an optimized production image.Multi-Stage Build
Build Stages Explained
Dependencies Stage
The
deps stage installs all npm dependencies. Using libc6-compat ensures compatibility with native Node modules.Builder Stage
The
builder stage copies dependencies and builds the Next.js application with telemetry disabled for faster builds.Building the Containers
Running Locally
When running locally, ensure you have valid Google Cloud credentials mounted or use Application Default Credentials (ADC).
Production Considerations
Backend
- Mount service account credentials or use Workload Identity
- Set all required environment variables (see Environment Variables)
- Use health check endpoints for container orchestration
- Enable logging with structured output
Frontend
- Configure
NEXT_PUBLIC_API_URLto point to your backend - Use HTTPS in production
- Consider using a CDN for static assets
- Set appropriate memory and CPU limits
Next Steps
Cloud Run Deployment
Deploy to Google Cloud Run for serverless scaling
Environment Variables
Configure all required environment variables