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
This commit is contained in:
Bkk1234 committed 2026-11-23 11:35:09 +07:00
1 parent 1b6c56b47c
commit b676889816
4 files changed
+46 -15

No files matched your search

+15 -15
View File
@@ -1,9 +1,10 @@
name: irrcal
# พอร์ตทั้งหมดมาจาก .env (คัดลอก .env.example → .env แล้วแก้ค่าจริง)
# *_CONTAINER_PORT = พอร์ตที่ process ฟังในคอนเทนเนอร์
# *_HOST_PORT = พอร์ตที่แมปออกเครื่องจริง
# ไฟล์นี้ไม่ถูก commit (.env) — .env.example ขึ้น git
# 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:
@@ -15,8 +16,8 @@ services:
WEB_CONTAINER_PORT: ${WEB_CONTAINER_PORT:-8080}
API_CONTAINER_PORT: ${API_CONTAINER_PORT:-8000}
TZ: ${TZ:-Asia/Bangkok}
ports:
- "${WEB_HOST_PORT:-8095}:${WEB_CONTAINER_PORT:-8080}"
expose:
- "${WEB_CONTAINER_PORT:-8080}"
depends_on:
api:
condition: service_started
@@ -26,7 +27,7 @@ services:
interval: 30s
timeout: 5s
retries: 3
start_period: 5s
start_period: 10s
logging:
driver: json-file
options:
@@ -49,8 +50,8 @@ services:
FARM_PERSIST_RUNS: ${FARM_PERSIST_RUNS:-true}
FARM_CORS_ORIGIN: ${FARM_CORS_ORIGIN:-*}
TZ: ${TZ:-Asia/Bangkok}
ports:
- "${API_HOST_PORT:-8000}:${API_CONTAINER_PORT:-8000}"
expose:
- "${API_CONTAINER_PORT:-8000}"
depends_on:
db:
condition: service_healthy
@@ -60,7 +61,7 @@ services:
interval: 30s
timeout: 5s
retries: 5
start_period: 10s
start_period: 20s
logging:
driver: json-file
options:
@@ -78,15 +79,14 @@ services:
- pgdata:/var/lib/postgresql/data
# สคีมาถูกสร้างอัตโนมัติเมื่อฐานข้อมูลยังว่าง (ครั้งแรกเท่านั้น)
- ./service/db/001_init.sql:/docker-entrypoint-initdb.d/001_init.sql:ro
ports:
- "${DB_HOST_PORT:-5433}:5432"
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
# ตรวจผ่าน 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: 10
start_period: 10s
retries: 12
start_period: 30s
logging:
driver: json-file
options: