services:
  jupyterhub:
    container_name: jupyterhub
    hostname: jupyterhub
    image: ${HUB_IMAGE:-registry.metabarcoding.org/metabarschool/obijupyterhub-hub:latest}
    expose:
      - "8000"
    volumes:
      # Access to Docker socket to spawn student containers
      - /var/run/docker.sock:/var/run/docker.sock
      # JupyterHub database persistence
      - data:/srv/jupyterhub
      # Mount the parent volumes directory to access users/, shared/, course/
      - ../jupyterhub_volumes:/volumes
      # Mount config file directly (for easy modifications)
      - ./jupyterhub_config.py:/srv/jupyterhub/jupyterhub_config.py:ro
    networks:
      - jupyterhub-network
    restart: unless-stopped
    environment:
      # Docker image used for student containers (read by jupyterhub_config.py)
      STUDENT_IMAGE: ${STUDENT_IMAGE:-registry.metabarcoding.org/metabarschool/obijupyterhub-student:latest}
      # Shared password for all students
      JUPYTERHUB_PASSWORD: metabar2025
      # Admin password (for installing R packages)
      JUPYTERHUB_ADMIN_PASSWORD: admin2025
      # Optional environment variables
      DOCKER_NOTEBOOK_DIR: /home/jovyan/work
      # Use PWD to get absolute path relative to docker-compose.yml location
      HOST_VOLUMES_PATH: ${PWD}/../jupyterhub_volumes

  # ---------- Nginx ----------

  caddy:
    container_name: jupyterhub-caddy
    hostname: jupytercaddy
    image: caddy:latest
    ports:
      - "8888:80"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy-data:/data
      - caddy-config:/config
      - web:/srv                # Votre app
    networks:
      - jupyterhub-network
    restart: unless-stopped

  # ---------- SFTPGo ----------
  sftpgo:
    image: drakkan/sftpgo:latest
    container_name: jupyterhub-sftpgo
    hostname: jupytersftp
    command: sftpgo serve --loaddata-from /config/local_config.json --loaddata-clean
    expose:
      - "2022"
      - "8080"
    environment:
      SFTPGO_DATA_PROVIDER__CREATE_DEFAULT_ADMIN: true
      SFTPGO_DEFAULT_ADMIN_USERNAME: admin
      SFTPGO_DEFAULT_ADMIN_PASSWORD: admin2025
      SFTPGO_HTTPD__BINDINGS__0__CLIENT_IP_PROXY_HEADER: X-Real-IP
    volumes:
      - shared:/volumes/shared
      - course:/volumes/course
      - web:/volumes/web
      - ./sftpgo_config.json:/config/local_config.json:ro

    networks:
      - jupyterhub-network
    restart: unless-stopped

networks:
  jupyterhub-network:
    name: jupyterhub-network
    driver: bridge

volumes:
  data:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ../jupyterhub_volumes/jupyterhub
  shared:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ../jupyterhub_volumes/shared
  course:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ../jupyterhub_volumes/course
  web:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ../jupyterhub_volumes/web
  caddy-data:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ../jupyterhub_volumes/caddy/data
  caddy-config:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ../jupyterhub_volumes/caddy/config
  users:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ../jupyterhub_volumes/users