services:

  openlitespeed:
    image: litespeedtech/openlitespeed:${OPENLITESPEED_VERSION:-latest}
    container_name: openlitespeed
    restart: unless-stopped
    ports:
      - "${PROXY_HTTP_PORT:-${HTTP_PORT}}"
      - "${HTTPS_PORT}"
    working_dir: /var/www/html
    volumes:
      - ./openlitespeed.conf:/usr/local/lsws/conf/httpd_config.conf
      - /etc/hitechcloud/openlitespeed/start.sh:/entrypoint.sh:ro
      - ./sockets/mysqld:/var/run/mysqld
      - webserver_data:/usr/local/lsws/conf/vhosts/
      - html_data:/var/www/html/
      - /etc/hitechcloud/nginx/certs/:/etc/nginx/ssl/
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - ./php.ini/7.4.ini:/usr/local/lsws/lsphp74/etc/php/7.4/litespeed/php.ini
      - ./php.ini/8.0.ini:/usr/local/lsws/lsphp80/etc/php/8.0/litespeed/php.ini
      - ./php.ini/8.1.ini:/usr/local/lsws/lsphp81/etc/php/8.1/litespeed/php.ini
      - ./php.ini/8.2.ini:/usr/local/lsws/lsphp82/etc/php/8.2/litespeed/php.ini
      - ./php.ini/8.3.ini:/usr/local/lsws/lsphp83/etc/php/8.3/litespeed/php.ini
      - ./php.ini/8.4.ini:/usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini
      - ./php.ini/8.5.ini:/usr/local/lsws/lsphp85/etc/php/8.5/litespeed/php.ini
    deploy:
      resources:
        limits:
          cpus: "${OPENLITESPEED_CPU:-0.5}"
          memory: "${OPENLITESPEED_RAM:-0.5G}"   
          pids: "${OPENLITESPEED_PIDS:-100}"  
    networks:
      - www
      - db
      
  openresty:
    image: openresty/openresty:${OPENRESTY_VERSION:-alpine}
    container_name: openresty
    restart: unless-stopped
    ports:
      - "${PROXY_HTTP_PORT:-${HTTP_PORT}}"
      - "${HTTPS_PORT}"
    working_dir: /var/www/html
    volumes:
      - ./openresty.conf:/etc/openresty/nginx.conf:ro
      - webserver_data:/etc/nginx/conf.d
      - html_data:/var/www/html/   
      - /etc/hitechcloud/nginx/certs/:/etc/nginx/ssl/
      - /etc/hitechcloud/nginx/default_page.html:/etc/nginx/default_page.html:ro
    deploy:
      resources:
        limits:
          cpus: "${OPENRESTY_CPU:-0.5}"
          memory: "${OPENRESTY_RAM:-0.5G}"   
          pids: "${OPENRESTY_PIDS:-100}"  
    depends_on:
      - "php-fpm-${DEFAULT_PHP_VERSION:-8.2}"
    networks:
      - www

  nginx:
    image: nginx:${NGINX_VERSION:-latest}
    container_name: nginx
    restart: unless-stopped
    ports:
      - "${PROXY_HTTP_PORT:-${HTTP_PORT}}"
      - "${HTTPS_PORT}"
    working_dir: /var/www/html
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - webserver_data:/etc/nginx/conf.d
      - html_data:/var/www/html/   
      - /etc/hitechcloud/nginx/certs/:/etc/nginx/ssl/   
      - /etc/hitechcloud/nginx/default_page.html:/etc/nginx/default_page.html:ro
    deploy:
      resources:
        limits:
          cpus: "${NGINX_CPU:-0.5}"
          memory: "${NGINX_RAM:-0.5G}"   
          pids: "${NGINX_PIDS:-100}"  
    depends_on:
      - "php-fpm-${DEFAULT_PHP_VERSION:-8.2}"
    networks:
      - www


  apache:
    image: httpd:${APACHE_VERSION:-latest}
    container_name: apache
    restart: unless-stopped
    ports:
      - "${PROXY_HTTP_PORT:-${HTTP_PORT}}"
      - "${HTTPS_PORT}"
    working_dir: /var/www/html
    volumes:
      - ./httpd.conf:/usr/local/apache2/conf/httpd.conf:ro
      - webserver_data:/etc/httpd/conf.d/
      - html_data:/var/www/html/
      - /etc/hitechcloud/nginx/certs/:/etc/apache2/ssl/
      - /etc/hitechcloud/nginx/default_page.html:/etc/apache2/default_page.html:ro
    deploy:
      resources:
        limits:
          cpus: "${APACHE_CPU:-0.5}"
          memory: "${APACHE_RAM:-0.5G}"
          pids: "${APACHE_PIDS:-100}"  
    depends_on:
      - "php-fpm-${DEFAULT_PHP_VERSION:-8.2}"
    networks:
      - www

  varnish:
    image: varnish:${VARNISH_VERSION:-stable}
    container_name: varnish
    restart: unless-stopped
    environment:
      WEB_SERVER: "${WEB_SERVER:-nginx}"
      VARNISH_SIZE: "${VARNISH_SIZE:-1G}"
    entrypoint: /bin/sh -c "cp /etc/varnish/default.vcl.template /etc/varnish/default.vcl && sed -i 's|VARNISH_BACKEND_HOST|'"$WEB_SERVER"'|g' /etc/varnish/default.vcl && /usr/local/bin/docker-varnish-entrypoint"
    command: [ "-n", "/var/lib/varnish" ]
    volumes:
      - ./default.vcl:/etc/varnish/default.vcl.template
    ports:
      - "${HTTP_PORT}"
    tmpfs:
      - /var/lib/varnish:exec
    deploy:
      resources:
        limits:
          cpus: "${VARNISH_CPU:-0.5}"
          memory: "${VARNISH_RAM:-0.5G}"
          pids: "${VARNISH_PIDS:-100}"  
    depends_on:
      - "${WEB_SERVER:-nginx}"
    networks:
      - www

  tor:
    image: hitechcloud/torwebsite:${TOR_VERSION:-latest}
    container_name: tor
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html
      - ./tor/hidden_service:/var/lib/tor/hidden_service
      - ./tor/torrc:/etc/tor/torrc
    deploy:
      resources:
        limits:
          cpus: "${TOR_CPU:-0.35}"
          memory: "${TOR_RAM:-0.35G}"
          pids: "${TOR_PIDS:-100}"
    networks:
      - www
      - db

  docker-proxy:
    image: tecnativa/docker-socket-proxy
    container_name: docker-proxy
    environment:
      CONTAINERS: 1
      POST: 1
      EXEC: 1
      INFO: 1
      VERSION: 1
    volumes:
      - /run/user/${USER_ID}/podman/podman.sock:/var/run/docker.sock:ro
    deploy:
      resources:
        limits:
          cpus: "0.1"
          memory: "64M"
          pids: 50
    networks:
      - socket-proxy

  cron:
    image: mcuadros/ofelia:latest
    container_name: cron
    restart: unless-stopped
    environment:
      DOCKER_HOST: tcp://docker-proxy:2375
    command: daemon --config=/crons.ini
    depends_on:
      docker-proxy:
        condition: service_started
    volumes:
      - /home/${CONTEXT}/crons.ini:/crons.ini:ro
    deploy:
      resources:
        limits:
          cpus: "${CRON_CPU:-0.5}"
          memory: "${CRON_RAM:-0.5G}"
          pids: "${CRON_PIDS:-100}"  
    networks:
      - socket-proxy
          
  mysql:
    image: mysql:${MYSQL_VERSION:-latest}
    container_name: mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
    ports:
      - "${MYSQL_PORT}"     
    volumes:
      - mysql_data:/var/lib/mysql
      - mysql_dumps:/tmp/dumps/  
      - /etc/hitechcloud/mysql/scripts/dump.sh:/dump.sh:ro
      - ./sockets/mysqld:/var/run/mysqld
      - ./my.cnf:/root/.my.cnf:ro
      - ./custom.cnf:/etc/mysql/conf.d/custom.cnf
    labels:
      - docker-volume-backup.archive-pre=/bin/sh -c '/dump.sh'
      - docker-volume-backup.archive-post=/bin/sh -c 'rm -rf /tmp/dumps/*'
    deploy:
      resources:
        limits:
          cpus: "${MYSQL_CPU:-0.5}"
          memory: "${MYSQL_RAM:-0.5G}"
          pids: "${MYSQL_PIDS:-100}"  
    networks:
      - db
    healthcheck:
      test: ['CMD-SHELL', 'mysqladmin ping -h 127.0.0.1 --silent']
      interval: 10s
      timeout: 3s
      retries: 5
      start_period: 10s

  mariadb:
    image: mariadb:${MYSQL_VERSION:-latest}
    container_name: mariadb
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
    ports:
      - "${MYSQL_PORT}"
    volumes:
      - mysql_data:/var/lib/mysql
      - mysql_dumps:/tmp/dumps/
      - /etc/hitechcloud/mysql/scripts/dump.sh:/dump.sh:ro
      - ./sockets/mysqld:/var/run/mysqld
      - ./my.cnf:/root/.my.cnf:ro
      - ./custom.cnf:/etc/mysql/conf.d/custom.cnf
    labels:
      - docker-volume-backup.archive-pre=/bin/sh -c '/dump.sh'
      - docker-volume-backup.archive-post=/bin/sh -c 'rm -rf /tmp/dumps/*'
    deploy:
      resources:
        limits:
          cpus: "${MARIADB_CPU:-0.5}"
          memory: "${MARIADB_RAM:-0.5G}"
          pids: "${MARIADB_PIDS:-100}"  
    networks:
      - db
    healthcheck:
      test: ['CMD-SHELL', 'mariadb-admin ping -h 127.0.0.1 --silent']
      interval: 10s
      timeout: 3s
      retries: 5
      start_period: 10s

  postgres:
    image: postgres:${POSTGRES_VERSION:-latest}
    container_name: postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgrespassword}
    ports:
      - "${POSTGRES_PORT}"
    volumes:
      - pg_data:/var/lib/postgresql/data
      - ./sockets/postgres:/var/run/postgresql
      #- ./postgre_custom.conf:/var/lib/postgresql/data/postgresql.conf
    deploy:
      resources:
        limits:
          cpus: "${POSTGRES_CPU:-0.3}"
          memory: "${POSTGRES_RAM:-0.3G}"
          pids: "${POSTGRES_PIDS:-100}"
    networks:
      - db
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER:-postgres}']
      interval: 1s
      timeout: 5s
      retries: 10
       
  redis:
    image: redis:${REDIS_VERSION:-8.6.2-alpine}
    container_name: redis
    restart: unless-stopped
    user: "${USER_ID:-0}"
    command: ["redis-server", "--bind", "0.0.0.0", "--port", "6379", "--save", ""]
    volumes:
      - ./sockets/redis:/var/run/redis
    deploy:
      resources:
        limits:
          cpus: "${REDIS_CPU:-0.1}"
          memory: "${REDIS_RAM:-0.1G}" 
          pids: "${REDIS_PIDS:-100}"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      retries: 3
      start_period: 5s
      timeout: 5s
    networks:
      - www
  
  valkey:
    image: valkey/valkey:${VALKEY_VERSION:-8.0-alpine}
    container_name: valkey
    restart: unless-stopped
    user: "${USER_ID:-0}"
    command: ["valkey-server", "--bind", "0.0.0.0", "--port", "6379"]
    volumes:
      - ./sockets/valkey:/var/run/valkey
    deploy:
      resources:
        limits:
          cpus: "${VALKEY_CPU:-0.1}"
          memory: "${VALKEY_RAM:-0.1G}"
          pids: "${VALKEY_PIDS:-100}"
    healthcheck:
      test: ["CMD", "valkey-cli", "ping"]
      interval: 30s
      retries: 3
      start_period: 5s
      timeout: 5s
    networks:
      - www

  elasticsearch:
    image: elasticsearch:${ELASTICSEARCH_VERSION:-9.3.2}
    container_name: elasticsearch
    restart: unless-stopped
    environment:
      discovery.type: single-node
      xpack.security.enabled: "false"
      ES_JAVA_OPTS: "-Xms512m -Xmx512m"
    volumes:
      - es_data:/usr/share/elasticsearch/data
      - es_config:/usr/share/elasticsearch/config
      - es_logs:/usr/share/elasticsearch/logs
    ulimits:
      nproc:
        soft: 4096
        hard: 4096
      nofile:
        soft: 65535
        hard: 65535
    deploy:
      resources:
        limits:
          cpus: "${ELASTICSEARCH_CPU:-0.5}"
          memory: "${ELASTICSEARCH_RAM:-1G}" 
          pids: "${ELASTICSEARCH_PIDS:-100}"
    healthcheck:
      test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
      interval: 10s
      timeout: 10s
      start_period: 5s
      retries: 3
    networks:
      - www


  opensearch:
    image: opensearchproject/opensearch:${OPENSEARCH_VERSION:-2.11.0}
    container_name: opensearch
    restart: unless-stopped
    environment:
      discovery.type: single-node
      OPENSEARCH_JAVA_OPTS: "-Xms512m -Xmx512m"
      DISABLE_SECURITY_PLUGIN: "true"
      OPENSEARCH_INITIAL_ADMIN_PASSWORD: "${OPENSEARCH_INITIAL_ADMIN_PASSWORD:-iIybFJOgznCYmpOO}"
      DISABLE_INSTALL_DEMO_CONFIG: "true"
    volumes:
      - opensearch_data:/usr/share/opensearch/data
      - opensearch_config:/usr/share/opensearch/config
      - opensearch_logs:/usr/share/opensearch/logs
    deploy:
      resources:
        limits:
          cpus: "${OPENSEARCH_CPU:-0.5}"
          memory: "${OPENSEARCH_RAM:-1G}" 
          pids: "${OPENSEARCH_PIDS:-100}"
    healthcheck:
      test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
      interval: 10s
      timeout: 10s
      start_period: 5s
      retries: 3
    networks:
      - www
  
  memcached:
    image: memcached:${MEMCACHED_VERSION:-1.6.41-alpine}
    container_name: memcached
    restart: unless-stopped
    user: "${USER_ID:-0}"
    command: ["memcached", "-u", "root", "-l", "0.0.0.0", "-p", "11211"]
    volumes:
      - ./sockets/memcached:/var/run/
    deploy:
      resources:
        limits:
          cpus: "${MEMCACHED_CPU:-0.1}"
          memory: "${MEMCACHED_RAM:-0.1G}" 
          pids: "${MEMCACHED_PIDS:-100}"
    healthcheck:
      test: ["CMD-SHELL", "echo stats | nc -w1 127.0.0.1 11211 | grep -q STAT"]
      interval: 30s
      retries: 3
      start_period: 5s
      timeout: 5s
    networks:
      - www


  php-fpm-5.6:
    image: shinsenter/php:5.6-fpm
    container_name: php-fpm-5.6
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/5.6.ini:/usr/local/etc/php/php.ini
      - ./php.ini/5.6.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - /etc/hitechcloud/php/ioncube/ioncube_loader_lin_5.6.so:/usr/local/lib/php/extensions/ioncube_loader.so:ro
      - /etc/hitechcloud/php/ioncube_extension.ini:/usr/local/etc/php/conf.d/docker-php-ext-ioncube.ini:ro
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_5_6_CPU:-0.25}"
          memory: "${PHP_FPM_5_6_RAM:-0.5G}"
          pids: "${PHP_FPM_5_6_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root  

  php-fpm-7.0:
    image: shinsenter/php:7.0-fpm
    container_name: php-fpm-7.0
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/7.0.ini:/usr/local/etc/php/php.ini
      - ./php.ini/7.0.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - /etc/hitechcloud/php/ioncube/ioncube_loader_lin_7.0.so:/usr/local/lib/php/extensions/ioncube_loader.so:ro
      - /etc/hitechcloud/php/ioncube_extension.ini:/usr/local/etc/php/conf.d/docker-php-ext-ioncube.ini:ro
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_7_0_CPU:-0.25}"
          memory: "${PHP_FPM_7_0_RAM:-0.5G}"
          pids: "${PHP_FPM_7_0_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root 
      
  php-fpm-7.1:
    image: shinsenter/php:7.1-fpm
    container_name: php-fpm-7.1
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/7.1.ini:/usr/local/etc/php/php.ini
      - ./php.ini/7.1.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - /etc/hitechcloud/php/ioncube/ioncube_loader_lin_7.1.so:/usr/local/lib/php/extensions/ioncube_loader.so:ro
      - /etc/hitechcloud/php/ioncube_extension.ini:/usr/local/etc/php/conf.d/docker-php-ext-ioncube.ini:ro      
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_7_1_CPU:-0.25}"
          memory: "${PHP_FPM_7_1_RAM:-0.5G}"
          pids: "${PHP_FPM_7_1_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root 
      

  php-fpm-7.2:
    image: shinsenter/php:7.2-fpm
    container_name: php-fpm-7.2
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/7.2.ini:/usr/local/etc/php/php.ini
      - ./php.ini/7.2.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - /etc/hitechcloud/php/ioncube/ioncube_loader_lin_7.2.so:/usr/local/lib/php/extensions/ioncube_loader.so:ro
      - /etc/hitechcloud/php/ioncube_extension.ini:/usr/local/etc/php/conf.d/docker-php-ext-ioncube.ini:ro
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_7_2_CPU:-0.25}"
          memory: "${PHP_FPM_7_2_RAM:-0.5G}"
          pids: "${PHP_FPM_7_2_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root
      


  php-fpm-7.3:
    image: shinsenter/php:7.3-fpm
    container_name: php-fpm-7.3
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/7.3.ini:/usr/local/etc/php/php.ini
      - ./php.ini/7.3.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - /etc/hitechcloud/php/ioncube/ioncube_loader_lin_7.3.so:/usr/local/lib/php/extensions/ioncube_loader.so:ro
      - /etc/hitechcloud/php/ioncube_extension.ini:/usr/local/etc/php/conf.d/docker-php-ext-ioncube.ini:ro
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_7_3_CPU:-0.25}"
          memory: "${PHP_FPM_7_3_RAM:-0.5G}"
          pids: "${PHP_FPM_7_3_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root
      

  php-fpm-7.4:
    image: shinsenter/php:7.4-fpm
    container_name: php-fpm-7.4
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/7.4.ini:/usr/local/etc/php/php.ini
      - ./php.ini/7.4.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - /etc/hitechcloud/php/ioncube/ioncube_loader_lin_7.4.so:/usr/local/lib/php/extensions/ioncube_loader.so:ro
      - /etc/hitechcloud/php/ioncube_extension.ini:/usr/local/etc/php/conf.d/docker-php-ext-ioncube.ini:ro
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_7_4_CPU:-0.25}"
          memory: "${PHP_FPM_7_4_RAM:-0.5G}"
          pids: "${PHP_FPM_7_4_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root
      
  php-fpm-8.0:
    image: shinsenter/php:8.0-fpm
    container_name: php-fpm-8.0
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/8.0.ini:/usr/local/etc/php/php.ini
      - ./php.ini/8.0.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro   
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_8_0_CPU:-0.25}"
          memory: "${PHP_FPM_8_0_RAM:-0.5G}"
          pids: "${PHP_FPM_8_0_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root
   
      

  php-fpm-8.1:
    image: shinsenter/php:8.1-fpm
    container_name: php-fpm-8.1
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/8.1.ini:/usr/local/etc/php/php.ini
      - ./php.ini/8.1.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - /etc/hitechcloud/php/ioncube/ioncube_loader_lin_8.1.so:/usr/local/lib/php/extensions/ioncube_loader.so:ro
      - /etc/hitechcloud/php/ioncube_extension.ini:/usr/local/etc/php/conf.d/docker-php-ext-ioncube.ini:ro
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_8_1_CPU:-0.25}"
          memory: "${PHP_FPM_8_1_RAM:-0.5G}"
          pids: "${PHP_FPM_8_1_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root
  

      
  php-fpm-8.2:
    image: shinsenter/php:8.2-fpm
    container_name: php-fpm-8.2
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/8.2.ini:/usr/local/etc/php/php.ini
      - ./php.ini/8.2.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - /etc/hitechcloud/php/ioncube/ioncube_loader_lin_8.2.so:/usr/local/lib/php/extensions/ioncube_loader.so:ro
      - /etc/hitechcloud/php/ioncube_extension.ini:/usr/local/etc/php/conf.d/docker-php-ext-ioncube.ini:ro
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_8_2_CPU:-0.25}"
          memory: "${PHP_FPM_8_2_RAM:-0.5G}"
          pids: "${PHP_FPM_8_2_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root
      

  php-fpm-8.3:
    image: shinsenter/php:8.3-fpm
    container_name: php-fpm-8.3
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/8.3.ini:/usr/local/etc/php/php.ini
      - ./php.ini/8.3.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - /etc/hitechcloud/php/ioncube/ioncube_loader_lin_8.3.so:/usr/local/lib/php/extensions/ioncube_loader.so:ro
      - /etc/hitechcloud/php/ioncube_extension.ini:/usr/local/etc/php/conf.d/docker-php-ext-ioncube.ini:ro      
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_8_3_CPU:-0.25}"
          memory: "${PHP_FPM_8_3_RAM:-0.5G}"
          pids: "${PHP_FPM_8_3_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root
      
  php-fpm-8.4:
    image: shinsenter/php:8.4-fpm
    container_name: php-fpm-8.4
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/8.4.ini:/usr/local/etc/php/php.ini
      - ./php.ini/8.4.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
      - /etc/hitechcloud/php/ioncube/ioncube_loader_lin_8.4.so:/usr/local/lib/php/extensions/ioncube_loader.so:ro
      - /etc/hitechcloud/php/ioncube_extension.ini:/usr/local/etc/php/conf.d/docker-php-ext-ioncube.ini:ro
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_8_4_CPU:-0.25}"
          memory: "${PHP_FPM_8_4_RAM:-0.5G}"
          pids: "${PHP_FPM_8_4_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root


     
  php-fpm-8.5:
    image: shinsenter/php:8.5-fpm
    container_name: php-fpm-8.5
    restart: unless-stopped
    volumes:
      - html_data:/var/www/html/
      - ./php.ini/8.5.ini:/usr/local/etc/php/php.ini
      - ./php.ini/8.5.ini:/usr/local/etc/php/conf.d/zz-docker-shinsenter-php.ini:ro
      - /etc/hitechcloud/wordpress/wp-cli.phar:/usr/local/bin/wp:ro
    environment:
      - APP_USER=root
      - APP_GROUP=root
      - APP_UID=${USER_ID:-0}
      - APP_GID=${USER_ID:-0}
      - ENABLE_TUNING_FPM=1
    deploy:
      resources:
        limits:
          cpus: "${PHP_FPM_8_5_CPU:-0.25}"
          memory: "${PHP_FPM_8_5_RAM:-0.5G}"
          pids: "${PHP_FPM_8_5_PIDS:-100}"
    networks:
      - www
      - db
    command: php-fpm --allow-to-run-as-root

  mongodb:
    image: mongo:${MONGODB_VERSION:-latest}
    container_name: mongodb
    restart: unless-stopped
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGODB_ROOT_USER:-admin}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_ROOT_PASSWORD:-rootpassword}
      MONGO_INITDB_DATABASE: ${MONGODB_DATABASE:-app}
    volumes:
      - mongodb_data:/data/db
      - mongodb_config:/data/configdb
    deploy:
      resources:
        limits:
          cpus: "${MONGODB_CPU:-0.5}"
          memory: "${MONGODB_RAM:-0.5G}"
          pids: "${MONGODB_PIDS:-100}"
    networks:
      - db

  backup:
    image: offen/docker-volume-backup:v2
    container_name: backup
    environment:
      USERNAME: ${CONTEXT}
      DOCKER_HOST: tcp://docker-proxy:2375
    depends_on:
      docker-proxy:
        condition: service_started
    env_file:
      - ./backup.env
    volumes:
      - html_data:/var/www/html/:ro
      - html_data:/backup/html:ro
      - mysql_dumps:/backup/mysql:ro
      - mail_data:/backup/mail:ro
      - webserver_data:/backup/vhosts:ro
      - pg_data:/backup/postgres:ro
      - ./crons.ini:/backup/crons.ini:ro
      - /etc/hitechcloud/backups/customized.template:/etc/dockervolumebackup/notifications.d/01.template:ro
    deploy:
      resources:
        limits:
          cpus: "${BACKUP_CPU:-1.0}"
          memory: "${BACKUP_RAM:-1.0g}"
          pids: "${BACKUP_PIDS:-100}"
    restart: unless-stopped
    networks:
      - socket-proxy
      - www

networks:
  default:
    driver: bridge
    labels:
      description: "Not used, serves as a fallback if no network is defined."
      purpose: "internal"
  www:
    driver: bridge
    labels:
      description: "This network is used for communication between website services (webserver to apps)."
      purpose: "internal"
  db:
    driver: bridge
    labels:
      description: "This network is used for communication between websites and database services (apps to database)."
      purpose: "internal"
  socket-proxy:
    driver: bridge
    internal: true   # no internet access
    labels:
      description: "Used by cron and backup containers to access docker socket securely."
      purpose: "internal"

volumes:
  mysql_data:
    driver: local
    labels:
      description: "This volume holds the mysql/mariadb databases."
      purpose: "database"
  mysql_dumps:
    driver: local
    labels:
      description: "This volume holds the .sql dumps of databases during backup."
      purpose: "storage"
  html_data:
    driver: local
    labels:
      description: "This volume holds the /var/www/html/ directory."
      purpose: "storage"
  mail_data:
    driver: local
    labels:
      description: "This volume holds the /var/mail/ directory."
      purpose: "storage"
  webserver_data:
    driver: local
    labels:
      description: "This volume holds the Nginx/Apache vhost files."
      purpose: "configuration"
  mongodb_data:
    driver: local
    labels:
      description: "This volume holds the mongodb databases."
      purpose: "database"
  mongodb_config:
    driver: local
    labels:
      description: "This volume holds the mongodb configuration files."
      purpose: "configuration"
  es_data:
    driver: local
    labels:
      description: "This volume holds the ElasticSearch data."
      purpose: "storage"
  es_config:
    driver: local
    labels:
      description: "This volume holds the ElasticSearch configuration."
      purpose: "configuration"
  es_logs:
    driver: local
    labels:
      description: "This volume holds the ElasticSearch logs."
      purpose: "logs"
  opensearch_data:
    driver: local
    labels:
      description: "This volume holds the OpenSearch data."
      purpose: "storage"
  opensearch_config:
    driver: local
    labels:
      description: "This volume holds the OpenSearch configuration."
      purpose: "configuration"
  opensearch_logs:
    driver: local
    labels:
      description: "This volume holds the OpenSearch logs."
      purpose: "logs"
  pg_data:
    driver: local
    labels:
      description: "This volume holds the postgresql databases."
      purpose: "database"
