services:

  etherpad:
    image: etherpad/etherpad:1.9.7
    ports:
      - "9001:9001"
    volumes:
      - ../doodlestudent/api/APIKEY.txt:/opt/etherpad-lite/APIKEY.txt
    networks:
      - app-network
    healthcheck:
      test: [ "CMD-SHELL", "node -e \"require('http').get('http://127.0.0.1:9001', res => { process.exit(res.statusCode===200?0:1) }).on('error', ()=>process.exit(1))\"" ]
      interval: 30s
      timeout: 10s
      start_period: 15s
      retries: 5

  mail:
    image: bytemark/smtp:latest
    restart: always
    ports:
      - "2525:25"
    networks:
      - app-network

  db:
    image: mysql:8.4
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=tlc
      - MYSQL_USER=tlc
      - MYSQL_PASSWORD=tlc
    healthcheck:
      test: [ "CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-proot" ]
      interval: 10s
      timeout: 1m
      retries: 5
    networks:
      - app-network

  back:
    image: benarbause/doodleback-with-quarkus:latest
    ports:
      - "8080:8080"
    volumes:
      - ../doodlestudent/api:/app
    depends_on:
      db:
        condition: service_healthy
      etherpad:
        condition: service_healthy
    networks:
      - app-network
    restart:
      unless-stopped

  #https://dev.to/rafi021/how-to-set-up-a-monitoring-stack-with-prometheus-grafana-and-node-exporter-using-docker-compose-17cc
  #https://belginux.com/monitoring-docker-grafana-prometheus-cadvisor/
  #https://github.com/Einsteinish/Docker-Compose-Prometheus-and-Grafana/tree/master
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    restart: unless-stopped
    ports:
      - "9090:9090"
    volumes:
      - ../prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
    command:
      - "--config.file=/etc/prometheus/prometheus.yml"
    depends_on:
      - back
      - db
    networks:
      - app-network

  grafana:
    image: grafana/grafana:12.3
    container_name: grafana
    ports:
      - "3000:3000"
    #restart: unless-stopped
    volumes:
      - grafana-data:/var/lib/grafana
      - ../grafana/provisioning:/etc/grafana/provisioning
    depends_on:
      - prometheus
    environment:
      - GF_SECURITY_ADMIN_USER=tlc
      - GF_SECURITY_ADMIN_PASSWORD=tlc
      - GF_PLUGINS_PREINSTALL=grafana-munin-datasource # Telechargement du plugin via var d'env
    networks:
      - app-network

  front:
    build:
      context: ..
      dockerfile: dockerfiles/front/Dockerfile
    ports:
      - "80:80"
    volumes:
      - ../doodlestudent/front:/app
      - ../certbot/www:/var/www/certbot:ro
      - ../certbot/conf:/etc/letsencrypt:ro
    environment:
      - FLASK_ENV=development
    depends_on:
      - back
      - db
      - etherpad
      - mail
    networks:
      - app-network

  # https://stackoverflow.com/questions/57591868/how-correctly-install-ssl-certificate-using-certbot-in-docker
  certbot:
    image: certbot/certbot:v5.3.1
    container_name: certbot
    depends_on:
      - front
    volumes:
      - ../certbot/www/:/var/www/certbot/:rw
      - ../certbot/conf/:/etc/letsencrypt/:rw


networks: # Declare the network to be used by the services
  app-network: # Is a user-defined network
    name: app-network #Name of the network (optional, Docker Compose will generate one if not provided)

volumes : # Declare the volume to be used by the Grafana service (NE PAS SUPPRIMER !!)
    grafana-data: # Name of the volume