services:
  php:
    image: ${IMAGES_PREFIX:-}app-php
    depends_on:
      database:
        condition: service_healthy
    restart: unless-stopped
    environment:
      PWA_UPSTREAM: pwa:3000
      SERVER_NAME: ${SERVER_NAME:-localhost}, php:80
      DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-16}&charset=utf8
      TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
      TRUSTED_HOSTS: ^${SERVER_NAME:-localhost|php}$$
    ports:
      - target: 80
        published: ${HTTP_PORT:-80}
      - target: 443
        published: ${HTTPS_PORT:-443}
      - target: 443
        published: ${HTTP3_PORT:-443}
        protocol: udp
    volumes:
      - caddy_data:/data
      - caddy_config:/config

  pwa:
    image: ${IMAGES_PREFIX:-}app-pwa
    environment:
      NEXT_PUBLIC_ENTRYPOINT: http://php

  database:
    image: postgres:${POSTGRES_VERSION:-16}-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-app}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
      POSTGRES_USER: ${POSTGRES_USER:-app}
    healthcheck:
      test: ["CMD", "pg_isready", "-d", "${POSTGRES_DB:-app}", "-U", "${POSTGRES_USER:-app}"]
      timeout: 5s
      retries: 5
      start_period: 60s
    volumes:
      - database_data:/var/lib/postgresql/data:rw

volumes:
  caddy_data:
  caddy_config:
  database_data:
  pgadmin_data:
