services:
  backend:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
      - "2222:2222"
    env_file: .env.example
    environment:
      DJANGO_DEBUG: "true"
      DJANGO_SECRET_KEY: "local-dev-only-not-for-production-use-change-in-prod"
      SECURE_SSL_REDIRECT: "false"
      SESSION_COOKIE_SECURE: "false"
      CSRF_COOKIE_SECURE: "false"
      POSTGRES_HOST: postgres
      REDIS_URL: redis://redis:6379/1
      CELERY_BROKER: redis://redis:6379/0
      EMAIL_HOST: mailpit
    volumes:
      - .:/app
      - ./repos:/data/repos
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy

  celery-worker:
    build: .
    command: celery -A config.celery worker -l info -Q celery
    env_file: .env.example
    environment:
      POSTGRES_HOST: postgres
      REDIS_URL: redis://redis:6379/1
      CELERY_BROKER: redis://redis:6379/0
    volumes:
      - .:/app
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy

  celery-beat:
    build: .
    command: celery -A config.celery beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
    env_file: .env.example
    environment:
      POSTGRES_HOST: postgres
      REDIS_URL: redis://redis:6379/1
      CELERY_BROKER: redis://redis:6379/0
    volumes:
      - .:/app
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy

  postgres:
    image: postgres:16-alpine
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: fossilrepo
      POSTGRES_USER: dbadmin
      # Dev-only credentials. Override via .env in production.
      POSTGRES_PASSWORD: Password123
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U dbadmin -d fossilrepo"]
      interval: 5s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 5

  mailpit:
    image: axllent/mailpit
    ports:
      - "8025:8025"
      - "1025:1025"

  minio:
    image: minio/minio
    command: server /data --console-address ":9001"
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin
    profiles:
      - storage

volumes:
  pgdata:
