File size: 3,654 Bytes
f368481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Maker harness — hạ tầng đầy đủ (atria-style), thêm dần theo từng phase.
# Phase 3: db + adminer. Phase 4 thêm redis. Phase 5 thêm keycloak. Phase 6 thêm app.
#
# Chạy hybrid (khuyến nghị cho dev Windows/Playwright): chỉ bật hạ tầng rồi chạy
# app trên host bằng .\web.ps1 với DATABASE_URL trỏ localhost:
#   docker compose up -d db adminer
#   $env:DATABASE_URL="postgresql://maker:maker@localhost:5432/maker"; .\web.ps1
services:
  db:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      - POSTGRES_DB=maker
      - POSTGRES_USER=maker
      - POSTGRES_PASSWORD=maker
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./schema.sql:/docker-entrypoint-initdb.d/schema.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U maker -d maker"]
      interval: 5s
      timeout: 5s
      retries: 5

  adminer:
    image: adminer:latest
    restart: unless-stopped
    ports:
      - "8081:8080"
    environment:
      - ADMINER_DEFAULT_SERVER=db
    depends_on:
      db:
        condition: service_healthy

  # Redis — bus step events (Phase 4). App tự degrade in-memory nếu vắng.
  redis:
    image: redis:7-alpine
    restart: unless-stopped
    ports:
      - "6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 10

  # App — maker harness (Phase 6). Trỏ vào db/redis/keycloak nội bộ compose.
  # Single worker cố ý (1 Chromium + serialize tool). Không bật service này nếu
  # chạy hybrid (app trên host) — dùng `docker compose up -d db redis keycloak`.
  app:
    build: .
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      - GROQ_API_KEY=${GROQ_API_KEY}
      - HARNESS_MODEL=${HARNESS_MODEL:-gpt-oss-120b}
      - CNC_HEADLESS=1
      - DATABASE_URL=${DATABASE_URL:-postgresql://maker:maker@db:5432/maker}
      - REDIS_URL=${REDIS_URL:-redis://redis:6379/0}
      - AUTH_MODE=${AUTH_MODE:-keycloak}
      - SESSION_SECRET=${SESSION_SECRET:-dev-maker-secret-change-me}
      - KEYCLOAK_URL=http://keycloak:8080
      - KEYCLOAK_PUBLIC_URL=${KEYCLOAK_PUBLIC_URL:-http://localhost:8082}
      - KEYCLOAK_REALM=maker
      - KEYCLOAK_CLIENT_ID=maker-web
    volumes:
      - ./modules:/app/modules            # sửa/thêm module không cần build lại
      - maker_var:/app/var                # uploads + output runtime
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:8080/healthz"]
      interval: 15s
      timeout: 5s
      retries: 5
      start_period: 40s
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
      keycloak:
        condition: service_started

  # Keycloak — auth OIDC (Phase 5). Dùng chung Postgres (DB 'keycloak' tạo bởi
  # schema.sql). App chỉ cần khi AUTH_MODE=keycloak; realm 'maker' import lúc start.
  keycloak:
    image: quay.io/keycloak/keycloak:26.0
    restart: unless-stopped
    command: ["start-dev", "--import-realm"]
    environment:
      - KC_DB=postgres
      - KC_DB_URL=jdbc:postgresql://db:5432/keycloak
      - KC_DB_USERNAME=maker
      - KC_DB_PASSWORD=maker
      - KC_HOSTNAME=localhost
      - KC_HTTP_ENABLED=true
      - KEYCLOAK_ADMIN=admin
      - KEYCLOAK_ADMIN_PASSWORD=${KEYCLOAK_ADMIN_PASSWORD:-admin}
    ports:
      - "8082:8080"
    volumes:
      - ./keycloak/realm-export.json:/opt/keycloak/data/import/realm-export.json:ro
    depends_on:
      db:
        condition: service_healthy

volumes:
  postgres_data:
  maker_var: