version: '3'

services:
  web:
    image: devicewise/studio_vi:latest
    runtime: nvidia
    command: bash -c "python3 manage.py makemigrations VisualInspectionApp && python3 manage.py migrate VisualInspectionApp && python3 manage.py collectstatic --noinput && daphne VisualInspectionService.asgi:application --port 8000 --bind 0.0.0.0"
    volumes:
      - .:/app
      - ./database:/app/database
      - static_volume:/staticfiles
      - ./media:/app/media
      - ./logs:/app/logs
      - /opt/dw/staging:/opt/dw/staging
    environment:
      - DJANGO_SETTINGS_MODULE=VisualInspectionService.settings
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=all
      - OMP_NUM_THREADS=4
      - C_FORCE_ROOT=true
      - PIN_MEMORY=false
    shm_size: '32gb'
    ports:
      - "8000:8000"
    ipc: host
    deploy:
      resources:
        reservations:
          devices:
          - driver: nvidia
            count: all
            capabilities: [gpu]  
            
  nginx:
    image: devicewise/nginx_vi:latest
    volumes:
      - static_volume:/staticfiles
      - ./media:/app/media
    ports:
      - "80:80"
      - "3000:443"
  redis:
    image: "redis:alpine"
    ports:
      - "6379:6379"

  celery:
    image: devicewise/studio_vi:latest
    runtime: nvidia
    command: ["celery", "-A", "VisualInspectionService", "worker", "--loglevel=DEBUG", "--pool=solo"]
    volumes:
      - .:/app
      - ./database:/app/database
      - static_volume:/staticfiles
      - ./media:/app/media
      - ./logs:/app/logs
      - /opt/dw/staging:/opt/dw/staging
    depends_on:
      - web
      - redis
    environment:
      - DJANGO_SETTINGS_MODULE=VisualInspectionService.settings
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=all
      - C_FORCE_ROOT=true
      - PIN_MEMORY=false
    shm_size: '32gb'

  frontend:
    build: 
      context: ../visualinspectionweb
      dockerfile: Dockerfile.dev
    volumes:
      - ../visualinspectionweb:/app
      - /app/node_modules
      
volumes:
  static_volume: