# CVE-2026-71362 — Magento / Adobe Commerce customer-session identity-switch lab.
# One command:  docker compose up -d   (first boot installs Magento; ~15-40 min)
#
# Only the storefront (nginx) is published to the host. DB / OpenSearch / Redis
# stay on the internal network so this never collides with other local services.

services:
  db:
    image: mariadb:11.4
    command: >
      --max_allowed_packet=64M
      --optimizer_use_condition_selectivity=1
      --optimizer_switch=rowid_filter=off
    environment:
      MARIADB_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpw}
      MARIADB_DATABASE: ${MYSQL_DATABASE:-magento}
      MARIADB_USER: ${MYSQL_USER:-magento}
      MARIADB_PASSWORD: ${MYSQL_PASSWORD:-magento}
    volumes:
      - dbdata:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 30
    restart: unless-stopped

  opensearch:
    image: opensearchproject/opensearch:2.19.0
    environment:
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g"
      - DISABLE_SECURITY_PLUGIN=true
      - DISABLE_INSTALL_DEMO_CONFIG=true
    ulimits:
      memlock: {soft: -1, hard: -1}
      nofile: {soft: 65536, hard: 65536}
    volumes:
      - osdata:/usr/share/opensearch/data
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    restart: unless-stopped

  php:
    build: ./php
    working_dir: /var/www/html
    environment:
      MAGENTO_VERSION: ${MAGENTO_VERSION:-2.4.9}
      MAGENTO_HOST: ${MAGENTO_HOST:-127.0.0.1}
      HOST_PORT: ${HOST_PORT:-8080}
      MAGENTO_ADMIN_USER: ${MAGENTO_ADMIN_USER:-admin}
      MAGENTO_ADMIN_PASSWORD: ${MAGENTO_ADMIN_PASSWORD:-Admin123!}
      MAGENTO_ADMIN_EMAIL: ${MAGENTO_ADMIN_EMAIL:-admin@example.com}
      BACKEND_FRONTNAME: ${BACKEND_FRONTNAME:-admin}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-magento}
      MYSQL_USER: ${MYSQL_USER:-magento}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-magento}
      PHP_MEMORY_LIMIT: 4G
      COMPOSER_MEMORY_LIMIT: -1
    volumes:
      - magesrc:/var/www/html
      - ./scripts:/lab-scripts:ro
      - ./patch:/lab-patch:ro
    depends_on:
      db:
        condition: service_healthy
      opensearch:
        condition: service_started
      redis:
        condition: service_started
    restart: unless-stopped

  nginx:
    image: nginx:1.27-alpine
    ports:
      - "${HOST_PORT:-8080}:80"
    volumes:
      - magesrc:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - php
    restart: unless-stopped

volumes:
  dbdata:
  osdata:
  magesrc:
