x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  apache:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}httpd:${APACHE_VERSION:-2.4.62-alpine3.20}
    ports:
      - '${APACHE_HTTP_PORT_OVERRIDE:-80}:80'
      - '${APACHE_HTTPS_PORT_OVERRIDE:-443}:443'
    volumes:
      - apache_logs:/usr/local/apache2/logs
      - ./htdocs:/usr/local/apache2/htdocs:ro

      # Custom configuration
      # - ./httpd.conf:/usr/local/apache2/conf/httpd.conf:ro
      # - ./ssl:/usr/local/apache2/conf/ssl:ro
    environment:
      - TZ=${TZ:-UTC}
      - APACHE_RUN_USER=${APACHE_RUN_USER:-www-data}
      - APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-www-data}
    deploy:
      resources:
        limits:
          cpus: ${APACHE_CPU_LIMIT:-1.0}
          memory: ${APACHE_MEMORY_LIMIT:-512M}
        reservations:
          cpus: ${APACHE_CPU_RESERVATION:-0.1}
          memory: ${APACHE_MEMORY_RESERVATION:-128M}
    healthcheck:
      test: [CMD, httpd, -t]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

volumes:
  apache_logs:
