version: "3"

services:

  janeway-postgres:
    image: postgres:15
    volumes:
      - ./db/postgres-data:/var/lib/postgresql/data
    ports:
      - "${DB_PORT}"
    environment:
      - "POSTGRES_PASSWORD=${DB_PASSWORD}"
      - "POSTGRES_USER=${DB_USER}"
      - "POSTGRES_DB=${DB_NAME}"
    depends_on:
      - janeway-pgadmin

  janeway-pgadmin:
    image: dpage/pgadmin4
    user: root
    ports:
      - "${PGADMIN_PORT}:80"
    volumes:
      - ./db/pgadmin:/var/lib/pgadmin
    environment:
            - PGADMIN_DEFAULT_EMAIL=dev@janeway.systems
            - "PGADMIN_DEFAULT_PASSWORD=${DB_PASSWORD}"
            - PG_ADMIN_LISTEN_ADDRESS=0.0.0.0
            - GUNICORN_THREADS=2
            - PGADMIN_SERVER_JSON_FILE=/var/lib/pgadmin/servers.json
            - PGADMIN_CONFIG_SERVER_MODE=False
            - PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED=False

  janeway-mysql:
    image: mysql:8.3
    volumes:
      - ./db/mysql-data:/var/lib/mysql
    ports:
      - "${DB_PORT}"
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - "MYSQL_PASSWORD=${DB_PASSWORD}"
      - "MYSQL_USER=${DB_USER}"
      - "MYSQL_DATABASE=${DB_NAME}"

  janeway-mariadb:
    image: mariadb/server:10.2.22
    volumes:
      - ./db/mariadb-data:/var/lib/mysql
    ports:
      - "${DB_PORT}"
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - "MYSQL_PASSWORD=${DB_PASSWORD}"
      - "MYSQL_USER=${DB_USER}"
      - "MYSQL_DATABASE=${DB_NAME}"

  start_dependencies:
    image: dadarek/wait-for-dependencies
    depends_on:
     - "janeway-${DB_VENDOR}"
     - janeway-debug-smtp
    command: "janeway-${DB_VENDOR}:${DB_PORT}"

  janeway-web:
    build:
      context: .
      dockerfile: dockerfiles/Dockerfile
    volumes:
      - ./src:/vol/janeway/src
      - ./lib:/vol/janeway/lib
      - ./logs:/vol/janeway/logs
      - ./db/janeway.sqlite3:/db/janeway.sqlite3
    ports:
      - "${JANEWAY_PORT}:8000"
    environment:
      - DB_VENDOR
      - DB_HOST
      - DB_PORT
      - DB_PASSWORD
      - DB_USER
      - DB_NAME
      - PYTHONDONTWRITEBYTECODE=yes
      - JANEWAY_SETTINGS_MODULE=core.dev_settings
      - NOSE_INCLUDE_EXE=1
      - JANEWAY_EMAIL_BACKEND
      - JANEWAY_EMAIL_HOST
      - JANEWAY_EMAIL_PORT
      - JANEWAY_EMAIL_USE_TLS

    depends_on:
      - "start_dependencies"
    cap_add:
      - SYS_PTRACE

  janeway-sqlite:
    build:
      context: .
      dockerfile: dockerfiles/Dockerfile
    command: /bin/bash
    volumes:
      - ./db/janeway.sqlite:/var/lib/janeway.sqlite
  janeway-debug-smtp:
    # Use same python as janeway-web to reduce the number of images
    image: python:3.8
    entrypoint: python -u -m smtpd -c DebuggingServer -n 0.0.0.0:1025
