Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfile #261

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add Dockerfile #261

wants to merge 2 commits into from

Conversation

jtabet
Copy link

@jtabet jtabet commented Mar 11, 2023

This pull requests adds a way to easily integrate gmrender-resurrect in a docker environment.
The "FRIENDLY_NAME" environment variable must be provided, and additional volume mounts for pulseaudio.

Here is what's needed to use pulseaudio in docker-compose:

    volumes:
      - /etc/localtime:/etc/localtime:ro
      - $HOME/.config/pulse/cookie:/root/.config/pulse/cookie
      - ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native
    environment:
      - PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native
    devices:
      - "/dev/snd:/dev/snd"
    group_add:
      - audio

@mill1000
Copy link
Contributor

Cool. Just a few thoughts from me.

  • What about using Alpine as the base image? It's generally smaller than Debian images.
  • FRIENDLY_NAME shouldn't be required. I would either update the command to conditionally use the variable, or have a default value.
  • UUID should also be a runtime option to enable the same image to be deployed multiple times.
  • An environment variable should be added to allow specifying arbitrary command line arguments. (e.g. output options, MIME filters)
  • Environment variables are not declared with an ENV instruction.
  • What about ALSA instead of PulseAudio? Even better if its a build option
  • In my experience it's better to use a valid init for the entrypoint and run the service as a command. I like to use tini.

Here's an untested Dockerfile that I whipped up. It builds both backends but I haven't confirmed if I can render anything.

ARG AUDIO_BACKEND="alsa"

# Build image
FROM alpine:latest AS build
ARG UUID
RUN apk add --update build-base autoconf automake libtool pkgconfig gstreamer-dev libupnp-dev uuidgen
WORKDIR /opt/gmrender-resurrect
COPY . .
RUN ./autogen.sh && ./configure CPPFLAGS="-DGMRENDER_UUID='\"${UUID:-`uuidgen`}\"'"
RUN make && make install DESTDIR=/gmrender-install

# ALSA image
FROM alpine:latest AS alpine-alsa
RUN apk add --update alsa-lib alsa-utils

# PulsaAudio image
FROM alpine:latest AS alpine-pulse
RUN apk add --update pulseaudio

# Run image
FROM alpine-${AUDIO_BACKEND}
COPY --from=build /gmrender-install /
RUN apk add --update tini libupnp gstreamer gstreamer-tools gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly
ENV FRIENDLY_NAME=
ENV UUID=
ENV OPTIONS=
EXPOSE 49494
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/bin/sh", "-c", "/usr/local/bin/gmediarender --logfile=stdout ${FRIENDLY_NAME:+-f \"$FRIENDLY_NAME\"} ${UUID:+--uuid \"$UUID\"} $OPTIONS"]

It defaults to an ALSA backend but PulseAudio can be build with:

docker build -t gmrender_pulse:latest . --build-arg AUDIO_BACKEND=pulse

Here's a comparison of image size

gmrender_debian         latest    7dc5e33f3a94   19 seconds ago      791MB
gmrender-alsa           latest    27c29f38b254   3 minutes ago       160MB
gmrender-pulse          latest    2d4c4b6b8525   4 minutes ago       161MB

@jtabet
Copy link
Author

jtabet commented Mar 26, 2023

I confirm it builds and runs with your changes. However, I cannot provide in depth tests, since I stopped using gmrender-resurrect because I can't use UPnP in my project.

@mill1000
Copy link
Contributor

I've confirmed the ALSA backend works on a Raspberry Pi 3 with the following Docker Compose.

services:
  gmrender:
    image: gmrender:latest
    container_name: gmrender-resurrect
    restart: unless-stopped
    network_mode: host
    environment:
      OPTIONS: "--mime-filter audio"
    devices:
      - "/dev/snd:/dev/snd"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants