# MySQL-Server und PHPmyAdmin
networks:
  nw-letto:
    external: true

volumes:
  lettomysql:
    name: lettomysql
    external: true

# Der Name bestimmt das Projekt und sollte bei jeder yml-Datei unterschiedlich sein - er kann mit -p bei docker-compose überschrieben werden
name: mysql

services:
  lettomysql:
    image: lettohub/letto-mysql:stable
    environment:
      - TZ=${TIMEZONE:-Europe/Berlin}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
    networks:
      - nw-letto
    ports:
      - "${MYSQL_PORT:-13306}:3306"
    deploy:
      resources:
        limits:
          memory: "${MYSQL_MEMORY_LIMIT:-${MEMORY_LIMIT:-1G}}"
    security_opt:
      - seccomp:unconfined
    logging:
      driver: "json-file"
      options:
        max-size: "2m"
        max-file: "3"
    volumes:
      # Speichere die Datenbank im Volume
      - ${MYSQL_VOLUME:-lettomysql}:/var/lib/mysql
      # Hier die Datenbank-Dumps
      - ${MYSQL_DUMP_PATH:-/opt/letto/docker/storage/database-dump}:/opt/dump
      # Und hier das Backup-Verzeichnis
      - ${MYSQL_BACKUP_PATH:-/opt/letto/docker/storage/database-backup}:/opt/backup
    hostname: ${MYSQL_HOST:-letto-mysql}
    container_name: ${MYSQL_HOST:-letto-mysql}
    restart: always

  lettophpmyadmin:
    image: phpmyadmin:latest
    networks:
      - nw-letto
    environment:
      - TZ=${TIMEZONE:-Europe/Berlin}
      - PMA_HOST=lettomysql
      - PMA_ABSOLUTE_URI=https://${SERVER_NAME:-localhost}/phpmyadmin/
    depends_on:
      - lettomysql
    deploy:
      resources:
        limits:
          memory: "${MYADMIN_MEMORY_LIMIT:-100M}"
    logging:
      driver: "json-file"
      options:
        max-size: "2m"
        max-file: "3"
    hostname: ${PHP_MYADMIN_HOST:-phpmyadmin}
    container_name: ${PHP_MYADMIN_HOST:-phpmyadmin}
    restart: always
