version: '3.9'

services:
  app:
    build: .
    container_name: dsp_app
    restart: unless-stopped
    env_file:
      - .env
    ports:
      - "4010:80"
      - "8082:80"
    environment:
      DB_HOST: db
      DB_PORT: 3306
      DB_NAME: niph_dsps
      DB_USER: dsp_user
      DB_PASS: dsp_pass
      JUPYTER_EXTERNAL_URL: ${JUPYTER_EXTERNAL_URL:-}
      JUPYTER_PORT: ${JUPYTER_PORT:-443}
      DSP_APP_ORIGINS: ${DSP_APP_ORIGINS:-}
      DSP_FRAME_ANCESTORS: ${DSP_FRAME_ANCESTORS:-}
    volumes:
      - ./:/var/www/html
    depends_on:
      - db

  db:
    image: mysql:8.0
    container_name: dsp_db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: niph_dsps
      MYSQL_USER: dsp_user
      MYSQL_PASSWORD: dsp_pass
    ports:
      - "3307:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./db/niph_dsps.sql:/docker-entrypoint-initdb.d/01-init.sql:ro

  phpmyadmin:
    image: phpmyadmin:latest
    container_name: dsp_phpmyadmin
    restart: unless-stopped
    ports:
      - "8081:80"
    environment:
      PMA_HOST: db
      PMA_USER: dsp_user
      PMA_PASSWORD: dsp_pass
      UPLOAD_LIMIT: 64M
    depends_on:
      - db

  jupyterhub:
    build:
      context: ./docker/jupyterhub
    container_name: dsp_jupyterhub
    restart: unless-stopped
    env_file:
      - .env
    ports:
      - "${JUPYTERHUB_PORT:-443}:8000"
      - "8888:8000"
    environment:
      DSP_JH_NETWORK: dsp_default
      DSP_APP_CONTAINER: dsp_app
      DSP_WORKSPACE_ROOT: ${DSP_WORKSPACE_ROOT:-/var/www/html/uploads/jupyter_workspace}
    volumes:
      - ./uploads/jupyter_workspace:/var/www/html/uploads/jupyter_workspace
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - app

volumes:
  mysql_data:
