mopidy-generate-docker.sh
· 3.5 KiB · Bash
Raw
#!/bin/bash
# This script generates a Dockerfile and a docker-compose.yml file for running
# Mopidy with various extensions.
#
# This is customized for my setup, so you may need to adjust it to fit the
# extensions that you actually need.
#
# You may also want to use a Pulse sink for audio output if you already have
# PulseAudio running on the host system, otherwise ALSA won't to
# control the audio output.
#
# Also note that the docker-compose.yml will mount the configuration and work
# directories from the host system ($HOME/.config/mopidy and
# $HOME/.local/share/mopidy).
# Content of the companion start.sh script:
#!/usr/bin/dumb-init /bin/sh
# set -x
# mopidy --config /mopidy/mopidy.conf
cat <<EOF > Dockerfile
FROM debian:12-slim
LABEL Author="Fabio Manganiello"
# Change the architecture if needed, e.g. arm64, armhf, etc.
ARG ARCH=amd64
ENV DEBIAN_FRONTEND=noninteractive
ENV PIP_NO_CACHE_DIR=1
RUN apt update && apt upgrade -y \\
&& apt install -y \\
alsa-utils \\
cmake \\
curl \\
dumb-init \\
gstreamer1.0-alsa \\
gstreamer1.0-pulseaudio \\
libcairo2-dev \\
mopidy \\
pkg-config \\
pulseaudio-utils \\
python3-pip \\
sudo \\
&& mkdir -p ~/.config/pip && printf "[global]\nbreak-system-packages = true\n" | tee ~/.config/pip/pip.conf \\
&& pip install --no-cache-dir \\
tidalapi==0.8.3 \\
mopidy-bandcamp \\
mopidy-funkwhale \\
mopidy-iris \\
mopidy-jellyfin \\
mopidy-local \\
mopidy-mobile \\
mopidy-mpd \\
mopidy-podcast \\
mopidy-scrobbler \\
mopidy-soundcloud \\
mopidy-tidal \\
mopidy-tunein \\
mopidy-youtube \\
yt-dlp \\
&& apt purge --auto-remove -y \\
cmake \\
gcc \\
libcairo2-dev \\
pkg-config \\
&& apt clean \\
&& apt autoremove -y \\
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.cache /root/.cache
# Needed to map the audio group to the host audio group,
# and the mopidy user to the current user, so we won't get permission issues
# while trying to access externally mounted sound devices
RUN usermod -u $(id -u) mopidy
RUN groupmod -g $(grep audio /etc/group | sed -r -e 's/^([^:]+:){2}([0-9]+):.*/\2/') audio
RUN usermod -aG audio mopidy
RUN sh -c 'echo "mopidy ALL=NOPASSWD: /usr/local/lib/python3.11/dist-packages/mopidy_iris/system.sh" >> /etc/sudoers'
USER mopidy
EXPOSE 6600
EXPOSE 6680
EXPOSE 5555/udp
ADD ./start.sh /start.sh
ENTRYPOINT ["dumb-init", "--"]
CMD ["/start.sh"]
HEALTHCHECK --interval=60s --timeout=5s --retries=3 \\
CMD curl --connect-timeout 5 --silent --show-error --fail http://localhost:6680/ || exit 1
EOF
cat <<EOF > docker-compose.yml
services:
mopidy:
build:
context: .
dockerfile: Dockerfile
container_name: mopidy
ports:
- "6600:6600" # MPD port
- "6680:6680" # HTTP port
- "5555:5555" # Streaming UDP port
devices:
- /dev/snd:/dev/snd # Audio device
hostname: mopidy
environment:
PULSE_SERVER: unix:/run/user/$(id -u)/pulse/native # Adjust user ID as needed
volumes:
- /run/user/$(id -u)/pulse:/run/user/$(id -u)/pulse # Adjust user ID as needed
- /run/user/$(id -u)/pulse/native:/run/user/$(id -u)/pulse/native # Adjust user ID as needed
# - /mnt/hd/media/music:/mnt/hd/media/music # Music library path
- $HOME/.config/mopidy/mopidy.conf:/mopidy/mopidy.conf # Configuration file
- $HOME/.local/share/mopidy:/var/lib/mopidy/.local/share/mopidy # Local data storage
- ./cache:/var/lib/mopidy/.cache/mopidy
restart: unless-stopped
EOF
1 | #!/bin/bash |
2 | |
3 | # This script generates a Dockerfile and a docker-compose.yml file for running |
4 | # Mopidy with various extensions. |
5 | # |
6 | # This is customized for my setup, so you may need to adjust it to fit the |
7 | # extensions that you actually need. |
8 | # |
9 | # You may also want to use a Pulse sink for audio output if you already have |
10 | # PulseAudio running on the host system, otherwise ALSA won't to |
11 | # control the audio output. |
12 | # |
13 | # Also note that the docker-compose.yml will mount the configuration and work |
14 | # directories from the host system ($HOME/.config/mopidy and |
15 | # $HOME/.local/share/mopidy). |
16 | |
17 | # Content of the companion start.sh script: |
18 | #!/usr/bin/dumb-init /bin/sh |
19 | # set -x |
20 | # mopidy --config /mopidy/mopidy.conf |
21 | |
22 | cat <<EOF > Dockerfile |
23 | FROM debian:12-slim |
24 | LABEL Author="Fabio Manganiello" |
25 | |
26 | # Change the architecture if needed, e.g. arm64, armhf, etc. |
27 | ARG ARCH=amd64 |
28 | |
29 | ENV DEBIAN_FRONTEND=noninteractive |
30 | ENV PIP_NO_CACHE_DIR=1 |
31 | |
32 | RUN apt update && apt upgrade -y \\ |
33 | && apt install -y \\ |
34 | alsa-utils \\ |
35 | cmake \\ |
36 | curl \\ |
37 | dumb-init \\ |
38 | gstreamer1.0-alsa \\ |
39 | gstreamer1.0-pulseaudio \\ |
40 | libcairo2-dev \\ |
41 | mopidy \\ |
42 | pkg-config \\ |
43 | pulseaudio-utils \\ |
44 | python3-pip \\ |
45 | sudo \\ |
46 | && mkdir -p ~/.config/pip && printf "[global]\nbreak-system-packages = true\n" | tee ~/.config/pip/pip.conf \\ |
47 | && pip install --no-cache-dir \\ |
48 | tidalapi==0.8.3 \\ |
49 | mopidy-bandcamp \\ |
50 | mopidy-funkwhale \\ |
51 | mopidy-iris \\ |
52 | mopidy-jellyfin \\ |
53 | mopidy-local \\ |
54 | mopidy-mobile \\ |
55 | mopidy-mpd \\ |
56 | mopidy-podcast \\ |
57 | mopidy-scrobbler \\ |
58 | mopidy-soundcloud \\ |
59 | mopidy-tidal \\ |
60 | mopidy-tunein \\ |
61 | mopidy-youtube \\ |
62 | yt-dlp \\ |
63 | && apt purge --auto-remove -y \\ |
64 | cmake \\ |
65 | gcc \\ |
66 | libcairo2-dev \\ |
67 | pkg-config \\ |
68 | && apt clean \\ |
69 | && apt autoremove -y \\ |
70 | && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.cache /root/.cache |
71 | |
72 | # Needed to map the audio group to the host audio group, |
73 | # and the mopidy user to the current user, so we won't get permission issues |
74 | # while trying to access externally mounted sound devices |
75 | RUN usermod -u $(id -u) mopidy |
76 | RUN groupmod -g $(grep audio /etc/group | sed -r -e 's/^([^:]+:){2}([0-9]+):.*/\2/') audio |
77 | RUN usermod -aG audio mopidy |
78 | |
79 | RUN sh -c 'echo "mopidy ALL=NOPASSWD: /usr/local/lib/python3.11/dist-packages/mopidy_iris/system.sh" >> /etc/sudoers' |
80 | |
81 | USER mopidy |
82 | |
83 | EXPOSE 6600 |
84 | EXPOSE 6680 |
85 | EXPOSE 5555/udp |
86 | |
87 | ADD ./start.sh /start.sh |
88 | |
89 | ENTRYPOINT ["dumb-init", "--"] |
90 | CMD ["/start.sh"] |
91 | |
92 | HEALTHCHECK --interval=60s --timeout=5s --retries=3 \\ |
93 | CMD curl --connect-timeout 5 --silent --show-error --fail http://localhost:6680/ || exit 1 |
94 | EOF |
95 | |
96 | cat <<EOF > docker-compose.yml |
97 | services: |
98 | mopidy: |
99 | build: |
100 | context: . |
101 | dockerfile: Dockerfile |
102 | container_name: mopidy |
103 | ports: |
104 | - "6600:6600" # MPD port |
105 | - "6680:6680" # HTTP port |
106 | - "5555:5555" # Streaming UDP port |
107 | devices: |
108 | - /dev/snd:/dev/snd # Audio device |
109 | hostname: mopidy |
110 | environment: |
111 | PULSE_SERVER: unix:/run/user/$(id -u)/pulse/native # Adjust user ID as needed |
112 | volumes: |
113 | - /run/user/$(id -u)/pulse:/run/user/$(id -u)/pulse # Adjust user ID as needed |
114 | - /run/user/$(id -u)/pulse/native:/run/user/$(id -u)/pulse/native # Adjust user ID as needed |
115 | # - /mnt/hd/media/music:/mnt/hd/media/music # Music library path |
116 | - $HOME/.config/mopidy/mopidy.conf:/mopidy/mopidy.conf # Configuration file |
117 | - $HOME/.local/share/mopidy:/var/lib/mopidy/.local/share/mopidy # Local data storage |
118 | - ./cache:/var/lib/mopidy/.cache/mopidy |
119 | restart: unless-stopped |
120 | EOF |
121 |