version: "3.5"

services:
  mysql:
    image: mariadb:latest
    volumes:
      - db-data:/var/lib/mysql
      - ./Docker/mysql/mysql.cnf:/etc/mysql/conf.d/custom.cnf:ro
      - ./Docker/mysql/bashrc:/root/.bashrc:ro
      - "${DB_IMPORTE_FILE_D8}:/docker-entrypoint-initdb.d/materio_d8.sql"
    networks:
      - database
    hostname: mysql
    environment:
      MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
      MYSQL_DATABASE: "${DB_NAME}"
      MYSQL_USER: "${DB_USERNAME}"
      MYSQL_PASSWORD: "${DB_PASSWORD}"

  # mysql-legacy:
  #   image: mariadb:latest
  #   volumes:
  #     - db-data-legacy:/var/lib/mysql
  #     - ./Docker/mysql/mysql.cnf:/etc/mysql/conf.d/custom.cnf:ro
  #     - ./Docker/mysql/bashrc:/root/.bashrc:ro
  #     - "${DB_IMPORTE_FILE_D7}:/docker-entrypoint-initdb.d/materio_d7.sql"
  #   networks:
  #     - database
  #   hostname: mysql-legacy
  #   environment:
  #     MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
  #     MYSQL_DATABASE: "${DB_LEGACY_NAME}"
  #     MYSQL_USER: "${DB_USERNAME}"
  #     MYSQL_PASSWORD: "${DB_PASSWORD}"

  redis:
    image: redis:4
    command: redis-server /usr/local/etc/redis.conf
    volumes:
      - redis-data:/data
      - ./Docker/redis/redis.conf:/usr/local/etc/redis.conf
    networks:
      - redis
    ports:
      - "6389"

  # redis-legacy:
  #   image: redis:3
  #   command: redis-server /usr/local/etc/redis.conf
  #   volumes:
  #     - redis-legacy-data:/data
  #     - ./Docker/redis/redis.conf:/usr/local/etc/redis.conf
  #   networks:
  #     - redis
  #   ports:
  #     - "6388"

  solr-new:
    build: ./Docker/solr/
    # user: ${USER_UID}:${USER_GID}
    environment:
      - SOLR_HOME=/var/solr
    volumes:
      - ./var_solr:/var/solr 
      # - solr-data: /var/solr
      # - "${SOLR_CORES}:/var/solr/data"
      # - "${SOLR_DATA}:/var/solr"
      # - "${SOLR_CORES}:/opt/solr/server/solr"
    command:
      - solr-precreate
    networks:
      - solr
    ports:
      - 8985:8983

  # solr-legacy:
  #   build: ./Docker/solr-legacy/
  #   volumes:
  #     - solr-cores-legacy:/opt/solr/server/solr
  #   networks:
  #     - solr
  #   ports:
  #     - 8983:8983


  php:
    build: ./Docker/php/
    expose:
      - 9000
      - 9001
      - 22
    user: ${USER_UID}:${USER_GID}
    volumes:
      - php-user-data:/home/${USER_UNAME}
      - "${PROJECT_ROOT}:/var/www/html/d8.materio.com/public_html"
      - "${LEGACY_ROOT}:/var/www/html/d7.materio.com/public_html"
      - "${LOG_ROOT}/php:/var/log:rw"
      - "${XDEBUG_INI}:/usr/local/etc/php/conf.d/xdebug.ini"
    working_dir: "/var/www/html/d8.materio.com/public_html"
    networks:
      - database
      - redis
      - server
      - solr
    # for xdebug 
    # https://github.com/docker/for-linux/issues/264#issuecomment-965465879
    extra_hosts:
      - host.docker.internal:host-gateway
    # mem_limit: 512m
    depends_on:
      - mysql
      # - mysql-legacy
      - redis
      - solr-new

  # php-legacy:
  #   build: ./Docker/php-legacy/
  #   expose:
  #     - 9000
  #   volumes:
  #     - php-legacy-root-data:/root
  #     - "${LEGACY_ROOT}:/var/www/html"
  #     - "${LOG_ROOT}/php-legacy:/var/log:rw"
  #   working_dir: "/var/www/html"
  #   networks:
  #     - database
  #     - redis
  #     - server
  #     - solr
  #   depends_on:
  #     - mysql-legacy
  #     - redis-legacy
  #     - solr-legacy

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - 8891:80
    networks:
      - database
    depends_on:
      - mysql
      # - mysql-legacy
    environment:
      PMA_HOSTS: mysql #,mysql-legacy

  nginx:
    build: ./Docker/nginx/
    ports:
      - 8890:80
    volumes:
      - "${PROJECT_ROOT}:/var/www/html/d8.materio.com/public_html"
      # - "${LEGACY_ROOT}:/var/www/html/d7.materio.com/public_html"
      - "${LOG_ROOT}:/var/log:rw"
    working_dir: "/var/www/html/d8.materio.com/public_html"
    networks:
      - server
      - solr
    depends_on:
      - php

  # nginx-legacy:
  #   build: ./Docker/nginx-legacy/
  #   ports:
  #     - 8880:80
  #   volumes:
  #     - "${LEGACY_ROOT}:/var/www/html"
  #     - "${LOG_ROOT}:/var/log:rw"
  #   networks:
  #     - server
  #     - solr
  #   depends_on:
  #     - php-legacy

  npm:
    build: ./Docker/npm
    user: ${USER_UID}:${USER_GID}
    volumes:
      - "${PROJECT_ROOT}:/app"
      - npm-user-data:/home/${USER_UNAME}
    # ports:
    #   - 8788:8788
    working_dir: "/app"
    networks:
      - server
    environment:
      - DRUPAL_ROOT=/var/www/html/d8.materio.com/public_html
      - USER_UNAME=${USER_UNAME}

volumes:
    php-user-data:
    # php-legacy-root-data:
    db-data:
    # db-data-legacy:
    redis-data:
    # redis-legacy-data:
    # solr-cores-legacy:
    # solr-cores:
    npm-user-data:

networks:
    database:
    redis:
    server:
    solr:
