x-php: &php
  build:
    context: docker/php
    args:
      PHP_VERSION: 8.4
      COMPOSER_VERSION: 2.8
      HOST_UID: ${HOST_UID:-1001}
      HOST_GID: ${HOST_GID:-1001}
  image: php:8.4-ieducar
  working_dir: /var/www/ieducar
  volumes:
    - ./:/var/www/ieducar
  links:
    - postgres
    - redis
  depends_on:
    postgres:
      condition: service_started
    redis:
      condition: service_started
  environment:
    CACHE_DRIVER: redis
    REDIS_HOST: redis
    DB_HOST: postgres
    PGPASSWORD: ${DB_PASSWORD}
  extra_hosts:
    - host.docker.internal:host-gateway

services:

  php:
    <<: *php
    container_name: ieducar-php
    command: tail -f /dev/null
    depends_on: []

  fpm:
    <<: *php
    container_name: ieducar-fpm

  horizon:
    <<: *php
    container_name: ieducar-horizon
    command: /var/www/ieducar/artisan horizon
    restart: always

  nginx:
    container_name: ieducar-nginx
    image: nginx:1.28-alpine
    links:
      - fpm
    working_dir: /var/www/ieducar
    volumes:
      - ./:/var/www/ieducar
      - ./docker/nginx/conf.d/:/etc/nginx/conf.d/
      - ./docker/nginx/snippets:/etc/nginx/snippets/
    ports:
      - ${DOCKER_NGINX_PORT:-80}:80
      - ${DOCKER_NGINX_SSL_PORT:-443}:443

  postgres:
    container_name: ieducar-postgres
    image: postgres:17-alpine
    environment:
      POSTGRES_DB: ${DB_DATABASE}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      PGUSER: ${DB_USERNAME}
    volumes:
      - postgres:/var/lib/postgresql/data
    ports:
      - ${DOCKER_POSTGRES_PORT:-5432}:5432

  redis:
    container_name: ieducar-redis
    image: redis:8-alpine
    restart: always
    ports:
      - ${DOCKER_REDIS_PORT:-6379}:6379

volumes:
    postgres:
