services:
  nginx:
    image: drupal-nginx
    build:
      context: ./nginx
      dockerfile: Dockerfile
      args:
        DOMAIN: ${DOMAIN}
    container_name: drupal-reverse-proxy
    labels:
      - traefik.enable=true
      - traefik.docker.network=traefik
      - traefik.http.routers.drupal-reverse-proxy.rule=Host(`${DOMAIN}`)
      - traefik.http.routers.drupal-reverse-proxy.entrypoints=web,websecure
      - traefik.http.routers.drupal-reverse-proxy.middlewares=https-redirect
      - traefik.http.routers.drupal-reverse-proxy.tls=true
      - traefik.http.routers.drupal-reverse-proxy.tls.certresolver=le
      - traefik.http.services.drupal-reverse-proxy.loadbalancer.server.port=80
    volumes:
      - ./drupal/root/web:/var/www/html
    networks:
      - traefik
      - drupal

  drupal-fpm:
    image: drupal-php8-4-fpm-bookworm
    build:
      context: ./drupal
      dockerfile: Dockerfile
      args:
        DRUPAL_VERSION: ${DRUPAL_VERSION:-11.1.6}
    labels:
      - traefik.enable=false
    container_name: drupal-fpm
    expose:
      - "9000"
    volumes:
      - ./drupal/root:/opt/drupal
    networks:
      - database
      - drupal

  redis:
    image: redis:7-alpine
    container_name: drupal-redis
    command: redis-server --loglevel warning
    environment:
      - OVERC
    volumes:
      - redis-data:/data
    networks:
      - drupal
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s

volumes:
  redis-data:
    name: drupal-redis-data

networks:
  traefik:
    external: true
  database:
    external: true
  drupal:
    name: drupal
