apiVersion: v1
data:
  Dockerfile: |
    # Optimized MPD Docker Image with latest packages
    # Multi-architecture support: amd64, arm64, armv7
    FROM alpine:3.21

    # Install MPD and all audio codecs/plugins
    RUN apk add --no-cache \
        # Core MPD
        mpd \
        mpd-doc \
        # Audio encoders/decoders
        lame \
        lame-doc \
        opus \
        opus-tools \
        vorbis-tools \
        flac \
        wavpack \
        faad2 \
        # FFmpeg for broader codec support
        ffmpeg \
        ffmpeg-libs \
        # Network protocols
        libsmbclient \
        libnfs \
        curl \
        # Audio outputs
        alsa-lib \
        pulseaudio \
        pipewire \
        # Utilities
        bash \
        tini \
        # Development tools for debugging (optional, remove to reduce size)
        # ncmpcpp \
        # mpc \
        && rm -rf /var/cache/apk/*

    # Create MPD directories with proper permissions
    RUN mkdir -p \
        /var/lib/mpd \
        /var/lib/mpd/music \
        /var/lib/mpd/playlists \
        /var/lib/mpd/data \
        /var/log/mpd \
        /run/mpd \
        && chown -R mpd:audio /var/lib/mpd /var/log/mpd /run/mpd

    # Copy optimized default configuration
    COPY mpd.conf /etc/mpd.conf
    RUN chown mpd:audio /etc/mpd.conf

    # Expose MPD control port and HTTP streaming port
    EXPOSE 6600 8000

    # Use tini as init system for proper signal handling
    ENTRYPOINT ["/sbin/tini", "--"]

    # Run MPD in foreground as mpd user
    USER mpd
    CMD ["mpd", "--no-daemon", "--stderr", "/etc/mpd.conf"]
  mpd.conf: |
    # MPD Configuration - Optimized for Kubernetes/Network Streaming
    # This is a default config that can be overridden by ConfigMap

    music_directory "/var/lib/mpd/music"
    playlist_directory "/var/lib/mpd/playlists"
    db_file "/var/lib/mpd/data/database"
    log_file "/var/log/mpd/mpd.log"
    pid_file "/run/mpd/pid"
    state_file "/var/lib/mpd/data/state"
    sticker_file "/var/lib/mpd/data/sticker.sql"

    # Network settings
    bind_to_address "0.0.0.0"
    port "6600"
    zeroconf_enabled "no"

    # Performance tuning - Optimized for network streaming over NFS
    audio_buffer_size "32768"         # 32MB buffer for smooth playback
    max_output_buffer_size "131072"   # 128MB output buffer
    connection_timeout "60"           # 60 second timeout for slow networks
    max_connections "20"              # Support more concurrent clients
    max_playlist_length "32768"       # Large playlist support

    # Database settings
    auto_update "yes"
    auto_update_depth "4"
    filesystem_charset "UTF-8"

    # Logging
    log_level "default"
    #log_level "verbose"  # Uncomment for debugging

    # HTTP streaming output - High quality MP3 (320kbps)
    audio_output {
        type "httpd"
        name "HTTP Stream"
        encoder "lame"
        port "8000"
        bitrate "320"
        format "44100:16:2"
        max_clients "10"
        always_on "yes"
        tags "yes"
        mixer_type "software"
    }

    # FIFO output for visualizers (optional)
    audio_output {
        type "fifo"
        name "FIFO"
        path "/tmp/mpd.fifo"
        format "44100:16:2"
    }

    # Null output as fallback
    audio_output {
        type "null"
        name "Null Output"
    }
kind: ConfigMap
metadata:
  name: mpd-build-files
  namespace: media
