version: '3.8'
name: dev

services:
  backend-a:
    build:
      context: ../../backend/
      dockerfile: ../deploy/dev/Dockerfile.backend
    environment:
      TOOLSHED_DB_PATH: /mnt/db.sqlite3
      TOOLSHED_USERFILES_PATH: /mnt/userfiles
      TOOLSHED_SETUP_PATH: /mnt/testdata.py
    volumes:
      - ../../backend:/code
      - ../../.git:/git:ro
      - ./instance_a/a.env:/code/.env
      - ./instance_a/testdata.py:/mnt/testdata.py
      - ./instance_a/a.sqlite3:/mnt/db.sqlite3
      - ./instance_a/userfiles:/mnt/userfiles
    expose:
      - 8000
    command: bash -c "python configure.py; python configure.py testdata; python manage.py runserver 0.0.0.0:8000 --insecure"

  backend-b:
    build:
      context: ../../backend/
      dockerfile: ../deploy/dev/Dockerfile.backend
    environment:
      TOOLSHED_DB_PATH: /mnt/db.sqlite3
      TOOLSHED_USERFILES_PATH: /mnt/userfiles
      TOOLSHED_SETUP_PATH: /mnt/testdata.py
    volumes:
      - ../../backend:/code
      - ../../.git:/git:ro
      - ./instance_b/b.env:/code/.env
      - ./instance_b/testdata.py:/mnt/testdata.py
      - ./instance_b/b.sqlite3:/mnt/db.sqlite3
      - ./instance_b/userfiles:/mnt/userfiles
    expose:
      - 8000
    command: bash -c "python configure.py; python configure.py testdata; python manage.py runserver 0.0.0.0:8000 --insecure"

  frontend:
    build:
      context: ../../frontend/
      dockerfile: ../deploy/dev/Dockerfile.frontend
    volumes:
      - ../../frontend:/app
      - ../../.git:/git:ro
      - /app/node_modules
    expose:
      - 5173
    command: bash -c "npm install && npm run dev -- --host"

  wiki:
    build:
      context: ../../
      dockerfile: deploy/dev/Dockerfile.wiki
    volumes:
      - ../../mkdocs.yml:/wiki/mkdocs.yml
      - ../../docs:/wiki/docs
    expose:
      - 8001
    command: mkdocs serve --dev-addr=0.0.0.0:8001

  proxy-a:
    build:
      context: ./
      dockerfile: Dockerfile.proxy
    volumes:
      - ./instance_a/nginx-a.dev.conf:/etc/nginx/nginx.conf:ro
      - ./instance_a/dns.json:/var/www/dns.json:ro
      - ./instance_a/domains.json:/var/www/domains.json:ro
      - ./instance_a/userfiles:/var/www/userfiles:ro
    ports:
      - "127.0.0.1:8080:8080"
      - "127.0.0.3:5353:5353"

  proxy-b:
    build:
      context: ./
      dockerfile: Dockerfile.proxy
    volumes:
      - ./instance_b/nginx-b.dev.conf:/etc/nginx/nginx.conf:ro
      - ./instance_b/userfiles:/var/www/userfiles:ro
    ports:
      - "127.0.0.2:8080:8080"

  dns:
    build:
      context: ./
      dockerfile: Dockerfile.dns
    volumes:
      - ./zone.json:/dns/zone.json
    expose:
      - 8053
    networks:
      default:
        aliases:
          - toolshed-dns
