# Les variables globales sont présentes dans le fichier .env
# - TAG
# - REGISTRY_URL
# - POSTGRES (user, password)
# - LOGGING_LEVEL_*

version: "3"

services:
  # Zookeeper basé sur la documentation officielle de Bitnami
  ## https://github.com/bitnami/containers/blob/main/bitnami/zookeeper/docker-compose.yml
  ## https://hub.docker.com/r/bitnami/zookeeper/
  zookeeper:
    image: docker.io/bitnami/zookeeper:3.9
    container_name: zookeeper
    ports:
      - "2181:2181"
    volumes:
      - "numecoeval_zookeeper_data:/bitnami"
    environment:
      ALLOW_ANONYMOUS_LOGIN: "yes"
  
  # Kafka basé sur la documentation officielle de Bitnami
  ## https://github.com/bitnami/containers/blob/main/bitnami/kafka/docker-compose.yml
  ## https://hub.docker.com/r/bitnami/kafka/
  kafka:
    image: docker.io/bitnami/kafka:3.6
    depends_on:
      - zookeeper
    container_name: kafka
    ports:
      - "9092:9092"
    volumes:
      - "numecoeval_kafka_data:/bitnami"
    environment:
      ALLOW_PLAINTEXT_LISTENER: "yes"
      KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"

  # Postgres basé sur la documentation officielle de Postgres sur Dockerhub
  ## https://hub.docker.com/_/postgres
  postgresdb:
    image: docker.io/postgres:15
    container_name: postgresdb
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: $POSTGRES_USER
      POSTGRES_PASSWORD: $POSTGRES_PASSWORD
    volumes:
      - "numecoeval_postgres_data:/var/lib/postgresql/data"

  api-rest-referentiels:
    image: ${REGISTRY_URL}/api-referentiel:${TAG}
    depends_on:
      - postgresdb
    ports:
      - "${PORT_PREFIX}8080:8080"
    environment:
      SERVER_PORT: "8080"
      MANAGEMENT_SERVER_PORT: "8080"
      SPRING_JPA_HIBERNATE_DDL-AUTO: "update"
      SPRING_DATASOURCE_URL: "jdbc:postgresql://postgresdb:5432/postgres?reWriteBatchedInserts=true"
      SPRING_DATASOURCE_USERNAME: $POSTGRES_USER
      SPRING_DATASOURCE_PASSWORD: $POSTGRES_PASSWORD
      SPRING_SERVLET_MULTIPART_MAXREQUESTSIZE: "45MB"
      SPRING_SERVLET_MULTIPART_MAXFILESIZE: "10MB"
      SPRING_JPA_PROPERTIES_HIBERNATE_JDBC_BATCHSIZE: "1000"
      SPRING_JPA_PROPERTIES_HIBERNATE_ORDERINSERTS: "true"
      SPRING_JPA_SHOWSQL: "false"
      NUMECOEVAL_URLS_ALLOWED: "http://localhost,http://api-rest-referentiels"
      LOGGING_LEVEL_ROOT: $LOGGING_LEVEL_ROOT
      LOGGING_LEVEL_ORG_SPRINGFRAMEWORK: $LOGGING_LEVEL_ORG_SPRINGFRAMEWORK

  api-rest-expositiondonneesentrees:
    image:  ${REGISTRY_URL}/api-expositiondonneesentrees:${TAG}
    depends_on:
      - postgresdb
      - api-rest-referentiels
    ports:
      - "${PORT_PREFIX}8081:8080"
    environment:
      SERVER_PORT: "8080"
      MANAGEMENT_SERVER_PORT: "8080"
      NUMECOEVAL_KAFKA_TOPIC_MAX_MESSAGES_SIZE: "52428800"
      NUMECOEVAL_REFERENTIEL_SERVER_URL: "http://api-rest-referentiels:8080"
      SPRING_SERVLET_MULTIPART_MAXREQUESTSIZE: "45MB"
      SPRING_SERVLET_MULTIPART_MAXFILESIZE: "10MB"
      SPRING_DATASOURCE_URL: "jdbc:postgresql://postgresdb:5432/postgres?reWriteBatchedInserts=true"
      SPRING_DATASOURCE_USERNAME: $POSTGRES_USER
      SPRING_DATASOURCE_PASSWORD: $POSTGRES_PASSWORD
      SPRING_JPA_PROPERTIES_HIBERNATE_GENERATESTATISTICS: "true"
      SPRING_JPA_PROPERTIES_HIBERNATE_ORDERINSERTS: "true"
      SPRING_JPA_PROPERTIES_HIBERNATE_JDBC_BATCHSIZE: "1000"
      SPRING_JPA_SHOWSQL: "false"
      NUMECOEVAL_URLS_ALLOWED: "http://localhost,http://api-rest-expositiondonneesentrees"
      LOGGING_LEVEL_ROOT: $LOGGING_LEVEL_ROOT
      LOGGING_LEVEL_ORG_SPRINGFRAMEWORK: $LOGGING_LEVEL_ORG_SPRINGFRAMEWORK

  api-event-donneesentrees:
    image: ${REGISTRY_URL}/api-event-donneesentrees:${TAG}
    depends_on:
      - kafka
      - postgresdb
      - api-rest-expositiondonneesentrees
    ports:
      - "${PORT_PREFIX}8083:8080"
    environment:
      SERVER_PORT: "8080"
      MANAGEMENT_SERVER_PORT: "8080"
      SPRING_KAFKA_BOOTSTRAPSERVERS: "kafka:9092"
      SPRING_DATASOURCE_URL: "jdbc:postgresql://postgresdb:5432/postgres?reWriteBatchedInserts=true"
      SPRING_DATASOURCE_USERNAME: $POSTGRES_USER
      SPRING_DATASOURCE_PASSWORD: $POSTGRES_PASSWORD
      LOGGING_LEVEL_ROOT: $LOGGING_LEVEL_ROOT
      LOGGING_LEVEL_ORG_SPRINGFRAMEWORK: $LOGGING_LEVEL_ORG_SPRINGFRAMEWORK

  api-event-calculs:
    image: ${REGISTRY_URL}/api-event-calculs:${TAG}
    depends_on:
      - kafka
      - postgresdb
    ports:
      - "${PORT_PREFIX}8085:8080"
    environment:
      SERVER_PORT: "8080"
      MANAGEMENT_SERVER_PORT: "8080"
      NUMECOEVAL_URLS_ALLOWED: "http://localhost,http://api-event-calculs"
      NUMECOEVAL_REFERENTIELS_URL: "http://api-rest-referentiels:8080"
      SPRING_KAFKA_BOOTSTRAPSERVERS: "kafka:9092"
      SPRING_DATASOURCE_URL: "jdbc:postgresql://postgresdb:5432/postgres?reWriteBatchedInserts=true"
      SPRING_DATASOURCE_USERNAME: $POSTGRES_USER
      SPRING_DATASOURCE_PASSWORD: $POSTGRES_PASSWORD
      LOGGING_LEVEL_ROOT: $LOGGING_LEVEL_ROOT
      LOGGING_LEVEL_ORG_SPRINGFRAMEWORK: $LOGGING_LEVEL_ORG_SPRINGFRAMEWORK

volumes:
  numecoeval_zookeeper_data:
    driver: local
  numecoeval_kafka_data:
    driver: local
  numecoeval_postgres_data:
    driver: local
