services:
  database:
    build: ./db
    image: bunker-database:latest
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    # optional: nur lokal erreichbar, falls du psql vom Server nutzen willst
    ports:
      - "127.0.0.1:${POSTGRES_PORT}:5432"
    volumes:
      - ./volumes/postgres:/var/lib/postgresql/data
      - ./volumes/db-init/data:/docker-entrypoint-initdb.d/data:ro
      - ./volumes/data:/data

  server-app:
    build: ./server-app
    image: bunker-server-app:latest
    restart: unless-stopped
    environment:
      APP_PORT: ${APP_PORT}
      DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/${POSTGRES_DB}?sslmode=disable
    expose:
      - "8080"
    volumes:
      - ./volumes/web:/app/web
    depends_on:
      - database

  ai-worker:
    build: ./ai-worker
    image: bunker-ai-worker:latest
    restart: unless-stopped
    environment:
      DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/${POSTGRES_DB}?sslmode=disable
      SD_MODEL_PATH: /app/models/sd15
      IMAGE_OUTPUT_DIR: /app/images
    volumes:
      - ./volumes/ai-models:/app/models
      - ./volumes/images:/app/images
    depends_on:
      - database

  background-worker:
    build: ./background-worker
    image: bunker-background-worker:latest
    restart: unless-stopped
    environment:
      DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/${POSTGRES_DB}?sslmode=disable
      RMV_API_KEY: ${RMV_API_KEY}
    depends_on:
      - database

volumes:
  caddy_data:
  caddy_config: