Docker Development Setup for ERP-Unlocked Monorepo
This document provides comprehensive instructions for Docker-based development in the ERP-Unlocked monorepo, covering both containerized and hybrid development approaches.
Table of Contents
Section titled “Table of Contents”- Prerequisites
- Development Environment Setup
- Docker Compose Development
- Hybrid Development (Recommended)
- Building with Docker Bake
- Individual App Development
- Database Operations
- Troubleshooting
Prerequisites
Section titled “Prerequisites”Required Software
Section titled “Required Software”- Docker Desktop (4.0+)
- Node.js (18+) with pnpm (8+)
- Python (3.11+) with uv (for Python packages)
- Git for version control
Install pnpm (if not already installed)
Section titled “Install pnpm (if not already installed)”npm install -g pnpm@latestVerify Installation
Section titled “Verify Installation”docker --versionpnpm --versionpython --versionDevelopment Environment Setup
Section titled “Development Environment Setup”1. Clone and Setup Repository
Section titled “1. Clone and Setup Repository”git clone https://github.com/ERP-Unlocked/ordermatic.gitcd ordermatic
# Install all dependencies using pnpm workspacespnpm install
# Install Python dependencies for PDF servicescd apps/pdf-api && uv sync && cd ../..cd apps/pdf-worker && uv sync && cd ../..2. Environment Configuration
Section titled “2. Environment Configuration”Create environment files for each app:
# Webapp environmentcp apps/webapp/.env.example apps/webapp/.env.local
# PDF API environmentcp apps/pdf-api/.env.example apps/pdf-api/.env3. Configure Environment Variables
Section titled “3. Configure Environment Variables”Edit the environment files with your local configuration:
apps/webapp/.env.local:
DATABASE_URL=postgresql://postgres:password@localhost:5432/erp_unlockedREDIS_URL=redis://localhost:6379CLERK_SECRET_KEY=your_clerk_secret_keyGEMINI_API_KEY=your_gemini_api_keyPDF_API_URL=http://localhost:8000apps/pdf-api/.env:
DATABASE_URL=postgresql://postgres:password@localhost:5432/erp_unlockedREDIS_URL=redis://localhost:6379GEMINI_API_KEY=your_gemini_api_keySERVICE_TOKEN=your_service_tokenDocker Compose Development
Section titled “Docker Compose Development”Starting All Services
Section titled “Starting All Services”# Start all services in backgrounddocker-compose up -d
# Start with logs visibledocker-compose upService-Specific Commands
Section titled “Service-Specific Commands”# Start only infrastructure services (PostgreSQL, Redis)docker-compose up -d postgres redis
# Start webapp and its dependenciesdocker-compose up webapp postgres redis
# Start PDF processing servicesdocker-compose up pdf-api pdf-worker redis postgresManaging Services
Section titled “Managing Services”# View service statusdocker-compose ps
# View logs from all servicesdocker-compose logs -f
# View logs from specific servicedocker-compose logs -f webapp
# Stop all servicesdocker-compose down
# Stop and remove volumes (clean slate)docker-compose down -vHybrid Development (Recommended)
Section titled “Hybrid Development (Recommended)”For optimal development experience, run infrastructure in Docker but apps natively:
1. Start Infrastructure Services
Section titled “1. Start Infrastructure Services”# Start only PostgreSQL and Redisdocker-compose up -d postgres redis
# Verify services are runningdocker-compose ps2. Run Apps Natively
Section titled “2. Run Apps Natively”Terminal 1 - Webapp (Astro + React):
cd apps/webapppnpm run dev# → http://localhost:4321Terminal 3 - PDF API:
cd apps/pdf-apiuv run fastapi dev app/main.py --host 0.0.0.0 --port 8000# → http://localhost:8000Terminal 4 - PDF Worker:
cd apps/pdf-workeruv run celery -A celery_app worker --loglevel=info3. Database Setup
Section titled “3. Database Setup”cd packages/dbpnpm run db:migratepnpm run db:seed # Optional: seed with sample dataBuilding with Docker Bake
Section titled “Building with Docker Bake”Docker Bake provides unified build configuration for all services:
Build All Services
Section titled “Build All Services”# Build all Docker servicesdocker buildx bake
# Build and push to registry (for CI/CD)docker buildx bake --push
# Build with custom tagBRANCH_NAME=feature/my-feature COMMIT_SHA=abc123 docker buildx bakeBuild Specific Services
Section titled “Build Specific Services”# Build only webappdocker buildx bake webapp
# Build PDF servicesdocker buildx bake pdf-services
# Build specific service groupdocker buildx bake --target pdf-apiBuild Configuration
Section titled “Build Configuration”The docker-bake.hcl file defines build targets:
webapp: Astro customer applicationpdf-api: FastAPI processing servicepdf-worker: Celery background worker- Groups:
default,webapp,pdf-services
Individual App Development
Section titled “Individual App Development”Webapp (Astro + React)
Section titled “Webapp (Astro + React)”cd apps/webapp
# Development serverpnpm run dev # Start dev server on port 4321pnpm run build # Build for productionpnpm run preview # Preview production build
# Database operationspnpm run db:migrate # Run database migrationspnpm run db:studio # Open Drizzle Studiopnpm run db:seed # Seed database with sample data
# Testing and lintingpnpm run test # Run testspnpm run lint # Lint codepnpm run type-check # TypeScript type checkingPDF API (FastAPI)
Section titled “PDF API (FastAPI)”cd apps/pdf-api
# Development serveruv run fastapi dev app/main.py --host 0.0.0.0 --port 8000
# Production serveruv run gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker
# Testing and utilitiesuv run pytest tests/ # Run testsuv run python -m app.scripts.health_check # Health checkPDF Worker (Celery)
Section titled “PDF Worker (Celery)”cd apps/pdf-worker
# Development workeruv run celery -A celery_app worker --loglevel=info
# Production workeruv run celery -A celery_app worker --loglevel=warning --concurrency=4
# Monitoring and utilitiesuv run celery -A celery_app flower # Flower web UIuv run celery -A celery_app status # Worker statusuv run celery -A celery_app inspect stats # Detailed statsDatabase Operations
Section titled “Database Operations”Using the Database Package
Section titled “Using the Database Package”cd packages/db
# Schema operationspnpm run db:generate # Generate migration from schema changespnpm run db:migrate # Apply pending migrationspnpm run db:rollback # Rollback last migration
# Development utilitiespnpm run db:studio # Open Drizzle Studio (GUI)pnpm run db:seed # Seed with sample datapnpm run db:reset # Reset database (drop + migrate + seed)
# Schema validationpnpm run db:check # Check for schema driftpnpm run db:validate # Validate migration filesDirect Database Access
Section titled “Direct Database Access”# Connect to PostgreSQL containerdocker exec -it erp_unlocked_postgres psql -U postgres -d erp_unlocked
# Common SQL operations\dt # List tables\d users # Describe table structureSELECT * FROM users LIMIT 5; # Query dataPackage Development
Section titled “Package Development”UI Components
Section titled “UI Components”cd packages/ui
# Developmentpnpm run dev # Storybook development serverpnpm run build # Build component librarypnpm run test # Test components
# Generate new componentpnpm run generate:component MyComponentShared Utils
Section titled “Shared Utils”cd packages/utils
# Development and testingpnpm run build # Build TypeScript utilitiespnpm run test # Run unit testspnpm run type-check # TypeScript validationDevelopment Workflows
Section titled “Development Workflows”Full Stack Development
Section titled “Full Stack Development”- Start infrastructure:
docker-compose up -d postgres redis - Run database migrations:
cd packages/db && pnpm run db:migrate - Start webapp:
cd apps/webapp && pnpm run dev - Start PDF services:
cd apps/pdf-api && uv run fastapi dev app/main.py - Start worker:
cd apps/pdf-worker && uv run celery -A celery_app worker --loglevel=info
Frontend-Only Development
Section titled “Frontend-Only Development”- Start infrastructure:
docker-compose up -d postgres redis - Seed database:
cd packages/db && pnpm run db:seed - Start webapp:
cd apps/webapp && pnpm run dev
API-Only Development
Section titled “API-Only Development”- Start infrastructure:
docker-compose up -d postgres redis - Start PDF API:
cd apps/pdf-api && uv run fastapi dev app/main.py - Start worker:
cd apps/pdf-worker && uv run celery -A celery_app worker --loglevel=info
Testing and Quality
Section titled “Testing and Quality”Running Tests
Section titled “Running Tests”# Run all tests from rootpnpm run test
# Run tests for specific appcd apps/webapp && pnpm run testcd apps/pdf-api && uv run pytest
# Run specific test suitespnpm run test:unit # Unit tests onlypnpm run test:integration # Integration tests onlypnpm run test:e2e # End-to-end testsCode Quality
Section titled “Code Quality”# Lint all codepnpm run lint
# Format all codepnpm run format
# Type checkingpnpm run type-check
# Pre-commit hooks (automatic)git commit -m "Your changes" # Runs lint, format, type-check automaticallyTroubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Port Conflicts
Section titled “Port Conflicts”# Check what's using a portlsof -i :4321 # Check webapp portlsof -i :8000 # Check PDF API port
# Kill processes using portssudo kill -9 $(lsof -ti:4321)Database Connection Issues
Section titled “Database Connection Issues”# Verify PostgreSQL is runningdocker-compose ps postgres
# Check database connectivitydocker exec -it erp_unlocked_postgres pg_isready
# Reset database connectiondocker-compose restart postgrespnpm Workspace Issues
Section titled “pnpm Workspace Issues”# Clear all node_modules and reinstallpnpm clean # Custom script to clean all node_modulespnpm install
# Clear pnpm cachepnpm store pruneDocker Build Issues
Section titled “Docker Build Issues”# Clean Docker cachedocker system prune -a
# Rebuild without cachedocker buildx bake --no-cache
# Check Docker Bake configurationdocker buildx bake --printDebug Commands
Section titled “Debug Commands”Service Health Checks
Section titled “Service Health Checks”# Check webapp healthcurl http://localhost:4321/health
# Check PDF API healthcurl http://localhost:8000/health
# Check Redis connectivityredis-cli -h localhost -p 6379 ping
# Check PostgreSQL connectivitydocker exec erp_unlocked_postgres pg_isreadyService Logs
Section titled “Service Logs”# Application logsdocker-compose logs webappdocker-compose logs pdf-api
# Database logsdocker-compose logs postgres
# Redis logsdocker-compose logs redisPerformance Optimization
Section titled “Performance Optimization”Development Performance
Section titled “Development Performance”# Use pnpm's node_modules linking for faster installspnpm config set store-dir ~/.pnpm-store
# Enable pnpm's shamefully-hoist for faster buildsecho "shamefully-hoist=true" >> .npmrc
# Use Docker BuildKit for faster buildsexport DOCKER_BUILDKIT=1Resource Management
Section titled “Resource Management”# Monitor Docker resource usagedocker stats
# Limit container resources in docker-compose.ymlservices: webapp: deploy: resources: limits: memory: 512M reservations: memory: 256MThis comprehensive setup ensures efficient development across the entire ERP-Unlocked monorepo, supporting both full containerized development and hybrid approaches based on your preferences and requirements.
Production Deployment Notes
Section titled “Production Deployment Notes”The production deployment process differs significantly from local development:
- PR-Based Workflow: All deployments use strict branch protection with conventional commit formats
- GitHub Actions: Automated builds triggered by pushes to protected branches (
main/staging) - Coolify Integration: Uses webhooks (not direct git integration) to trigger deployments from GHCR images
- Image Registry: All production images stored in GitHub Container Registry with commit-based tagging
- Trigger.dev Integration: Background jobs deployed separately via
pnpm run trigger:deploy
For complete deployment procedures, see Deployment Guide.