implement Phase 1-2
This commit is contained in:
parent
41573b3c4f
commit
b976cf3124
23 changed files with 1291 additions and 79 deletions
105
docker-compose.yml
Normal file
105
docker-compose.yml
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
# Local dev infrastructure — Word Versioning
|
||||
# ใช้ร่วมกับ .env (สร้างจาก .env.example) — ทุก credential อยู่ใน env เท่านั้น ห้าม hardcode
|
||||
#
|
||||
# docker compose up -d # รัน infra: db + minio (+ init buckets) + keycloak
|
||||
# docker compose --profile api up -d # เพิ่ม backend API (หลัง Phase 2 มี Dockerfile)
|
||||
|
||||
name: word-versioning
|
||||
|
||||
services:
|
||||
# --- PostgreSQL (EF Core / Npgsql) ---------------------------------
|
||||
db:
|
||||
image: postgres:16
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
ports:
|
||||
- "5432:5432" # เปิดให้ backend ที่รันด้วย dotnet run บน host เชื่อมได้
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
|
||||
# --- MinIO (S3-compatible สำหรับไฟล์ .docx) -----------------------
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
command: server /data --console-address ":9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
|
||||
# ให้ healthcheck (mc ready) เรียกผ่าน alias "local" ได้
|
||||
MC_HOST_local: http://${MINIO_ROOT_USER}:${MINIO_ROOT_PASSWORD}@localhost:9000
|
||||
ports:
|
||||
- "9000:9000" # S3 API
|
||||
- "9001:9001" # MinIO console
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "mc", "ready", "local"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 12
|
||||
|
||||
# สร้าง bucket docx-versions + docx-templates แบบ private (anonymous = none)
|
||||
# idempotent — รันซ้ำได้ด้วย --ignore-existing
|
||||
minio-init:
|
||||
image: minio/mc:latest
|
||||
depends_on:
|
||||
minio:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
|
||||
entrypoint: >
|
||||
/bin/sh -c "
|
||||
set -e;
|
||||
mc alias set local http://minio:9000 $$MINIO_ROOT_USER $$MINIO_ROOT_PASSWORD;
|
||||
mc mb --ignore-existing local/docx-versions;
|
||||
mc mb --ignore-existing local/docx-templates;
|
||||
mc anonymous set none local/docx-versions;
|
||||
mc anonymous set none local/docx-templates;
|
||||
echo 'MinIO buckets ready: docx-versions, docx-templates (private)';
|
||||
"
|
||||
|
||||
# --- Keycloak (OIDC) -----------------------------------------------
|
||||
# realm word-versioning import อัตโนมัติตอน startup จาก /keycloak/realm-export.json
|
||||
# ไม่ mount volume เก็บข้อมูล realm โดยตั้งใจ: ตั้งแต่ compose down ขึ้นไป realm จะถูก
|
||||
# import ใหม่จาก realm-export.json (ไฟล์นี้คือ source of truth ของ realm config ฝั่ง dev)
|
||||
# — แก้อะไรใน realm ให้แก้ใน realm-export.json แล้ว docker compose down && up
|
||||
keycloak:
|
||||
image: quay.io/keycloak/keycloak:26.2
|
||||
command: start-dev --import-realm
|
||||
environment:
|
||||
KC_BOOTSTRAP_ADMIN_USERNAME: ${KC_BOOTSTRAP_ADMIN_USERNAME}
|
||||
KC_BOOTSTRAP_ADMIN_PASSWORD: ${KC_BOOTSTRAP_ADMIN_PASSWORD}
|
||||
ports:
|
||||
- "8080:8080" # admin console + OIDC endpoints
|
||||
volumes:
|
||||
- ./keycloak/realm-export.json:/opt/keycloak/data/import/realm-export.json:ro
|
||||
|
||||
# --- Backend API (ยังไม่เปิดใช้ — รอ Phase 2 สร้าง Dockerfile) -----
|
||||
# รันฝั่ง host ด้วย `dotnet run` ได้เลย โดยชี้ config ไปที่ localhost:5432 / localhost:9000
|
||||
# หรือรันใน network นี้: docker compose --profile api up -d --build
|
||||
api:
|
||||
build:
|
||||
context: ./backend
|
||||
dockerfile: WordVersioning.Api/Dockerfile
|
||||
profiles: ["api"]
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
minio:
|
||||
condition: service_healthy
|
||||
keycloak:
|
||||
condition: service_started
|
||||
ports:
|
||||
- "8081:8080"
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
minio_data:
|
||||
Loading…
Add table
Add a link
Reference in a new issue