# Use this file for development only

services:

  mariadb:
    image: mariadb:latest
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=iop
      - MYSQL_DATABASE=phpmyfaq
      - MYSQL_USER=phpmyfaq
      - MYSQL_PASSWORD=phpmyfaq
      - MYSQL_ROOT_HOST=%
    ports:
      - '3306:3306'
    volumes:
      - ./volumes/mariadb:/var/lib/mysql

  postgres:
    image: postgres:latest
    restart: always
    environment:
      - POSTGRES_DB=phpmyfaq
      - POSTGRES_USER=phpmyfaq
      - POSTGRES_PASSWORD=phpmyfaq
    ports:
      - '5432:5432'
    volumes:
      - ./volumes/postgres:/var/lib/postgresql/data

  #sqlserver:
  #  image: mcr.microsoft.com/mssql/server:2022-latest
  #  ports:
  #    - 1433:1433
  #  environment:
  #    SA_PASSWORD: 'phpMyFAQ-4.0'
  #    ACCEPT_EULA: 'Y'

  apache:
    build:
      context: .
      dockerfile: .docker/apache/Dockerfile
    restart: always
    stdin_open: true
    environment:
      - PMF_DB_HOST=db
      - PMF_DB_NAME=phpmyfaq
      - PMF_DB_USER=phpmyfaq
      - PMF_DB_PASS=phpmyfaq
      - PMF_DISABLE_HTACCESS=""
      - PMF_TIMEZONE="Europe/Berlin"
      - PMF_ENABLE_UPLOADS="On"
      - PMF_MEMORY_LIMIT="2048M" # only for development
      - PHP_LOG_ERRORS="On"
      - PHP_ERROR_REPORTING="E_ALL & E_DEPRECATED" # Production Value: E_ALL & ~E_DEPRECATED
    links:
      - mariadb:db
      - postgres
      - elasticsearch
    ports:
      - '8080:80'
      - '443:443'
    volumes:
      - ./phpmyfaq:/var/www/html
    depends_on:
      - pnpm

  nginx:
    image: nginx:latest
    restart: always
    links:
      - php-fpm
    volumes:
      - ./phpmyfaq:/var/www/html
      - ./.docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
      - ./.docker/cert.pem:/etc/ssl/cert.pem
      - ./.docker/cert-key.pem:/etc/ssl/cert-key.pem
    ports:
      - '80:80'
      - '443:443'

  php-fpm:
    build: .docker/php-fpm
    restart: always
    stdin_open: true
    environment:
      - PMF_DB_HOST=db
      - PMF_DB_NAME=phpmyfaq
      - PMF_DB_USER=phpmyfaq
      - PMF_DB_PASS=phpmyfaq
      - PMF_DISABLE_HTACCESS=""
      - PMF_TIMEZONE="Europe/Berlin"
      - PMF_ENABLE_UPLOADS="On"
      - PMF_MEMORY_LIMIT="2048M" # only for development
      - PHP_LOG_ERRORS="On"
      - PHP_ERROR_REPORTING="E_ALL & E_DEPRECATED" # Production Value: E_ALL & ~E_DEPRECATED
    links:
      - mariadb:db
      - postgres
      - elasticsearch
    volumes:
      - ./phpmyfaq:/var/www/html
    depends_on:
      - pnpm

  frankenphp:
    build: .docker/frankenphp
    restart: always
    stdin_open: true
    environment:
      - PMF_DB_HOST=db
      - PMF_DB_NAME=phpmyfaq
      - PMF_DB_USER=phpmyfaq
      - PMF_DB_PASS=phpmyfaq
      - PMF_DISABLE_HTACCESS=""
      - PMF_TIMEZONE="Europe/Berlin"
      - PMF_ENABLE_UPLOADS="On"
      - PMF_MEMORY_LIMIT="2048M" # only for development
      - PHP_LOG_ERRORS="On"
      - PHP_ERROR_REPORTING="E_ALL & E_DEPRECATED" # Production Value: E_ALL & ~E_DEPRECATED
    links:
      - mariadb:db
      - postgres
      - elasticsearch
    ports:
      - '80:80'
      - '443:443'
      - '443:443/udp' # HTTP/3
    volumes:
      - ./phpmyfaq:/var/www/html
      - ./.docker/cert.pem:/etc/ssl/cert.pem
      - ./.docker/cert-key.pem:/etc/ssl/cert-key.pem
      - ./volumes/caddy_data:/data
      - ./volumes/caddy_config:/config
    depends_on:
      - pnpm

  pnpm:
    image: node:22-alpine
    restart: 'no'
    command: sh -c "corepack enable && corepack prepare pnpm@latest --activate && pnpm install && pnpm build"
    working_dir: /app
    stdin_open: true
    tty: true
    volumes:
      - .:/app
    depends_on:
      - composer

  composer:
    image: composer:latest
    restart: 'no'
    command: composer install --verbose --ignore-platform-reqs
    stdin_open: true
    tty: true
    volumes:
      - .:/app

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    stdin_open: true
    environment:
      UPLOAD_LIMIT: 100M
    links:
      - mariadb:db
    ports:
      - '8000:80'
    volumes:
      - ./volumes/sessions:/sessions

  pgadmin:
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: postgres@phpmyfaq.de
      PGADMIN_DEFAULT_PASSWORD: postgres
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    volumes:
      - ./volumes/pgadmin:/root/.pgadmin
    ports:
      - '8008:80'

  elasticsearch:
    image: elasticsearch:8.16.5
    container_name: phpmyfaq-41_elasticsearch-v8
    restart: always
    environment:
      - cluster.name=phpmyfaq-cluster
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
      - "_JAVA_OPTIONS=-XX:UseSVE=0"
      - "ES_JAVA_OPTS=-Xint"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    user: elasticsearch
    command:
      [
        'sh',
        '-c',
        './bin/elasticsearch-plugin list | grep -q analysis-icu || ./bin/elasticsearch-plugin install analysis-icu && ./bin/elasticsearch',
      ]
    volumes:
      - ./volumes/esdata:/usr/share/elasticsearch/data
    ports:
      - '9200:9200'
      - '9300:9300'

  opensearch:
    image: opensearchproject/opensearch:2.19.2
    container_name: opensearch
    environment:
      - cluster.name=phpmyfaq-cluster
      - node.name=phpmyfaq
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - http.port=9201
      - "_JAVA_OPTIONS=-XX:UseSVE=0"
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
      - "DISABLE_INSTALL_DEMO_CONFIG=true"
      - "DISABLE_SECURITY_PLUGIN=true"
      - "DISABLE_PERFORMANCE_ANALYZER_AGENT=true"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - ./volumes/opensearchdata:/usr/share/opensearch/data
    ports:
      - '9201:9201'
      - '9600:9600'
