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

docker: optimizations #2074

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
.git
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we want to ignore this anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jukebox calls git to show some git values on startup. Without the .git folder this runs into an error. I know it's not a vital function, but I wanted to resolve warnings and errors wherever possible, so when a "real" error occurs you don't get distracted by these "built-in" errors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I understand the reasoning behind it. But this folder can grow a lot over time. So maybe the best approach would be to remove the git command? If it runs into errors, it doesn't work anyways and might be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-added .git along with hidden github dirs and added the git errors to the known to-be-ignored errors in the doc

.githooks
.github
.dockerignore
.DS_Store

# Application
docker
docs
installation
src
shared

# webapp
Expand Down
41 changes: 20 additions & 21 deletions docker/armv7/jukebox.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@ FROM arm32v7/debian:buster-slim
# These are only dependencies that are required to get as close to the
# Raspberry Pi environment as possible.
RUN apt-get update && apt-get install -y \
alsa-utils \
libasound2-dev \
libasound2-plugins \
pulseaudio \
pulseaudio-utils \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

RUN usermod -aG audio,pulse,pulse-access root
ARG UID
ARG USER
ARG HOME
ENV INSTALLATION_PATH ${HOME}/RPi-Jukebox-RFID

ENV HOME /root
ENV MPD_HOST mpd
ENV INSTALLATION_DIR /home/pi/RPi-Jukebox-RFID
ENV DOCKER_DIR ${INSTALLATION_DIR}/docker

WORKDIR $INSTALLATION_DIR
RUN test ${UID} -gt 0 && useradd -m -u ${UID} ${USER} || continue
RUN usermod -aG pulse ${USER}

# Jukebox
# Install all Jukebox dependencies
Expand All @@ -34,13 +31,12 @@ RUN apt-get update && apt-get install -qq -y \
#resolvconf
#python3-spidev

COPY . ${INSTALLATION_DIR}

# Install Jukebox
# Install libzmq with Websocket support from pre-compiled source
ENV ZMQ_TMP_DIR libzmq
ENV ZMQ_PREFIX /usr/local
RUN cd ${HOME} && mkdir ${ZMQ_TMP_DIR} && cd ${ZMQ_TMP_DIR}; \
ENV ZMQ_TMP_DIR "/root/libzmq"
ENV ZMQ_PREFIX "/usr/local"
ENV ZMQ_DRAFT_API 1
RUN mkdir -p ${ZMQ_TMP_DIR} && cd ${ZMQ_TMP_DIR}; \
wget --quiet --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1KP6BqLF-i2dCUsHhOUpOwwuOmKsB5GKY' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1KP6BqLF-i2dCUsHhOUpOwwuOmKsB5GKY" -O libzmq.tar.gz && rm -rf /tmp/cookies.txt; \
tar -xzf libzmq.tar.gz; \
rm -f libzmq.tar.gz; \
Expand All @@ -49,26 +45,29 @@ RUN cd ${HOME} && mkdir ${ZMQ_TMP_DIR} && cd ${ZMQ_TMP_DIR}; \
# Install libzmq with Websocket and compile
# ENV LIBSODIUM_VERSION 1.0.18
# ENV ZMQ_VERSION 4.3.4
# RUN cd ${HOME} && mkdir ${ZMQ_TMP_DIR} && cd ${ZMQ_TMP_DIR}; \
# RUN mkdir -p ${ZMQ_TMP_DIR} && cd ${ZMQ_TMP_DIR}; \
# wget --quiet https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VERSION}-RELEASE/libsodium-${LIBSODIUM_VERSION}.tar.gz; \
# tar -zxvf libsodium-${LIBSODIUM_VERSION}.tar.gz; \
# cd libsodium-${LIBSODIUM_VERSION}/; \
# ./configure; \
# make && make install
# RUN cd ${HOME}/${ZMQ_TMP_DIR}; \
# RUN cd ${ZMQ_TMP_DIR}; \
# wget https://github.com/zeromq/libzmq/releases/download/v${ZMQ_VERSION}/zeromq-${ZMQ_VERSION}.tar.gz -O libzmq.tar.gz; \
# tar -xzf libzmq.tar.gz; \
# zeromq-${ZMQ_VERSION}/configure --prefix=${ZMQ_PREFIX} --enable-drafts; \
# make && make install;

RUN pip3 install --pre pyzmq \
--install-option=--enable-drafts \
--install-option=--zmq=${ZMQ_PREFIX}
USER ${USER}
WORKDIR ${HOME}
COPY --chown=${USER}:${USER} . ${INSTALLATION_PATH}/

RUN pip3 install --no-cache-dir -r ${INSTALLATION_DIR}/requirements.txt
RUN pip3 install --no-cache-dir -r ${INSTALLATION_PATH}/requirements.txt
RUN pip3 install --no-cache-dir --pre --no-binary pyzmq pyzmq

EXPOSE 5555 5556

WORKDIR ${INSTALLATION_PATH}/src/jukebox

# Run Jukebox
# CMD bash
CMD python3 ${INSTALLATION_DIR}/src/jukebox/run_jukebox.py
CMD python3 ${INSTALLATION_PATH}/src/jukebox/run_jukebox.py
4 changes: 2 additions & 2 deletions docker/config/docker.pulse.mpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# be disabled and audio files will only be accepted over ipc socket (using
# file:// protocol) or streaming files over an accepted protocol.
#
music_directory "/home/pi/RPi-Jukebox-RFID/shared/audiofolders"
music_directory "~/RPi-Jukebox-RFID/shared/audiofolders"
#
# This setting sets the MPD internal playlist directory. The purpose of this
# directory is storage for playlists created by MPD. The server will use
Expand Down Expand Up @@ -67,7 +67,7 @@ sticker_file "~/.config/mpd/sticker.sql"
# initialization. This setting is disabled by default and MPD is run as the
# current user.
#
user "root"
# user "root"
#
# This setting specifies the group that MPD will run as. If not specified
# primary group of user specified with "user" setting will be used (if set).
Expand Down
5 changes: 0 additions & 5 deletions docker/config/jukebox.overrides.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
playermpd:
host: mpd
mpd_conf: /etc/mpd.conf
pulse:
outputs:
primary:
pulse_sink_name: Channel_1__Channel_2.2
39 changes: 29 additions & 10 deletions docker/docker-compose.linux.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
version: "3.9"

services:
mpd:
devices:
- /dev/snd

jukebox:
devices:
- /dev/snd
version: "3.9"

services:
mpd:
build:
args:
- UID=${UID:-1000}
- USER=pi
- HOME=/home/pi
environment:
- PULSE_SERVER=unix:/tmp/pulse-sock
volumes:
- ../shared/audiofolders:/home/pi/RPi-Jukebox-RFID/shared/audiofolders
- ../shared/playlists:/home/pi/.config/mpd/playlists
- ./config/docker.pulse.mpd.conf:/home/pi/.config/mpd/mpd.conf
- $XDG_RUNTIME_DIR/pulse/native:/tmp/pulse-sock

jukebox:
build:
args:
- UID=${UID:-1000}
- USER=pi
- HOME=/home/pi
environment:
- PULSE_SERVER=unix:/tmp/pulse-sock
volumes:
- ../shared:/home/pi/RPi-Jukebox-RFID/shared
- ./config/docker.pulse.mpd.conf:/home/pi/.config/mpd/mpd.conf
- $XDG_RUNTIME_DIR/pulse/native:/tmp/pulse-sock
5 changes: 0 additions & 5 deletions docker/docker-compose.mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ version: "3.9"

services:
mpd:
environment:
- PULSE_SERVER=tcp:host.docker.internal:4713
volumes:
- ./config/docker.pulse.mpd.conf:/root/.config/mpd/mpd.conf:rw
- ~/.config/pulse:/root/.config/pulse
- /usr/local/Cellar/pulseaudio/14.2/etc/pulse:/etc/pulse

jukebox:
environment:
- PULSE_SERVER=tcp:host.docker.internal:4713
volumes:
- ~/.config/pulse:/root/.config/pulse
- /usr/local/Cellar/pulseaudio/14.2/etc/pulse:/etc/pulse
12 changes: 0 additions & 12 deletions docker/docker-compose.windows.yml

This file was deleted.

32 changes: 18 additions & 14 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,43 @@ version: "3.9"
services:
mpd:
build:
args:
- UID=0
- USER=root
- HOME=/root
context: ../
dockerfile: ./docker/mpd.Dockerfile
container_name: mpd
ports:
- 6600:6600
- 8800:8800
environment:
- PULSE_SERVER=tcp:host.docker.internal:4713
restart: unless-stopped
volumes:
- ../shared/audiofolders:/home/pi/RPi-Jukebox-RFID/shared/audiofolders:rw
- ../shared/playlists:/root/.config/mpd/playlists:rw
- ./config/docker.mpd.conf:/root/.config/mpd/mpd.conf:rw
- ../shared/audiofolders:/root/RPi-Jukebox-RFID/shared/audiofolders
- ../shared/playlists:/root/.config/mpd/playlists
- ./config/docker.pulse.mpd.conf:/root/.config/mpd/mpd.conf

jukebox:
build:
args:
- UID=0
- USER=root
- HOME=/root
context: ../
dockerfile: ./docker/jukebox.Dockerfile
container_name: jukebox
depends_on:
- mpd
links:
- mpd
environment:
- PULSE_SERVER=tcp:host.docker.internal:4713
ports:
- 5555:5555
- 5556:5556
- 5557:5557
restart: unless-stopped
tty: true
volumes:
- ../src/jukebox:/home/pi/RPi-Jukebox-RFID/src/jukebox
- ../shared:/home/pi/RPi-Jukebox-RFID/shared
- ./config/docker.mpd.conf:/etc/mpd.conf
- ../shared:/root/RPi-Jukebox-RFID/shared
- ./config/docker.pulse.mpd.conf:/root/.config/mpd/mpd.conf

webapp:
build:
Expand All @@ -44,10 +50,8 @@ services:
- jukebox
environment:
- CHOKIDAR_USEPOLLING=true
links:
- jukebox
ports:
- 3001:3000
- 3000:3000
restart: unless-stopped
volumes:
- ../src/webapp:/home/node/webapp
Expand Down
22 changes: 12 additions & 10 deletions docker/jukebox.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,38 @@ FROM debian:bullseye-slim
# These are only dependencies that are required to get as close to the
# Raspberry Pi environment as possible.
RUN apt-get update && apt-get install -y \
alsa-utils \
libasound2-dev \
libasound2-plugins \
pulseaudio \
pulseaudio-utils \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

RUN usermod -aG audio,pulse,pulse-access root
ARG UID
ARG USER
ARG HOME
ENV INSTALLATION_PATH ${HOME}/RPi-Jukebox-RFID

ENV HOME /root
ENV INSTALLATION_PATH /home/pi/RPi-Jukebox-RFID

WORKDIR $INSTALLATION_PATH
RUN test ${UID} -gt 0 && useradd -m -u ${UID} ${USER} || continue
RUN usermod -aG pulse ${USER}

# Jukebox
# Install all Jukebox dependencies
RUN apt-get update && apt-get install -qq -y \
--allow-downgrades --allow-remove-essential --allow-change-held-packages \
gcc at wget \
espeak mpc mpg123 git ffmpeg spi-tools netcat alsa-tools \
espeak mpc mpg123 git ffmpeg spi-tools netcat \
python3 python3-dev python3-pip python3-mutagen python3-gpiozero

COPY . ${INSTALLATION_PATH}
USER ${USER}
WORKDIR ${HOME}
COPY --chown=${USER}:${USER} . ${INSTALLATION_PATH}/

RUN pip3 install --no-cache-dir -r ${INSTALLATION_PATH}/requirements.txt
RUN pip3 install pyzmq

EXPOSE 5555 5556

WORKDIR ${INSTALLATION_PATH}/src/jukebox

# Run Jukebox
# CMD bash
CMD python3 ${INSTALLATION_PATH}/src/jukebox/run_jukebox.py
21 changes: 9 additions & 12 deletions docker/mpd.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@ FROM debian:bullseye-slim

RUN set -eux ; \
apt-get update && apt-get install -y \
alsa-utils \
libasound2-dev \
libasound2-plugins \
pulseaudio \
pulseaudio-utils \
mpd mpc \
--no-install-recommends \
; \
rm -rf /var/lib/apt/lists/*

ENV HOME /root

RUN mkdir ${HOME}/.config ${HOME}/.config/mpd ; \
touch ${HOME}/.config/mpd/state
RUN mkdir -p /home/pi/RPi-Jukebox-RFID/shared/audiofolders

RUN usermod -aG audio,pulse,pulse-access root
ARG UID
ARG USER
ARG HOME

VOLUME ${HOME}/.config/mpd
RUN useradd -m -u ${UID} ${USER} || continue
RUN usermod -aG pulse ${USER}

EXPOSE 6600
USER ${USER}
RUN mkdir -p ${HOME}/.config/mpd ; \
touch ${HOME}/.config/mpd/state

CMD [ ! -s ~/.config/mpd/pid ] && mpd --stdout --no-daemon ${HOME}/.config/mpd/mpd.conf
CMD mpd --stdout --no-daemon ${HOME}/.config/mpd/mpd.conf
Loading