networks:
  transcendance-network:
    driver: bridge
  monitoring:
    driver: bridge
services:
  ###############
  #    USER     #
  ###############
  frontend:
    build: ./frontend
    container_name: frontend
    restart: on-failure:3
    networks:
      - transcendance-network
    volumes:
      - static-volume:/volumes/static
    logging:
      driver: gelf
      options:
        gelf-address: "udp://127.0.0.1:12201"
        tag: "{{.Name}}"

  # 
  # The "entry point" as in it does all of this:
  #  - serve files (images, static files, video)
  #  - redirect request to appropirate service (reverse proxy)
  #  - be the one that handles TLS/SSL (basically HTTPS)
  #  - other stuff I don't know yet
  nginx:
    build: ./nginx
    container_name: nginx
    restart: always
    networks:
      - transcendance-network
    ports:
      - '8888:443'
    volumes:
      # if you need to share files with nginx, you do it here.
      - static-volume:/volumes/static
      - images-volume:/volumes/icons
    environment:
      # this can stay the same for developpement. This is an alias to `localhost`
      - NGINX_DOMAIN=local.maix.me
    logging:
      driver: gelf
      options:
        gelf-address: "udp://127.0.0.1:12201"
        tag: "{{.Name}}"

  ###############
  #    ICONS    #
  ###############
  icons:
    build:
      context: ./src/
      args:
        - SERVICE=icons
        #- EXTRA_FILES=icons/extra
    container_name: icons
    restart: always
    networks:
      - transcendance-network
    volumes:
      - images-volume:/volumes/store
      - sqlite-volume:/volumes/database
    environment:
      - JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
      - USER_ICONS_STORE=/volumes/store
      - DATABASE_DIR=/volumes/database
    logging:
      driver: gelf
      options:
        gelf-address: "udp://127.0.0.1:12201"
        tag: "{{.Name}}"


  ###############
  #    AUTH     #
  ###############
  auth:
    build:
      context: ./src/
      args:
        - SERVICE=auth
        - EXTRA_FILES=auth/extra
    container_name: auth 
    restart: always
    networks:
      - transcendance-network
    volumes:
      - sqlite-volume:/volumes/database
      - static-volume:/volumes/static
    environment:
      - JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
      - DATABASE_DIR=/volumes/database
      - PROVIDER_FILE=/extra/providers.toml
    logging:
      driver: gelf
      options:
        gelf-address: "udp://127.0.0.1:12201"
        tag: "{{.Name}}"


  ###############
  #    CHAT     #
  ###############
  chat:
    build:
      context: ./src/
      args:
        - SERVICE=chat
        - EXTRA_FILES=chat/extra
    container_name: chat 
    restart: always
    networks:
      - transcendance-network
    volumes:
      - sqlite-volume:/volumes/database
      - static-volume:/volumes/static
    environment:
      - JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
      - DATABASE_DIR=/volumes/database
      - PROVIDER_FILE=/extra/providers.toml
      - SESSION_MANAGER=${SESSION_MANAGER}

  ###############
  #    USER     #
  ###############
  user:
    build:
      context: ./src/
      args:
        - SERVICE=user
        # - EXTRA_FILES=user/extra
    container_name: user
    restart: always
    networks:
      - transcendance-network
    volumes:
      - sqlite-volume:/volumes/database
      - static-volume:/volumes/static
    environment:
      - JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
      - DATABASE_DIR=/volumes/database
    logging:
      driver: gelf
      options:
        gelf-address: "udp://127.0.0.1:12201"
        tag: "{{.Name}}"


  ###############
  # MONITORING  #
  ###############

  grafana:
    container_name: monitoring-grafana
    image: grafana/grafana-enterprise
    restart: always
    networks:
      - transcendance-network
      - monitoring
    depends_on:
      - prometheus
    ports:
      - '3000:3000'
    volumes:
      - ./monitoring/grafana/alerting:/etc/grafana/provisioning/alerting
      - ./monitoring/grafana/datasources:/etc/grafana/provisioning/datasources
      - ./monitoring/grafana/dashboards-config:/etc/grafana/provisioning/dashboards
      - ./monitoring/grafana/dashboards:/var/lib/grafana/dashboards
      - grafana-data:/var/lib/grafana
    environment:
      # this can stay the same for developpement. This is an alias to `localhost`
      - NGINX_DOMAIN=local.maix.me
      - GF_LOG_LEVEL=warn
      - GF_SERVER_ROOT_URL=http://local.maix.me:3000
      - GF_SECURITY_ADMIN_USER=${GRAFANA_ADMIN_USER}
      - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASS}
    logging:
      driver: gelf
      options:
        gelf-address: "udp://127.0.0.1:12201"
        tag: "{{.Name}}"

  prometheus:
    image: prom/prometheus:latest
    container_name: monitoring-prometheus
    networks:
      - transcendance-network
      - monitoring
    volumes:
      - ./monitoring/prometheus:/etc/prometheus/
    restart: unless-stopped
    logging:
      driver: gelf
      options:
        gelf-address: "udp://127.0.0.1:12201"
        tag: "{{.Name}}"

  cadvisor:
    image: gcr.io/cadvisor/cadvisor:latest
    networks:
      - monitoring
    container_name: monitoring-cadvisor
    ports:
      - '8080:8080'
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:ro
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
    restart: unless-stopped
    logging:
      driver: gelf
      options:
        gelf-address: "udp://127.0.0.1:12201"
        tag: "{{.Name}}"


  blackbox:
    image: prom/blackbox-exporter:latest
    container_name: monitoring-blackbox
    networks:
      - transcendance-network
    ports:
      - "9115:9115"
    restart: unless-stopped
    logging:
      driver: gelf
      options:
        gelf-address: "udp://127.0.0.1:12201"
        tag: "{{.Name}}"



  ###############
  #     LOGS    #
  ###############

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.23
    container_name: logs-elasticsearch
    networks:
      - monitoring
    environment:
      - discovery.type=single-node
      - ES_JAVA_OPTS=-Xms512m -Xmx512m
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
    volumes:
      - elastic-data:/usr/share/elasticsearch/data
      - ./logs/elasticsearch:/setup
    ports:
      - "9200:9200"
    command: ["/setup/bootstrap.sh"]
    restart: unless-stopped

  logstash:
    image: docker.elastic.co/logstash/logstash:7.17.23
    container_name: logs-logstash
    depends_on:
      - elasticsearch
    networks:
      - monitoring
    volumes:
      - ./logs/logstash/pipeline:/usr/share/logstash/pipeline
    ports:
      - "12201:12201/udp"
    restart: unless-stopped

  kibana:
    image: docker.elastic.co/kibana/kibana:7.17.23
    container_name: logs-kibana
    depends_on:
      - elasticsearch
    networks:
      - monitoring
    environment:
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
      - SERVER_PUBLICBASEURL=http://local.maix.me:5601
      - ELASTICSEARCH_USERNAME=elastic
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
    ports:
      - "5601:5601"
    volumes:
      - ./logs/kibana:/setup
    command: ["/setup/bootstrap.sh"]
    restart: unless-stopped

volumes:
  images-volume:
  sqlite-volume:
  static-volume:
  grafana-data:
  elastic-data:
