1+ # =============================================================================
2+ # Docker Compose - Full Application Stack
3+ # =============================================================================
4+ # Simulates dev/prod environment with all services running in containers.
5+ #
6+ # Usage:
7+ # Start: docker compose -f docker-compose-all.yml up -d
8+ # Stop: docker compose -f docker-compose-all.yml down
9+ # Logs: docker compose -f docker-compose-all.yml logs -f user-service
10+ # Rebuild: docker compose -f docker-compose-all.yml up -d --build
11+ #
12+ # For production, use external secrets management (Vault, AWS Secrets Manager)
13+ # instead of environment variables in this file.
14+ # =============================================================================
15+
116services :
17+ # ---------------------------------------------------------------------------
18+ # Application Service
19+ # ---------------------------------------------------------------------------
220 user-service :
321 build :
422 context : .
523 dockerfile : Dockerfile
24+ container_name : user-application
625 ports :
7- - " 3001:3001"
26+ - " 3001:3001" # REST API
27+ - " 9090:9090" # gRPC API
828 depends_on :
9- - postgres
29+ postgres :
30+ condition : service_healthy
1031 environment :
11- - SPRING_PROFILES_ACTIVE=docker
12- - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/users
13- - SPRING_DATASOURCE_USERNAME=test_user_rw
14- - SPRING_DATASOURCE_PASSWORD=test_user@pass01
15- - JWT_ACCESS_SECRET=13483567-651e-410a-b79e-d4c1a66d3bd526b90300-0d1e-4d92-85e0-1747241d052d
16- - JWT_REFRESH_SECRET=8878f2cc-616e-413a-9b72-2eb32d7bf55c332df003-da39-45b7-82b1-f5f0d3203375
17- - CLIENT_URL=http://localhost:3000
18- volumes :
19- - ./logs:/app/logs
32+ # Profile: use 'dev' for development simulation, 'prod' for production
33+ - SPRING_PROFILES_ACTIVE=dev
34+
35+ # Database connection (matches dev/prod profile expectations)
36+ - DATABASE_URL=jdbc:postgresql://postgres:5432/users
37+ - DATABASE_USERNAME=app_user
38+ - DATABASE_PASSWORD=${DB_PASSWORD:-changeme_in_production}
39+
40+ # JWT secrets - MUST be overridden in production!
41+ # Generate with: openssl rand -base64 64
42+ - JWT_ACCESS_SECRET=${JWT_ACCESS_SECRET:-dev-only-access-secret-key-must-be-at-least-64-bytes-long-for-hs512}
43+ - JWT_REFRESH_SECRET=${JWT_REFRESH_SECRET:-dev-only-refresh-secret-key-must-be-at-least-64-bytes-long-for-hs512}
44+
45+ # CORS - adjust for your frontend URL
46+ - CORS_ALLOWED_ORIGINS=${CORS_ALLOWED_ORIGINS:-http://localhost:3000}
47+
48+ # JVM options for container environment
49+ - JAVA_OPTS=-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0
50+ healthcheck :
51+ test : [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3001/actuator/health" ]
52+ interval : 30s
53+ timeout : 10s
54+ retries : 3
55+ start_period : 60s
56+ restart : unless-stopped
57+ deploy :
58+ resources :
59+ limits :
60+ cpus : ' 2'
61+ memory : 1G
62+ reservations :
63+ cpus : ' 0.5'
64+ memory : 512M
2065 networks :
21- - user -network
66+ - app -network
2267
68+ # ---------------------------------------------------------------------------
69+ # PostgreSQL Database
70+ # ---------------------------------------------------------------------------
2371 postgres :
24- image : postgres:17.5-alpine
72+ image : postgres:17-alpine
73+ container_name : user-application-db
2574 ports :
26- - " 54321:5432"
75+ - " 54321:5432" # External port for debugging (remove in production)
2776 environment :
2877 - POSTGRES_DB=users
29- - POSTGRES_USER=test_user_rw
30- - POSTGRES_PASSWORD=test_user@pass01
78+ - POSTGRES_USER=app_user
79+ - POSTGRES_PASSWORD=${DB_PASSWORD:-changeme_in_production}
80+ # Performance tuning for container
81+ - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C
3182 volumes :
3283 - postgres_data:/var/lib/postgresql/data
84+ healthcheck :
85+ test : [ "CMD-SHELL", "pg_isready -U app_user -d users" ]
86+ interval : 10s
87+ timeout : 5s
88+ retries : 5
89+ start_period : 30s
90+ restart : unless-stopped
91+ deploy :
92+ resources :
93+ limits :
94+ cpus : ' 1'
95+ memory : 512M
96+ reservations :
97+ cpus : ' 0.25'
98+ memory : 256M
3399 networks :
34- - user -network
100+ - app -network
35101
36102volumes :
37103 postgres_data :
104+ name : user-service-postgres-data
38105
39106networks :
40- user-network :
41- driver : bridge
107+ app-network :
108+ name : user-service-network
109+ driver : bridge
0 commit comments