services:
  nginx:
    image: nginx:1.27-alpine
    container_name: taskco-app-nginx
    restart: unless-stopped
    ports:
      - "8081:80"
    volumes:
      - ./.docker/nginx/app/dev.conf:/etc/nginx/conf.d/default.conf:ro
      - ./ssl:/etc/nginx/ssl:ro
      - ./app/public:/var/www/html/public:ro
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      - app
    networks:
      - taskco_network
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost/health || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s

  app:
    build:
      context: .
      dockerfile: .docker/app/dev/Dockerfile
    image: taskco-app:latest
    container_name: taskco-app
    restart: unless-stopped
    env_file:
      - .env
    environment:
      AUTO_MIGRATE: "false"
      AUTO_FIX_PERMISSIONS: "false"
    ports:
      - "8000:8000"
    volumes:
      - ./app:/var/www/html
      - taskco-app-bootstrap-cache:/var/www/html/bootstrap/cache
      - taskco-app-storage:/var/www/html/storage
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - taskco_network
    healthcheck:
      test: [ "CMD-SHELL", "curl -f http://localhost:8000/health || exit 1" ]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s  # increase from 15s to 30s


  postgres:
    image: postgres:16-alpine
    container_name: taskco-app-postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${DB_DATABASE}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    env_file:
      - .env
    ports:
      - "5442:5432"
    volumes:
      - taskco-app-postgres-data:/var/lib/postgresql/data
    networks:
      - taskco_network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -h localhost -U ${DB_USERNAME} -d ${DB_DATABASE}"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s

  redis:
    image: redis:7-alpine
    container_name: taskco-app-redis
    restart: unless-stopped
    ports:
      - "6382:6379"
    volumes:
      - taskco-app-redis-data:/data
    networks:
      - taskco_network
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s

  worker:
    build:
      context: .
      dockerfile: .docker/worker/worker.Dockerfile
    image: taskco-app-worker:latest
    container_name: taskco-app-worker
    restart: unless-stopped
    env_file:
      - .env
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ./app:/var/www/html
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - taskco_network
    healthcheck:
      test: ["CMD-SHELL", "supervisorctl status || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  scheduler:
    image: taskco-app-worker:latest
    container_name: taskco-app-scheduler
    restart: unless-stopped
    command: php artisan schedule:work
    env_file:
      - .env
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ./app:/var/www/html
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - taskco_network
    healthcheck:
      test: ["CMD-SHELL", "php /var/www/html/artisan schedule:list || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  mailpit:
    image: axllent/mailpit:latest
    container_name: taskco_mailpit
    ports:
      - "1026:1025"
      - "8026:8025"
    restart: unless-stopped
    networks:
      - taskco_network

networks:
  taskco_network:
    driver: bridge

volumes:
  taskco-app-postgres-data:
  taskco-app-redis-data:
  taskco-app-storage:
  taskco-app-bootstrap-cache:
