services:
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    container_name: chronis-app
    working_dir: /var/www
    volumes:
      - ./:/var/www
    depends_on:
      - postgres
      - redis
    networks:
      - chronis
    env_file:
      - .env

  nginx:
    image: nginx:1.27-alpine
    container_name: chronis-nginx
    ports:
      - "8080:80"
    volumes:
      - ./:/var/www
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - app
    networks:
      - chronis

  postgres:
    image: postgres:16-alpine
    container_name: chronis-postgres
    environment:
      POSTGRES_DB: ${DB_DATABASE:-chronis}
      POSTGRES_USER: ${DB_USERNAME:-chronis}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-secret}
    volumes:
      - chronis-pgdata:/var/lib/postgresql/data
    networks:
      - chronis

  redis:
    image: redis:7-alpine
    container_name: chronis-redis
    networks:
      - chronis

  horizon:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    container_name: chronis-horizon
    working_dir: /var/www
    command: php artisan horizon
    volumes:
      - ./:/var/www
    depends_on:
      - app
      - redis
      - postgres
    networks:
      - chronis
    env_file:
      - .env

  scheduler:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    container_name: chronis-scheduler
    working_dir: /var/www
    command: sh -c "while true; do php artisan schedule:run --verbose --no-interaction; sleep 60; done"
    volumes:
      - ./:/var/www
    depends_on:
      - app
      - postgres
      - redis
    networks:
      - chronis
    env_file:
      - .env

networks:
  chronis:
    driver: bridge

volumes:
  chronis-pgdata:
