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

Update docker compose file #1812

Merged
merged 2 commits into from
Mar 8, 2024
Merged

Update docker compose file #1812

merged 2 commits into from
Mar 8, 2024

Conversation

HNKNTA
Copy link

@HNKNTA HNKNTA commented Feb 26, 2024

Added S6_KEEP_ENV to example, without it pulse connection won't happen

mikebrady and others added 2 commits December 22, 2023 20:10
Set to 28 days.
Added S6_KEEP_ENV to example, without it pulse connection won't happen
@rmounce
Copy link

rmounce commented Feb 27, 2024

IMO this should be the default behaviour in the Dockerfile, could be achieved with:

  • Adding ENV S6_KEEP_ENV=1
  • or
  • Changing the entrypoint to ENTRYPOINT ["/init","/command/with-contenv","./run.sh"]

I'm effectively doing the latter in my compose file: https://github.com/rmounce/ledfx-airplay-compose/blob/main/docker-compose.yml

@HNKNTA
Copy link
Author

HNKNTA commented Feb 27, 2024

I'm wondering for any potential drawbacks for having this by default in the Dockerfile. Usually it's better to have fewer exposes by default.

@mikebrady
Copy link
Owner

Thanks for this PR. I am not a Docker maven, I'm afraid, and I wonder what Noel Hibbard's (@noelhibbard) view might be.

@noelhibbard
Copy link

Thanks for this PR. I am not a Docker maven, I'm afraid, and I wonder what Noel Hibbard's (@noelhibbard) view might be.

I'm not doing anything special to get PA to work.

My system.pa has this line in it:
load-module module-native-protocol-unix auth-anonymous=1 socket=/var/run/pulse/native

My docker compose has this volume in it:
- /var/run/pulse/native:/tmp/pulseaudio.socket

I don't set any environment vars in my docker compose and I don't even set the pa server within shairport-sync.conf.

@HNKNTA
Copy link
Author

HNKNTA commented Feb 29, 2024

Thanks for this PR. I am not a Docker maven, I'm afraid, and I wonder what Noel Hibbard's (@noelhibbard) view might be.

I'm not doing anything special to get PA to work.

My system.pa has this line in it: load-module module-native-protocol-unix auth-anonymous=1 socket=/var/run/pulse/native

My docker compose has this volume in it: - /var/run/pulse/native:/tmp/pulseaudio.socket

I don't set any environment vars in my docker compose and I don't even set the pa server within shairport-sync.conf.

Well, maybe this works, bot only in case you disabled auth and shairport-sync uses default PA connection as /tmp/pulseaudio.socket, not sure how it detects the defaults though.
Anyway, in case of auth enabled, one need to mount cookie and set an env var with the path for it. Custom path to PA socket → the same. And the current docker image built in the way not allowing custom env variables to shairport w/o this S6_KEEP_ENV=1

@mikebrady
Copy link
Owner

Thanks for these contributions. What is the effect of the S6_KEEP_ENV=1 setting, please? It's a bit hard to understand its significance in this application...

@HNKNTA
Copy link
Author

HNKNTA commented Mar 5, 2024

Thanks for these contributions. What is the effect of the S6_KEEP_ENV=1 setting, please? It's a bit hard to understand its significance in this application...

Let me try to add a bit of context here. So, if one run the container from the shairport-sync image, providing env variables, they'd go to the container context, for example:

NAME=shairport-sync
IMAGE=mikebrady/shairport-sync:latest
CONTAINER_PULSE_RUNTIME_DIR=/tmp/pulse
CONTAINER_SOCKET_PATH=$CONTAINER_PULSE_RUNTIME_DIR/native
CONTAINER_PULSE_COOKIE=$CONTAINER_PULSE_RUNTIME_DIR/cookie

docker run -d --restart unless-stopped \
	--name ${NAME} \
	--net=host \
	-e PULSE_SERVER=$CONTAINER_SOCKET_PATH \
	-e PULSE_COOKIE=$CONTAINER_PULSE_COOKIE \
        -v /run/user/1000/pulse/:$CONTAINER_PULSE_RUNTIME_DIR \
        -v /home/pi/.config/pulse/cookie:$CONTAINER_PULSE_COOKIE \
${IMAGE} -X -o pa --statistics

After that, if one would go to the container via docker exec and do printenv will make sure PULSE_SERVER and PULSE_COOKIE env vars are there. However, if to put printenv to /run.sh (script that runs the shairport-sync) and restart the container — these env vars won't print. That was exactly my case not able to run the container, pulse connection was refused.
To allow S6 overlay to read env vars, S6_KEEP_ENV=1 should be added according to the docs: https://github.com/just-containers/s6-overlay?tab=readme-ov-file#customizing-s6-overlay-behaviour, after this the printenv from /run.sh will print the env variables and pulse connectivity established.

Another option might be to change image build process as @rmounce suggested, but I'm not sure if this should be changed, as most of the users may not use env vars at all.

@noelhibbard
Copy link

noelhibbard commented Mar 5, 2024

Thanks for these contributions. What is the effect of the S6_KEEP_ENV=1 setting, please? It's a bit hard to understand its significance in this application...

Let me try to add a bit of context here. So, if one run the container from the shairport-sync image, providing env variables, they'd go to the container context, for example:

NAME=shairport-sync
IMAGE=mikebrady/shairport-sync:latest
CONTAINER_PULSE_RUNTIME_DIR=/tmp/pulse
CONTAINER_SOCKET_PATH=$CONTAINER_PULSE_RUNTIME_DIR/native
CONTAINER_PULSE_COOKIE=$CONTAINER_PULSE_RUNTIME_DIR/cookie

docker run -d --restart unless-stopped \
	--name ${NAME} \
	--net=host \
	-e PULSE_SERVER=$CONTAINER_SOCKET_PATH \
	-e PULSE_COOKIE=$CONTAINER_PULSE_COOKIE \
        -v /run/user/1000/pulse/:$CONTAINER_PULSE_RUNTIME_DIR \
        -v /home/pi/.config/pulse/cookie:$CONTAINER_PULSE_COOKIE \
${IMAGE} -X -o pa --statistics

After that, if one would go to the container via docker exec and do printenv will make sure PULSE_SERVER and PULSE_COOKIE env vars are there. However, if to put printenv to /run.sh (script that runs the shairport-sync) and restart the container — these env vars won't print. That was exactly my case not able to run the container, pulse connection was refused. To allow S6 overlay to read env vars, S6_KEEP_ENV=1 should be added according to the docs: https://github.com/just-containers/s6-overlay?tab=readme-ov-file#customizing-s6-overlay-behaviour, after this the printenv from /run.sh will print the env variables and pulse connectivity established.

Another option might be to change image build process as @rmounce suggested, but I'm not sure if this should be changed, as most of the users may not use env vars at all.

What is odd is I added a test env variable to my docker compose and it shows up in the container and I am NOT using S6_KEEP_ENV=1 or /command/with-contenv on the entrypoint. I needed curl in my containers so I am building my own image but I'm not doing anything special in my Dockerfile. It looks like this:

FROM mikebrady/shairport-sync:development

RUN apk -U add curl

I'm not opposed to adding S6_KEEP_ENV=1 as the default. It seems like a non-breaking change to me. I just think it's odd mine is keeping the environment without using that option.

@noelhibbard
Copy link

For example I can start a new container like this:
docker run -d --name shairport-sync-envtest -e test=123 mikebrady/shairport-sync:development

Then I can print the environment like this:
docker exec shairport-sync-envtest printenv

And I get this:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=665a658f8afa
test=123
S6_CMD_WAIT_FOR_SERVICES=1
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
HOME=/root

@noelhibbard
Copy link

I see now.. I missed this part:

However, if to put printenv to /run.sh (script that runs the shairport-sync) and restart the container — these env vars won't print.

@mikebrady
Copy link
Owner

Thanks @HNKNTA and @noelhibbard.

I'm not opposed to adding S6_KEEP_ENV=1 as the default. It seems like a non-breaking change to me. I just think it's odd mine is keeping the environment without using that option.

I'll add this to the Docker image Real Soon Now™.

@mikebrady
Copy link
Owner

Actually, @HNKNTA, if you would be kind enough to target this PR at the development branch rather than the master branch, that would be better -- it'll eventually make its way into the master branch.

@HNKNTA HNKNTA changed the base branch from master to development March 8, 2024 08:39
@HNKNTA
Copy link
Author

HNKNTA commented Mar 8, 2024

Changed the target branch.
Thank you @mikebrady @noelhibbard for considering these changes.

@mikebrady mikebrady merged commit ab59f20 into mikebrady:development Mar 8, 2024
9 checks passed
@mikebrady
Copy link
Owner

Many thanks!

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.

4 participants