# 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"]
