services:
  wp:
    image: authldap_test:${WORDPRESS_VERSION:-6.7}-${PHP_VERSION:-8.4}
    build:
      context: dockersetup
      dockerfile: Dockerfile_wordpress
      args:
        PHP_VERSION: ${PHP_VERSION:-8.4}
        WORDPRESS_VERSION: ${WORDPRESS_VERSION:-6.7}
    volumes:
      - .:/var/www/html/wp-content/plugins/authldap
      - wordpress:/var/www/html
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: "wordpress"
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: "wppasswd"
      WORDPRESS_DEBUG: 1
      PHP_IDE_CONFIG: serverName=localhost
    depends_on:
      db:
        condition: service_healthy
      openldap:
        condition: service_healthy
    links:
      - db

  nginx:
    image: nginx
    volumes:
      - ./dockersetup/nginx/default.conf:/etc/nginx/conf.d/default.conf
      - .:/var/www/html/wp-content/plugins/authldap
      - wordpress:/var/www/html
    #ports:
    #  - 80:80
    links:
      - wp:wp
    depends_on:
      - wp

  wpcli:
    image: wordpress:cli
    volumes:
      - wordpress:/var/www/html
      - .:/var/www/html/wp-content/plugins/authldap
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: "wordpress"
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: "wppasswd"
    user: "33:33"
    depends_on:
      - db
      - wp

  db:
    image: mysql:latest # https://hub.docker.com/_/mysql/ - or mariadb https://hub.docker.com/_/mariadb
    #ports:
    #  - 3306:3306 # change ip if required
    command: [
      '--character-set-server=utf8mb4',
      '--collation-server=utf8mb4_unicode_ci'
    ]
    volumes:
      - ./wp-data:/docker-entrypoint-initdb.d
      - db_data:/var/lib/mysql
    environment:
      MYSQL_DATABASE: "wordpress"
      MYSQL_ROOT_PASSWORD: "wppasswd"
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      timeout: 1s
      retries: 10
      interval: 2s

  openldap:
    image: bitnami/openldap:latest
#    build:
#      context: dockersetup
#      dockerfile: Dockerfile_ldap
    ports:
      - "389:389"
    volumes:
      - ./.ci/50-init.ldif:/container/service/slapd/assets/config/bootstrap/ldif/custom/50-bootstrap.ldif
    #command: "--copy-service --loglevel debug"
    #restart: unless-stopped
    environment:
      LDAP_LOG_LEVEL: "0"
      LDAP_TLS: "false"
      LDAP_ADMIN_PASSWORD: "insecure"
      LDAP_URI: "ldap://localhost:389"
      LDAP_ADMIN_USERNAME: admin
      LDAP_PORT_NUMBER: 389

    healthcheck:
      test: ["CMD", "/opt/bitnami/openldap/bin/ldapsearch", "-H",  "ldap://localhost/", "-x", "-s", "base", "-LLL", "+"]
      timeout: 1s
      retries: 10
      interval: 2s

volumes:
  db_data:
  wordpress:
