version: '3.5'

services:
  db:
    image: postgres:9.5
    container_name: ${COMPOSE_PROJECT_NAME}-mahara-db
    environment:
      POSTGRES_DB: ${MAHARA_DB_NAME}
      POSTGRES_PASSWORD: ${MAHARA_DB_PASSWD}
      POSTGRES_USER: ${MAHARA_DB_USER}
    volumes:
      - mahara-db:/var/lib/postgresql/data
    networks:
      - mahara-net

  mahara-redis:
    image: redis:6.0
    container_name: ${COMPOSE_PROJECT_NAME}-mahara-redis
    networks:
      - mahara-net

  # mahara-elastic can be used instead of the "internal" search. To do so
  # requires the elastic plugin to be configured, and then search settings
  # changed to 'elastic' in the Mahara site options.
  mahara-elastic:
    image: elasticsearch:6.8.12
    container_name: ${COMPOSE_PROJECT_NAME}-mahara-elastic
    environment:
      discovery.type: single-node
    volumes:
      - mahara-elastic:/usr/share/elasticsearch/data
    networks:
      - mahara-net

  web:
    image: mahara:${DOCKER_UBUNTU_VERSION}
    # container_name: ${COMPOSE_PROJECT_NAME}-mahara-web
    # Inject any MAHARA environment variables from the host into the container.
    # This values could come from:
    # - environment variables in the host
    # - .env file in the directory that docker compose is run from
    # - default value here.
    environment:
      - MAHARA_WWW_SERVERNAME
      - MAHARA_WWW_SERVEADMIN
      - MAHARA_DB_TYPE
      - MAHARA_DB_HOST=${COMPOSE_PROJECT_NAME}-mahara-db
      - MAHARA_DB_USER
      - MAHARA_DB_NAME
      - MAHARA_DB_PASSWD
      - MAHARA_DATA_ROOT
      - MAHARA_WWW_ROOT
      - MAHARA_SEND_EMAIL
      - MAHARA_SEND_ALL_EMAIL_TO
      - MAHARA_PRODUCTION_MODE
      - MAHARA_PERF_TO_FOOT
      - MAHARA_SKINS
      - MAHARA_ISOLOATED_INSTITUTIONS
      - MAHARA_DB_PREFIX
      - MAHARA_SITE_THEME_PREFS
      - MAHARA_CLEAN_URLS
      - MAHARA_PUBLIC_SEARCH_ALLOWED
      - MAHARA_PROBATION_ENABLED
      - MAHARA_SHOW_LOGIN_INSIDE_BLOCK
      - MAHARA_EXTERNAL_LOGIN
      - MAHARA_URL_SECRET
      - MAHARA_PASSWORD_SALT_MAIN
      - MAHARA_PASSWORD_SALT_ALT1
      - MAHARA_SESSION_HANDLER=redis
      - MAHARA_REDIS_SERVER=${COMPOSE_PROJECT_NAME}-mahara-redis:6379
      - MAHARA_REDIS_SENTINEL_SERVERS
      - MAHARA_REDIS_MASTER_GROUP
      - MAHARA_REDIS_PREFIX
      - MAHARA_ELASTICSEARCH_HOST
      - MAHARA_ELASTICSEARCH_PORT
      - MAHARA_ELASTICSEARCH_SCHEME=http
      - MAHARA_ELASTICSEARCH_USERNAME
      - MAHARA_ELASTICSEARCH_PASSWD
      - MAHARA_ELASTICSEARCH_INDEXING_USERNAME
      - MAHARA_ELASTICSEARCH_INDEXING_PASSWD
      - MAHARA_ELASTICSEARCH_INDEX_NAME
      - MAHARA_ELASTICSEARCH_BYPASS_INDEX_NAME
      - MAHARA_ELASTICSEARCH_ANALYZER
      - MAHARA_ELASTICSEARCH_TYPES
      - MAHARA_ELASTICSEARCH_IGNORE_SSL
      - MAHARA_ELASTICSEARCH_REQUEST_LIMIT
      - MAHARA_ELASTICSEARCH_REDO_LIMIT
      - MAHARA_SMTP_HOSTS
      - MAHARA_SMTP_PORT
    #ports:
      # The Mahara docker image only supports http on port 80. If https is
      # required (strongly recommended) This can be achieved by an intermediary
      # such as a NGINX reverse proxy that also terminates the https connection
      # and passed http onto Mahara.
      # In order to run this independently as a production file, chain in docker-compose.prod.yaml
      # to add the port configuration
    volumes:
      - mahara-data:/mahara/data
    networks:
        mahara-net:
          aliases:
            - ${COMPOSE_PROJECT_NAME}

  # The admin instance is responsible for triggering the cron task periodically.
  # In this compose setup we use a periodic curl command to the web container
  # to keep this simple. In a real deployment environment there may be better
  # tools for triggering scheduled tasks.
  mahara-admin:
    image: jsonfry/curl-cron
    container_name: ${COMPOSE_PROJECT_NAME}-mahara-admin
    environment:
      - MAHARA_URL_SECRET
      - CRON_SCHEDULE=* * * * *
      - OPTIONS=http://${COMPOSE_PROJECT_NAME}/lib/cron.php?urlsecret=${MAHARA_URL_SECRET}
    networks:
      - mahara-net

networks:
  mahara-net:
    external: true

volumes:
  mahara-db:
    external: true
  mahara-data:
    external: true
  mahara-elastic:
    external: true
