services:
  web:
    image: webdevops/php-apache-dev:7.4
    platform: linux/amd64
    volumes:
      - "./src:/web"
      - "./scripts:/scripts"
      - "./module:/module"
      - "./build:/build"
#      - "/Users/nikitakiselev/code/italy-moda/image/catalog:/web/upload/image/catalog"
    ports:
      - "8000:80"
    restart: always
    deploy:
      resources:
        limits:
          memory: 1G
    healthcheck:
      test: [ "CMD", "curl" ,"-f", "http://localhost/index.php?route=extension/tgshop/handle&api_action=health" ]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 5s
    environment:
      - WEB_DOCUMENT_ROOT=/web/upload
      - PHP_DISPLAY_ERRORS=1
      - XDEBUG_IDE_KEY=PHPSTORM
      - XDEBUG_START_WITH_REQUEST=trigger
      - XDEBUG_CLIENT_HOST=host.docker.internal
      - XDEBUG_CLIENT_PORT=9003
      - XDEBUG_DISCOVER_CLIENT_HOST=false
      - PHP_IDE_CONFIG=serverName=telecart
      - php.session.gc_maxlifetime=28800
      - php.session.cookie_lifetime=0
      - TELECART_REDIS_HOST=redis
      - TELECART_REDIS_PORT=6379
      - TELECART_REDIS_DATABASE=0
    depends_on:
      - mysql
      - redis

  redis:
    image: redis:latest
    restart: unless-stopped
    healthcheck:
      test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]

  mysql:
    image: mariadb:10.2.7
    platform: linux/amd64
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=secret
      - MYSQL_DATABASE=ocstore3
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost", "-u", "root", "-psecret" ]
      timeout: 20s
      retries: 10
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./sql_dumps:/sql_dumps
      - ./docker/mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d

  cron:
    image: ghcr.io/telecart-labs/scheduler:latest
    platform: linux/amd64
    restart: unless-stopped
    environment:
      CRONTAB: |
        */5 * * * * php /web/upload/cli.php schedule:run > /proc/1/fd/1
    volumes:
      - ./src:/web
      - ./scripts:/scripts
      - ./module:/module
      - ./build:/build
    depends_on:
      - mysql

volumes:
  mysql_data:
