version: '3.8'

services:
  # PostgreSQL Database (compartilhado)
  postgres:
    image: postgres:13-alpine
    container_name: flowable-postgres
    environment:
      POSTGRES_USER: flowable
      POSTGRES_PASSWORD: flowable
      POSTGRES_DB: flowable
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U flowable -d flowable"]
      interval: 5s
      timeout: 5s
      retries: 10

  # Flowable REST API
  flowable-rest:
    image: flowable/flowable-rest:6.8.0
    container_name: flowable-rest
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/flowable
      SPRING_DATASOURCE_USERNAME: flowable
      SPRING_DATASOURCE_PASSWORD: flowable
      SPRING_DATASOURCE_DRIVER-CLASS-NAME: org.postgresql.Driver
      FLOWABLE_DATABASE_SCHEMA_UPDATE: "true"
      FLOWABLE_COMMON_APP_IDM-ADMIN_USER: admin
      FLOWABLE_COMMON_APP_IDM-ADMIN_PASSWORD: admin123
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

  # Flowable UI (novo serviço)
  flowable-ui:
    image: flowable/flowable-ui:6.8.0
    container_name: flowable-ui
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/flowable  # Mesmo banco
      SPRING_DATASOURCE_USERNAME: flowable
      SPRING_DATASOURCE_PASSWORD: flowable
      SPRING_DATASOURCE_DRIVER-CLASS-NAME: org.postgresql.Driver
      FLOWABLE_DATABASE_SCHEMA_UPDATE: "false"  # Já criado pelo REST API
      FLOWABLE_ADMIN_USER: admin
      FLOWABLE_ADMIN_PASSWORD: admin123
    ports:
      - "8888:8080"  # Porta diferente da REST API
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

volumes:
  postgres_data: