version: '3.8'

services:
  mariadb:
    image: mariadb:11.3
    restart: always
    env_file:
      - ./.env
    volumes:
      - mariadb_data:/var/lib/mysql
    ports:
      - 3306:3306
    networks:
      - network  # Adding the network communication between containers
    environment:
      - MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD}
      - MOODLE_DATABASE_USER=${MOODLE_DATABASE_USER}
      - MOODLE_DATABASE_PASSWORD=${MOODLE_DATABASE_PASSWORD}


  moodle:
    env_file:
      - ./.env
    restart: always
    build:  # Building own Moodle container from Dockerfile.
      context: ./moodle  # The context of the build (where is Dockerfile)
      dockerfile: Dockerfile
      args:
        - MOODLE_BASE_DIR=${MOODLE_BASE_DIR}
        - MOODLE_BASE_DIR_DATA=${MOODLE_BASE_DIR_DATA}
        - MOODLE_DATABASE_TYPE=mariadb
        - MOODLE_DATABASE_HOST=${MOODLE_DATABASE_HOST}
        - MOODLE_DATABASE_NAME=${MOODLE_DATABASE_NAME}
        - MOODLE_DATABASE_USER=${MOODLE_DATABASE_USER}
        - MOODLE_DATABASE_PASSWORD=${MOODLE_DATABASE_PASSWORD}
        - MOODLE_PHPUNIT_DATAROOT=${MOODLE_PHPUNIT_DATAROOT}
    ports:
      - 80:80
      - 443:443
      - 9003:9003
    dns:
      - 8.8.8.8
      - 8.8.4.4
    depends_on: # Dependency from MariaDB service
      - mariadb
    volumes:
      - ${PWD}/asystgrade:${MOODLE_BASE_DIR}/local/asystgrade  # Sync the plugin folder with the container
      - moodle_data:${MOODLE_BASE_DIR}  # Volume for Moodle
      - moodledata:${MOODLE_BASE_DIR_DATA}  # Volume for Moodle data
      - moodle_phpunit_data:${MOODLE_PHPUNIT_DATAROOT}
    networks:
      - network  # Adding the network communication between containers

  flask:
    build:
      context: ./flask  # The context of the Flask build (where is Dockerfile)
      dockerfile: Dockerfile
    env_file:
      - ./.env
    restart: always
    ports:
      - 5000:5000
    volumes:
      - ./flask:/app
    networks:
      - network

volumes: # Defining local volumes
  moodledata:
    driver: local
  mariadb_data:
    driver: local
  moodle_data:
    driver: local
  asystgrade:
    driver: local
  flask:
    driver: local
  moodle_phpunit_data:
    driver: local

networks:
  network:  # Creating a network