services:

  wordpress:
    image: wordpress:6.7-php8.1
    restart: always
    ports:
      - 8081:80
    env_file:
      - .wp-env
    links:
      - db
      - clickhouse
      - tracker
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DEBUG: 1
      WP_ENVIRONMENT_TYPE: ${WP_ENVIRONMENT_TYPE:-local}
      WP_PHPUNIT__TESTS_CONFIG: /var/www/html/wp-content/plugins/altis-accelerate/tests/phpunit/wp-tests-config.php
      WORDPRESS_CONFIG_EXTRA: |
        define( 'WORDPRESS_DEBUG', true );
        define( 'WP_DEBUG_LOG', true );
        define( 'WP_DEBUG_DISPLAY', true );
        define( 'ALTIS_ACCELERATE_LOG_ENDPOINT', 'http://localhost:3399' );
    volumes:
      - ./:/var/www/html/wp-content/plugins/altis-accelerate
      - ./.wordpress:/var/www/html
    depends_on:
      db:
        condition: service_healthy

  db:
    image: mariadb:11.7
    restart: always
    ports:
      - 3306
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mariadb-admin", "ping", "-h", "localhost", "-u", "wordpress", "-pwordpress"]
      interval: 5s
      timeout: 2s
      retries: 10

  tracker:
    image: humanmade/accelerate-tracker:latest
    ports:
      - 3399:3000
    environment:
      ACCESS_KEY: admin
      SECRET_KEY: password
      CLICKHOUSE_HOST: clickhouse
      DO_CLICKHOUSE: true
      DO_PINPOINT: ''

  clickhouse:
    image: clickhouse/clickhouse-server:25.2
    ulimits:
      nofile:
        soft: 262144
        hard: 262144
    ports:
      - '9020:9000'
      - '8123:8123'
    volumes:
      - ch:/var/lib/clickhouse
      - ./.setup:/.setup
    environment:
      CLICKHOUSE_SKIP_USER_SETUP: 1

  grafana:
    image: grafana/grafana-enterprise
    ports:
      - '3600:3000'
    volumes:
      - grafana:/var/lib/grafana
    environment:
      - GF_INSTALL_PLUGINS=grafana-clickhouse-datasource

volumes:
  db:
  ch:
  grafana:
