services:
    postgres:
        image: postgres:17-alpine
        container_name: baron_postgres
        environment:
            POSTGRES_USER: ${DB_USER:-baron}
            POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
            POSTGRES_DB: ${DB_NAME:-baron_sso}
        ports:
            - "${DB_PORT:-5432}:5432"
        volumes:
            - postgres_data:/var/lib/postgresql/data
            - ./docker/init-metadata:/docker-entrypoint-initdb.d
        networks:
            - baron_net
        healthcheck:
            test:
                [
                    "CMD-SHELL",
                    "pg_isready -U ${DB_USER:-baron} -d ${DB_NAME:-baron_sso}",
                ]
            interval: 5s
            timeout: 5s
            retries: 5
        restart: always

    clickhouse:
        image: clickhouse/clickhouse-server:latest
        container_name: baron_clickhouse
        environment:
            CLICKHOUSE_USER: ${CLICKHOUSE_USER:-baron}
            CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:-password}
        networks:
            - baron_net

    redis:
        image: redis:7-alpine
        container_name: baron_redis
        restart: always
        command: redis-server --port 6389
        ports:
            - "6389:6389"
        volumes:
            - redis_data:/data
        networks:
            - baron_net

volumes:
    postgres_data:
    clickhouse_data:
    redis_data:

networks:
    baron_net:
        name: baron_net
        external: true
        driver: bridge
