# File: mariadb/docker-compose.yml
# DMS Container v0_8_0 แยก service/  /lcbp3-db
x-restart: &restart_policy
  restart: unless-stopped

x-logging: &default_logging
  logging:
    driver: "json-file"
    options:
      max-size: "10m"
      max-file: "5"
services:
  mariadb:
    <<: [*restart_policy, *default_logging]
    image: mariadb:10.11
    container_name: dms_mariadb
    stdin_open: true
    tty: true
    deploy:
      resources:
        limits:
          cpus: "2.0"
          memory: 4G
        reservations:
          cpus: "0.5"
          memory: 1G
    environment:
      MYSQL_ROOT_PASSWORD: "Center#2025"
      MYSQL_DATABASE: "dms"
      MYSQL_USER: "center"
      MYSQL_PASSWORD: "Center#2025"
      TZ: "Asia/Bangkok"
    expose:
      - "80"
    volumes:
      - "/share/Container/dms/mariadb/data:/var/lib/mysql"
      - "/share/Container/dms/mariadb/my.cnf:/etc/mysql/conf.d/my.cnf:ro"
      - "/share/Container/dms/mariadb/init:/docker-entrypoint-initdb.d:ro"
      - "/share/dms-data/mariadb/backup:/backup"
    healthcheck:
      test:
        ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -pCenter#2025 || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 15
    networks:
      lcbp3: {}

  phpmyadmin:
    <<: [*restart_policy, *default_logging]
    image: phpmyadmin:5-apache
    container_name: dms_phpmyadmin
    stdin_open: true
    tty: true
    deploy:
      resources:
        limits:
          cpus: "0.25"
          memory: 256M
    environment:
      TZ: "Asia/Bangkok"
      PMA_HOST: "mariadb"
      PMA_PORT: "3306"
      PMA_ABSOLUTE_URI: "https://pma.np-dms.work/"
      UPLOAD_LIMIT: "256M"
      MEMORY_LIMIT: "512M"
    expose:
      - "80"
    volumes:
      - "/share/Container/dms/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php:ro"
      - "/share/Container/dms/phpmyadmin/zzz-custom.ini:/usr/local/etc/php/conf.d/zzz-custom.ini:ro"
      - "/share/Container/dms/phpmyadmin/sessions:/sessions:rw"
      - "/share/Container/dms/phpmyadmin/tmp:/var/lib/phpmyadmin/tmp:rw"
      - "/share/Container/dms/logs/phpmyadmin:/var/log/apache2"
    depends_on:
      mariadb:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1/"]
      interval: 15s
      timeout: 5s
      retries: 20
    networks:
      lcbp3: {}
networks:
  lcbp3:
    external: true
