# Dockerfile
FROM alpine:3.20

LABEL maintainer="will"
LABEL version="1.0"

# ffmpeg + bash + coreutils
RUN apk add --no-cache ffmpeg bash coreutils procps

WORKDIR /app

# Where optional URL files can be mounted
VOLUME ["/app"]

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Defaults (override at runtime)
ENV URLS="" \ 
    URLS_FILE="/app/urls.txt" \
    LOOP="1" \
    PROTOCOL="udp" \
    TARGET="udp://239.0.0.1:1234?ttl=16" \
    # m4a is typically AAC-in-MP4; copy when target supports AAC:
    CODEC="aac" \
    COPY_CODEC_WHEN_POSSIBLE="1" \
    BITRATE="160k" \
    SAMPLE_RATE="48000" \
    FFMPEG_EXTRA_ARGS=""

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
    CMD test -f /tmp/ffmpeg.pid && ps -p "$(cat /tmp/ffmpeg.pid)" > /dev/null
