version: '3'

services:
  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      TZ: "UTC"  # Fuseau horaire pour éviter les avertissements
    ports:
      - "3307:3306"
    networks:
      - keycloak-network
    volumes:
      - mysql_data:/var/lib/mysql

  keycloak:
    image: quay.io/keycloak/keycloak:latest
    environment:
      KEYCLOAK_DB_VENDOR: ${KEYCLOAK_DB_VENDOR}
      KEYCLOAK_DB_ADDR: ${KEYCLOAK_DB_ADDR}
      KEYCLOAK_DB_DATABASE: ${KEYCLOAK_DB_DATABASE}
      KEYCLOAK_DB_USER: ${KEYCLOAK_DB_USER}
      KEYCLOAK_DB_PASSWORD: ${KEYCLOAK_DB_PASSWORD}
      KEYCLOAK_HTTP_PORT: 8080  # Assure que HTTP est sur le port 8080
      KEYCLOAK_HTTPS_PORT: 8443    # Désactive HTTPS en mettant le port à 0
      KEYCLOAK_HTTP_ENABLED: "true"  # Assure que HTTP est activé
      KC_DB: mysql
      KC_DB_URL: jdbc:mysql://${KEYCLOAK_DB_ADDR}/${KEYCLOAK_DB_DATABASE}
      KC_DB_USERNAME: ${KEYCLOAK_DB_USER}
      KC_DB_PASSWORD: ${KEYCLOAK_DB_PASSWORD}
      KEYCLOAK_ADMIN: admin          # Nom d'utilisateur admin
      KEYCLOAK_ADMIN_PASSWORD: kolo58SIAKA # Mot de passe admin
    ports:
      - "8080:8080"
      - "8443:8443"
    depends_on:
      - mysql
    networks:
      - keycloak-network
    command:
      - start-dev  # Démarre Keycloak en mode développement sans la configuration HTTPS
    volumes:
      - ./keycloak-config:/opt/keycloak/config

networks:
  keycloak-network:
    driver: bridge

volumes:
  mysql_data:
