From 7fd701463314e2f5bc5ee134c0628c86f18d1170 Mon Sep 17 00:00:00 2001
From: Chris Pastl <chris@crispybits.app>
Date: Mon, 18 Sep 2023 15:26:31 +0200
Subject: [PATCH] refactor: adapt make and dockerfile, add pulse test

---
 Dockerfile                           | 14 ++++++++++++--
 Makefile                             |  4 +++-
 config/sample.engine-core.docker.ini |  2 +-
 tests/mac-pulse-docker.sh            |  5 +++++
 4 files changed, 21 insertions(+), 4 deletions(-)
 create mode 100644 tests/mac-pulse-docker.sh

diff --git a/Dockerfile b/Dockerfile
index 8cb53d0..75521c1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -12,7 +12,15 @@ RUN apt update --allow-releaseinfo-change && \
       apt -y --no-install-recommends install \
       build-essential \
       alsa-utils \
-      libssl-dev
+      libssl-dev \
+      espeak \
+      vorbis-tools \
+      sox \
+      libasound2 \
+      libasound2-plugins \
+      pulseaudio \
+      pulseaudio-utils
+
 
 # Setup Engine
 ENV TZ=Europe/Vienna
@@ -26,7 +34,9 @@ COPY VERSION /srv/VERSION
 
 RUN groupadd --gid ${AURA_GID} aura && \
       useradd --gid ${AURA_GID} --no-user-group --uid ${AURA_UID} --home-dir /srv --no-create-home aura && \
-      chown -R ${AURA_UID}:${AURA_GID}  /srv /var/audio
+      chown -R ${AURA_UID}:${AURA_GID} /srv /var/audio && \
+      usermod -aG audio,pulse,pulse-access aura && \
+      chown -R aura:aura $HOME
 
 
 USER aura
diff --git a/Makefile b/Makefile
index e5cc2e2..68b2d3b 100644
--- a/Makefile
+++ b/Makefile
@@ -24,6 +24,7 @@ help::
 # Settings
 
 AURA_ENGINE_CORE_ALSA_CONFIG := ${CURDIR}/config/asound.conf
+AURA_ENGINE_CORE_PULSE_CONFIG := ${CURDIR}/config/pulse
 AURA_ENGINE_CORE_SOCKET := "aura_engine_socket"
 AURA_ENGINE_CORE_CONFIG := ${CURDIR}/config/engine-core.docker.ini
 AURA_AUDIO_STORE_SOURCE := ${CURDIR}/audio/source
@@ -37,10 +38,11 @@ DOCKER_RUN = @docker run \
 		--name $(APP_NAME) \
 		--network="host" \
 		--mount type=tmpfs,destination=/tmp \
-		--device /dev/snd \
 		--group-add audio \
 		--ulimit rtprio=95 --ulimit memlock=-1 --shm-size=512m \
 		--env-file docker.env \
+		-e PULSE_SERVER=host.docker.internal \
+    	--mount type=bind,source=/Users/chris/.config/pulse,target=/home/pulseaudio/.config/pulse \
 		-v "$(AURA_ENGINE_CORE_ALSA_CONFIG)":"/etc/asound.conf" \
 		-v "$(AURA_ENGINE_CORE_SOCKET)":"/srv/socket" \
 		-v "$(AURA_ENGINE_CORE_CONFIG)":"/etc/aura/engine-core.ini":ro \
diff --git a/config/sample.engine-core.docker.ini b/config/sample.engine-core.docker.ini
index ac29069..2a72a82 100644
--- a/config/sample.engine-core.docker.ini
+++ b/config/sample.engine-core.docker.ini
@@ -61,7 +61,7 @@ fallback_music_folder="/var/audio/fallback"
 #
 # Choose your weapon: "alsa" (1 input/output), "pulseaudio" (multi input/output)
 # or "jack" (multi input/output)
-soundsystem="alsa"
+soundsystem="pulseaudio"
 
 ##################################################################################################
 # Input / Output
diff --git a/tests/mac-pulse-docker.sh b/tests/mac-pulse-docker.sh
new file mode 100644
index 0000000..2ba7535
--- /dev/null
+++ b/tests/mac-pulse-docker.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+# Run some commands for testing - rm if done...
+#
+
+docker run -it -e PULSE_SERVER=host.docker.internal --mount type=bind,source=/Users/chris/.config/pulse,target=/home/pulseaudio/.config/pulse --entrypoint speaker-test --rm jess/pulseaudio -c 2 -l 1 -t wav
\ No newline at end of file
-- 
GitLab