version: "3.5"
services:
    web:
      build: .
      container_name: web
      ports:
            - 443:443
      volumes:
          - ./api:/var/www/html/api
          - ./bin:/var/www/html/bin
          - ./lib:/var/www/html/lib
          #TODO Fix this in the code
          - ./tmp:/var/www/html/tmp
          - ./tmp:/smartdata/tmp
          #TODO Custom certificates
          #- ./crt:/etc/apache2/ssl/server.crt
          #- ./key:/etc/apache2/ssl/server.key
          #- ./ca:/etc/apache2/ssl/ca.crt
          - certificates:/certmanager/certificates
      depends_on:
          - cassandra
          - mariadb
    mariadb:
      image: mariadb:latest
      container_name: mariadb
      volumes:
          - mariadb:/var/lib/mysql
          - ./docker/db:/docker-entrypoint-initdb.d/
      #deploy:
      # replicas: 0
      env_file:
          - docker/variables.env

    cassandra:
      image: cassandra:4
      container_name: cassandra
      healthcheck:
        test: ["CMD-SHELL", "[ $$(nodetool statusgossip) = running ]"]
        interval: 60s
        timeout: 10s
        retries: 5
      ulimits:
        memlock: -1
      #deploy:
      # replicas: 0
      volumes:
        - cassandra:/var/lib/cassandra
        - ./docker/cassandra:/docker-entrypoint-initdb.d/
      env_file:
        - docker/variables.env

    cassandra-setup:
      build:
        context: docker/cassandra-setup
      depends_on:
        cassandra:
          condition: service_healthy
      volumes:
        - ./docker/cassandra-setup:/scripts/       
      env_file:
        - docker/variables.env        

    #grafana:
    #  image: grafana
    #  container_name: grafana
    #  deploy:
    #    replicas: 0
    #  env_file:
    #    - docker/variables.env
    #  ports:
    #    - 3000:3000
    #  depends_on:
    #    - cassandra

    mongo:
      image: mongo:7.0.12
      volumes:
        - mongo:/data/db
        - ./docker/mongo:/docker-entrypoint-initdb.d/
      env_file:
        - docker/variables.env

    smartdata-context-api:
      build: ./context/
      env_file:
        - docker/variables.env

    smartdata-context-ingress:
      build: ./ingress/
      env_file:
        - docker/variables.env
      volumes:
        - ./docker/ingress/config:/app/config

    minio:
      image: minio/minio:latest
      container_name: minio
      env_file:
        - docker/variables.env
      ports:
        - "9000:9000"    # Port for S3 API access
        - "9001:9001"    # Port for MinIO console
      volumes:
        - minio_data:/data   # Volume for persisting data
      command: server /data --console-address ":9001"


    tikiwikidb-test:
      image: mariadb:latest
      container_name: tikiwikidb-test
      volumes:
          - tikiwikidb-test:/var/lib/mysql
          - ./docker/tikiwikidb-test:/docker-entrypoint-initdb.d/
      profiles:
        - test    
      env_file:
          - docker/tikiwikidb-test/variables.env

    smartdatacontext-test:
      build: 
        context: ./docker/smartdatacontext-test
      profiles:
        - test    

volumes:
  certificates:
  mariadb:
  cassandra:
  mongo:
  minio_data:
  tikiwikidb-test:

