version: "3.9"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: laravel-app:latest
    container_name: laravel_app
    restart: unless-stopped

    ports:
      - "8080:80"                    # Angepasst für Synology (Port 81 oft belegt)

    environment:
      # Laravel Environment
      - APP_NAME=${APP_NAME:-Laravel}
      - APP_ENV=${APP_ENV:-production}
      - APP_KEY=${APP_KEY}
      - APP_DEBUG=${APP_DEBUG:-false}
      - APP_URL=${APP_URL:-http://localhost:8080}

      # Database - PostgreSQL
      - DB_CONNECTION2=${DB_CONNECTION2:-pgsql}
      - DB_HOST2=${DB_HOST2:-postgres}
      - DB_PORT2=${DB_PORT2:-5432}
      - DB_DATABASE2=${DB_DATABASE2:-ingest_db}
      - DB_USERNAME2=${DB_USERNAME2:-ingest_user}
      - DB_PASSWORD2=${DB_PASSWORD2:-ingest_pwd}

      # Session & Cache
      - SESSION_DRIVER=${SESSION_DRIVER:-file}
      - CACHE_STORE=${CACHE_STORE:-file}
      - QUEUE_CONNECTION=${QUEUE_CONNECTION:-sync}

      # Logging
      - LOG_CHANNEL=${LOG_CHANNEL:-stack}
      - LOG_LEVEL=${LOG_LEVEL:-info}

      # Mail
      - MAIL_MAILER=${MAIL_MAILER:-log}

    volumes:
      - app-storage:/var/www/html/storage
      - app-bootstrap-cache:/var/www/html/bootstrap/cache
      - ./database:/var/www/html/database

    networks:
      - laravel-network

    depends_on:
      postgres:
        condition: service_healthy

  postgres:
    image: postgres:16-alpine
    container_name: laravel_postgres
    restart: unless-stopped

    environment:
      - POSTGRES_DB=${DB_DATABASE2:-ingest_db}
      - POSTGRES_USER=${DB_USERNAME2:-ingest_user}
      - POSTGRES_PASSWORD=${DB_PASSWORD2:-ingest_pwd}
      - PGDATA=/var/lib/postgresql/data/pgdata

    volumes:
      - postgres-data:/var/lib/postgresql/data

    ports:
      - "5432:5432"                 # Optional: Direktzugriff auf PostgreSQL

    networks:
      - laravel-network

    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME2:-ingest_user}"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  postgres-data:
    driver: local
  app-storage:
    driver: local
  app-bootstrap-cache:
    driver: local

networks:
  laravel-network:
    driver: bridge
