Files
sprinkler-calculation/docker-compose.yml
T
Bkk1234 b676889816 fix(deploy): Dokploy-safe compose split + resilient db healthcheck
- docker-compose.yml is now the server form: no published host ports
  (expose only), so a port already taken on the host can no longer stop
  the stack; local ports moved to docker-compose.override.yml, which
  Dokploy never reads
- db healthcheck probes TCP 127.0.0.1 instead of the unix socket and
  allows start_period 30s / 12 retries while initdb finishes
- api start_period 20s
2026-11-23 11:35:09 +07:00

98 lines
3.3 KiB
YAML

name: irrcal
# docker-compose.yml — รูปแบบสำหรับ deploy (Dokploy/เซิร์ฟเวอร์)
# * ไม่ publish host port — ให้ Traefik/edge คุยผ่าน internal network
# * พอร์ตที่ process ฟังในคอนเทนเนอร์ยังมาจาก .env (WEB_CONTAINER_PORT / API_CONTAINER_PORT)
# * รันบนเครื่องตัวเอง: `docker compose up -d` จะ merge docker-compose.override.yml (host port อยู่ในนั้น)
# * Dokploy รัน `docker compose -f docker-compose.yml` → override ไม่ถูกใช้
services:
web:
build:
context: .
dockerfile: Dockerfile
image: irrcal-web:latest
environment:
WEB_CONTAINER_PORT: ${WEB_CONTAINER_PORT:-8080}
API_CONTAINER_PORT: ${API_CONTAINER_PORT:-8000}
TZ: ${TZ:-Asia/Bangkok}
expose:
- "${WEB_CONTAINER_PORT:-8080}"
depends_on:
api:
condition: service_started
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:$${WEB_CONTAINER_PORT}/healthz > /dev/null 2>&1 || exit 1"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
api:
build:
context: ./service
dockerfile: Dockerfile
image: irrcal-api:latest
environment:
FARM_API_HOST: 0.0.0.0
FARM_API_PORT: ${API_CONTAINER_PORT:-8000}
FARM_DB_HOST: db
FARM_DB_PORT: 5432
FARM_DB_NAME: ${DB_NAME:-farm_planning}
FARM_DB_USER: ${DB_USER:-postgres}
FARM_DB_PASSWORD: ${DB_PASSWORD:-farm_planning_dev}
FARM_PERSIST_RUNS: ${FARM_PERSIST_RUNS:-true}
FARM_CORS_ORIGIN: ${FARM_CORS_ORIGIN:-*}
TZ: ${TZ:-Asia/Bangkok}
expose:
- "${API_CONTAINER_PORT:-8000}"
depends_on:
db:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:$${FARM_API_PORT}/api/v1/health > /dev/null || exit 1"]
interval: 30s
timeout: 5s
retries: 5
start_period: 20s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
db:
image: postgres:17-alpine
environment:
POSTGRES_DB: ${DB_NAME:-farm_planning}
POSTGRES_USER: ${DB_USER:-postgres}
POSTGRES_PASSWORD: ${DB_PASSWORD:-farm_planning_dev}
TZ: ${TZ:-Asia/Bangkok}
volumes:
- pgdata:/var/lib/postgresql/data
# สคีมาถูกสร้างอัตโนมัติเมื่อฐานข้อมูลยังว่าง (ครั้งแรกเท่านั้น)
- ./service/db/001_init.sql:/docker-entrypoint-initdb.d/001_init.sql:ro
restart: unless-stopped
healthcheck:
# ตรวจผ่าน TCP (127.0.0.1) ไม่ใช่ unix socket — กันกรณี socket dir ไม่พร้อมบน host ที่แชร์ volume
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -p 5432 -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 12
start_period: 30s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
volumes:
pgdata: