services:
  mariadb:
    image: docker.io/supernote/mariadb:10.6.19
    container_name: supernote-mariadb
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-mB8mP6kB7qA1}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-supernotedb}
      MYSQL_USER: ${MYSQL_USER:-enote}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-rH4bL9oI3kS0}
      TZ: ${TZ:-UTC}
    command: --skip-name-resolve --bind-address=0.0.0.0
    volumes:
      - ./sndata/db_data:/var/lib/mysql
      - ./sndata/config/mysql/conf.d:/etc/mysql/conf.d:ro
      - /etc/localtime:/etc/localtime:ro
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h localhost -u root -p$$MYSQL_ROOT_PASSWORD || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 30s
    restart: unless-stopped

  redis:
    image: docker.io/supernote/redis:7.0.12
    container_name: supernote-redis
    environment:
      TZ: ${TZ:-UTC}
      REDIS_PASSWORD: ${REDIS_PASSWORD:-ratta@2024..}
    env_file:
      - .dbenv
    command: ["redis-server", "--requirepass", "${REDIS_PASSWORD:-ratta@2024..}"]
    volumes:
      - ./sndata/redis_data:/data
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 3

  notelib:
    image: docker.io/supernote/notelib:6.9.3
    container_name: supernote-notelib
    environment:
      TZ: ${TZ:-UTC}
    volumes:
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped

  supernote-service:
    image: docker.io/supernote/supernote-service:25.12.17
    depends_on:
      mariadb:
        condition: service_healthy
      redis:
        condition: service_healthy
    container_name: supernote-service
    ports:
      - "19071:19071"
      - "18072:18072"
      - "${FRONTEND_PORT:-19072}:8080"
      - "${DOMAIN_PORT:-8199}:8080"
    environment:
      EXTERNAL_PORT_BACKEND: "19071"
      EXTERNAL_PORT_FRONTEND: ${FRONTEND_PORT:-19072}
      EXTERNAL_PORT_DOMAIN: ${DOMAIN_PORT:-8199}
      TZ: ${TZ:-UTC}
    env_file:
      - .dbenv
    volumes:
      - ./sndata/recycle:/home/supernote/recycle
      - ./supernote_data:/home/supernote/data
      - ./sndata/logs/cloud:/home/supernote/cloud/logs
      - ./sndata/logs/app:/home/supernote/logs
      - ./sndata/logs/web:/var/log/nginx
      - ./sndata/convert:/home/supernote/convert
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

volumes:
  db_data:
  redis_data:
