version: "3.8"
services:

  db:
    image: postgres
    restart: always
    environment:
      - POSTGRES_ROOT_PASSWORD=${POSTGRES_ROOT_PASSWORD}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
    volumes:
      - db:/var/lib/postgresql/data
    networks:
       - internal  
    deploy: 
       resources:
         limits:
           cpus: '1.0'
           memory: 512M         

  comfy:
    image: comfy
    user: "${UID}:${GID}"
    restart: always
    ports:
      - "8000"
    volumes:
      - media:/app/media
      - static:/app/static
    environment:
      - SECRET_KEY=${SECRET_KEY}
      - DATABASE_URL=${DATABASE_URL}
      - DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}
      - SENTRY_DSN=${SENTRY_DSN}
      - SENTRY_ENVIRONMENT=${SENTRY_ENVIRONMENT} 
      - EMAIL_HOST=${EMAIL_HOST}
      - EMAIL_HOST_USER=${EMAIL_HOST_USER}
      - EMAIL_HOST_PASSWORD=${EMAIL_HOST_PASSWORD}
      - EMAIL_PORT=${EMAIL_PORT}
      - EMAIL_USE_TLS=${EMAIL_USE_TLS}
      - DEFAULT_FROM_EMAIL=${DEFAULT_FROM_EMAIL}      
    depends_on:
      - db
    networks:
       - internal
    deploy: 
       resources:
         limits:
           cpus: '1.0'
           memory: 512M            

  web:
    image: nginx
    restart: always
    volumes:
      - nginx:/etc/nginx/conf.d
      - static:/opt/services/comfy/static
      - media:/opt/services/comfy/media 
    ports:
      - "80"
    environment:
      - NGINX_HOST=${NGINX_HOST}
      - NGINX_PORT=${NGINX_PORT}
    networks:
       - internal
       - web      
    deploy: 
       resources:
         limits:
           cpus: '1.0'
           memory: 256M       
       labels:
        - "traefik.enable=true"
        - "traefik.docker.network=web"          
        - "traefik.http.routers.artel.rule=Host(`${NGINX_HOST}`)"        
        - "traefik.http.routers.artel.entrypoints=websecure"    
        - "traefik.http.services.artel.loadbalancer.server.port=80"                 
        - "traefik.http.routers.artel.tls=true"    
        - "traefik.http.routers.artel.tls.certresolver=ovh"    

volumes:
  db:
  media:
  static:
  nginx:

networks:
  internal:
  web:
    external:
      name: web  

