feat: APISIX gateway with Docker Compose orchestration for stock microservices
- APISIX declarative config with versioned API routes (/api/v1/{service}/...)
- proxy-rewrite for path transformation, CORS global rule, rate limiting (100 req/s)
- Active health checks on all 6 upstream services
- Docker Compose with 11 containers: Redis, PostgreSQL, MongoDB, 6 Python services, APISIX, Next.js frontend
- Environment config via .env.example
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
169
docker-compose.yml
Normal file
169
docker-compose.yml
Normal file
@ -0,0 +1,169 @@
|
||||
version: "3.8"
|
||||
|
||||
x-common-env: &common-env
|
||||
REDIS_URL: redis://redis:6379/0
|
||||
POSTGRES_HOST: postgres
|
||||
POSTGRES_PORT: "5432"
|
||||
POSTGRES_DB: stockdb
|
||||
POSTGRES_USER: stock
|
||||
POSTGRES_PASSWORD: stock
|
||||
MONGODB_URI: mongodb://mongo:27017
|
||||
MONGODB_DB: stock_analysis
|
||||
LOG_LEVEL: INFO
|
||||
LOG_FORMAT: json
|
||||
|
||||
services:
|
||||
# ─── Infrastructure ───────────────────────────────────
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- redis-data:/data
|
||||
command: redis-server --appendonly yes
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 5s
|
||||
retries: 3
|
||||
|
||||
postgres:
|
||||
image: timescale/timescaledb:latest-pg16
|
||||
environment:
|
||||
POSTGRES_USER: stock
|
||||
POSTGRES_PASSWORD: stock
|
||||
POSTGRES_DB: stockdb
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- pg-data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U stock"]
|
||||
interval: 5s
|
||||
retries: 3
|
||||
|
||||
mongo:
|
||||
image: mongo:7
|
||||
ports:
|
||||
- "27017:27017"
|
||||
volumes:
|
||||
- mongo-data:/data/db
|
||||
healthcheck:
|
||||
test: ["CMD", "mongosh", "--eval", "db.runCommand('ping').ok"]
|
||||
interval: 5s
|
||||
retries: 3
|
||||
|
||||
# ─── API Gateway ──────────────────────────────────────
|
||||
apisix:
|
||||
image: apache/apisix:3.8.0-debian
|
||||
ports:
|
||||
- "9080:9080" # API Gateway
|
||||
- "9091:9091" # Prometheus metrics
|
||||
volumes:
|
||||
- ./apisix/conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro
|
||||
- ./apisix/conf/apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro
|
||||
depends_on:
|
||||
- stock-dart-collector
|
||||
- stock-kis-collector
|
||||
- stock-news-crawler
|
||||
- stock-screener
|
||||
- stock-catalyst
|
||||
- stock-llm-analyzer
|
||||
|
||||
# ─── Microservices ────────────────────────────────────
|
||||
stock-dart-collector:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: stock-dart-collector/Dockerfile
|
||||
environment:
|
||||
<<: *common-env
|
||||
DART_API_KEY: ${DART_API_KEY}
|
||||
ports:
|
||||
- "8001:8001"
|
||||
depends_on:
|
||||
redis:
|
||||
condition: service_healthy
|
||||
|
||||
stock-kis-collector:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: stock-kis-collector/Dockerfile
|
||||
environment:
|
||||
<<: *common-env
|
||||
KIS_APP_KEY: ${KIS_APP_KEY}
|
||||
KIS_APP_SECRET: ${KIS_APP_SECRET}
|
||||
KIS_BASE_URL: ${KIS_BASE_URL:-https://openapivts.koreainvestment.com:9443}
|
||||
ports:
|
||||
- "8002:8002"
|
||||
depends_on:
|
||||
redis:
|
||||
condition: service_healthy
|
||||
|
||||
stock-news-crawler:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: stock-news-crawler/Dockerfile
|
||||
environment:
|
||||
<<: *common-env
|
||||
ports:
|
||||
- "8003:8003"
|
||||
depends_on:
|
||||
redis:
|
||||
condition: service_healthy
|
||||
|
||||
stock-screener:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: stock-screener/Dockerfile
|
||||
environment:
|
||||
<<: *common-env
|
||||
ports:
|
||||
- "8004:8004"
|
||||
depends_on:
|
||||
redis:
|
||||
condition: service_healthy
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
||||
stock-catalyst:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: stock-catalyst/Dockerfile
|
||||
environment:
|
||||
<<: *common-env
|
||||
ports:
|
||||
- "8005:8005"
|
||||
depends_on:
|
||||
redis:
|
||||
condition: service_healthy
|
||||
mongo:
|
||||
condition: service_healthy
|
||||
|
||||
stock-llm-analyzer:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: stock-llm-analyzer/Dockerfile
|
||||
environment:
|
||||
<<: *common-env
|
||||
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
|
||||
ports:
|
||||
- "8006:8006"
|
||||
depends_on:
|
||||
redis:
|
||||
condition: service_healthy
|
||||
|
||||
# ─── Frontend ─────────────────────────────────────────
|
||||
stock-frontend:
|
||||
build:
|
||||
context: ../stock-frontend
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
NEXT_PUBLIC_API_URL: http://localhost:9080/api/v1
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- apisix
|
||||
|
||||
volumes:
|
||||
redis-data:
|
||||
pg-data:
|
||||
mongo-data:
|
||||
Reference in New Issue
Block a user