- web: nginx:alpine serving the static SPA, listens on WEB_CONTAINER_PORT rendered from deploy/nginx.conf.template (envsubst), gzip + cache headers, /healthz, proxies /api/ to the api container - api: julia:1.13-bookworm, libpq5 + curl, Pkg.instantiate from the committed Manifest, listens on FARM_API_PORT, healthcheck on /api/v1/health - db: postgres:17-alpine with 001_init.sql mounted for first-run schema, pg_isready healthcheck, named volume - every port comes from .env (container port + host port separated); .env.example committed, .env ignored
98 lines
3.1 KiB
YAML
98 lines
3.1 KiB
YAML
name: irrcal
|
|
|
|
# พอร์ตทั้งหมดมาจาก .env (คัดลอก .env.example → .env แล้วแก้ค่าจริง)
|
|
# *_CONTAINER_PORT = พอร์ตที่ process ฟังในคอนเทนเนอร์
|
|
# *_HOST_PORT = พอร์ตที่แมปออกเครื่องจริง
|
|
# ไฟล์นี้ไม่ถูก commit (.env) — .env.example ขึ้น git
|
|
|
|
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}
|
|
ports:
|
|
- "${WEB_HOST_PORT:-8095}:${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: 5s
|
|
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:?ต้องตั้ง DB_PASSWORD ใน .env ก่อนรัน}
|
|
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}"
|
|
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: 10s
|
|
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:?ต้องตั้ง DB_PASSWORD ใน .env ก่อนรัน}
|
|
TZ: ${TZ:-Asia/Bangkok}
|
|
volumes:
|
|
- 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}"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 10
|
|
start_period: 10s
|
|
logging:
|
|
driver: json-file
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
volumes:
|
|
pgdata:
|