
services:
  # Base de données PostgreSQL
  eglpm_postgres:
    image: postgres:17.3
    container_name: postgres_db
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_EGL_PM_DB}
    ports:
      - "5432:5432"
    volumes:
      - eglpm_postgres_data:/var/lib/postgresql/data
    networks:
      - eglpm_net

  # Interface de gestion PostgreSQL
  eglpm_pgadmin:
    image: dpage/pgadmin4
    container_name: eglpm_pgadmin
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
    ports:
      - "9203:80"
    depends_on:
      - eglpm_postgres
    networks:
      - eglpm_net

  # Broker de messages RabbitMQ
  eglpm_rabbitmq:
    image: rabbitmq:3-management
    container_name: eglpm_rabbitmq_broker
    ports:
      - "5672:5672"
      - "15672:15672"
    environment:
      RABBITMQ_DEFAULT_USER: guest
      RABBITMQ_DEFAULT_PASS: guest
    volumes:
      - eglpm_rabbitmq_data:/var/lib/rabbitmq
    networks:
      - eglpm_net

  # Gestionnaire d'identité Keycloak
  eglpm_keycloak:
    image: quay.io/keycloak/keycloak:23.0.6
    container_name: eglpm_keycloak
    environment:
      KC_BOOTSTRAP_ADMIN_USERNAME: ${KEYCLOAK_ADMIN}
      KC_BOOTSTRAP_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD}
      KC_DB: postgres
      KC_DB_URL: jdbc:postgresql://eglpm_postgres:5432/${POSTGRES_EGL_PM_DB}
      KC_DB_USERNAME: ${POSTGRES_USER}
      KC_DB_PASSWORD: ${POSTGRES_PASSWORD}
    command: start-dev --http-port 9204
    ports:
      - "9204:9204"
    depends_on:
      - eglpm_postgres
    networks:
      - eglpm_net

  # API Spring Boot
  eglpm_backend:
    build: ./backend
    container_name: eglpm_backend
    ports:
      - "9207:8080"
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://eglpm_postgres:5432/${POSTGRES_EGL_PM_DB}
      SPRING_DATASOURCE_USERNAME: ${POSTGRES_USER}
      SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD}
      SPRING_RABBITMQ_HOST: eglpm_rabbitmq
      SPRING_RABBITMQ_PORT: 5672
      SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: http://eglpm_keycloak:9204/realms/master
    depends_on:
      - eglpm_postgres
      - eglpm_rabbitmq
      - eglpm_keycloak
    networks:
      - eglpm_net

  # Application Frontend Angular
  eglpm_frontend:
    build: ./frontend
    container_name: eglpm_frontend
    ports:
      - "9208:80"
    depends_on:
      - eglpm_backend
    networks:
      - eglpm_net

volumes:
  eglpm_postgres_data:
  eglpm_rabbitmq_data:

networks:
  eglpm_net:
    driver: bridge