name: i-drive-dc
volumes:
  backend-db:

services:

  ### redis
  ### todo force docker to delete cache on restart cuz yes
  redis:
    container_name: idrive-redis
    image: redis:latest
    restart: unless-stopped
    #healthcheck:
    #  test: [ "CMD-SHELL", "ls" ]
    #  interval: 10s
    #  retries: 10

    deploy:
      resources:
        limits:
          memory: 256M

  ### Main backend
  
  backend:
    container_name: idrive-backend
    image: ghcr.io/pam-param-pam/idrive-backend:${BACKENDTAG-latest}
#    platform: linux/arm64
    pull_policy: missing
    build:
      context: ./backend
    restart: unless-stopped
    ports:
      - 8001:8000
    healthcheck:  # DO POPRAWY
      test: [ "CMD-SHELL", "ls" ]
      interval: 10s
      retries: 10
    environment:
      # DJANGO SECRET KEYS
      - I_DRIVE_BACKEND_SECRET_KEY=${I_DRIVE_BACKEND_SECRET_KEY}

      # For later
      - PROTOCOL=${PROTOCOL:-https}

      # GENERAL
      - IS_DEV_ENV=${IS_DEV_ENV:-false}
      - DEPLOYMENT_HOST=${DEPLOYMENT_HOST:-localhost}
      - BACKEND_BASE_URL=${PROTOCOL:-https}://${DEPLOYMENT_HOST:-localhost}/api

      # Other that have to be set
      - I_DRIVE_REDIS_ADDRESS=redis
      - I_DRIVE_REDIS_PORT=6379
      - I_DRIVE_BACKEND_STORAGE_DIR=/app/data

    volumes:
      - backend-db:/app/data
    deploy:
      resources:
        limits:
          memory: 1G


 ### nginx

  nginx:
    image: ghcr.io/pam-param-pam/idrive-nginx:${NGINXTAG-latest}
    container_name: idrive-nginx
#    platforms:
#      -linux/arm64

    build:
      context: ./frontend
    restart: unless-stopped
    ports:
      - ${PORT:-80}:80
    depends_on:
      backend:
        condition: service_healthy
    healthcheck: ### KWESTIA PORTU DO SPRAWDZENIA
      test: [ "CMD-SHELL", "curl http://localhost:80/healthcheck || exit 1" ]
      interval: 10s
      retries: 10
    environment:
      - VITE_BACKEND_BASE_URL=${PROTOCOL:-https}://${DEPLOYMENT_HOST:-localhost}/api # PORTS may be diffrent
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf

    deploy:
      resources:
        limits:
          memory: 64M