version: '3.8'

services:
  redis:
    image: redis:7-alpine
    command: redis-server --appendonly yes
    volumes:
      - redis_data:/data
    ports:
      - "6379:6379"
    restart: unless-stopped

  web:
    build: .
    ports:
      - "8000:8000" 
    environment:
      - DATABASE_HOST=192.168.10.209
      - DATABASE_PORT=3306
      - DATABASE_NAME=dbstmmobile
      - DATABASE_USER=root
      - DATABASE_PASSWORD=Messis#01
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
      - DJANGO_SETTINGS_MODULE=stmunicipal.settings
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      - redis
    restart: unless-stopped
    volumes:
      - static_volume:/app/staticfiles
      - media_volume:/app/media
      # Caminho absoluto - funcionará no Ubuntu
      - /home/estm/filemaneger/apk:/app/apk_files:ro
    command: >
      sh -c "python manage.py migrate &&
             python manage.py collectstatic --noinput &&
             gunicorn stmunicipal.wsgi:application --bind 0.0.0.0:8000 --workers 3"

  celery-worker:
    build: .
    environment:
      - DATABASE_HOST=192.168.10.209
      - DATABASE_PORT=3306
      - DATABASE_NAME=dbstmmobile
      - DATABASE_USER=root
      - DATABASE_PASSWORD=Messis#01
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
      - DJANGO_SETTINGS_MODULE=stmunicipal.settings
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      - redis
    restart: unless-stopped
    volumes:
      - static_volume:/app/staticfiles
      - media_volume:/app/media
      - /home/estm/filemaneger/apk:/app/apk_files:ro
    command: python -m celery -A stmunicipal worker --loglevel=info --concurrency=2

  celery-beat:
    build: .
    environment:
      - DATABASE_HOST=192.168.10.209
      - DATABASE_PORT=3306
      - DATABASE_NAME=dbstmmobile
      - DATABASE_USER=root
      - DATABASE_PASSWORD=Messis#01
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
      - DJANGO_SETTINGS_MODULE=stmunicipal.settings
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      - redis
    restart: unless-stopped
    volumes:
      - static_volume:/app/staticfiles
      - media_volume:/app/media
      - /home/estm/filemaneger/apk:/app/apk_files:ro
    command: python -m celery -A stmunicipal beat --loglevel=info

volumes:
  redis_data:
  static_volume:
  media_volume: