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
Fix alpine incompatibility #1481
Conversation
bin/mc-send-to-console
Outdated
@@ -12,8 +12,13 @@ if [ ! -p "${CONSOLE_IN_NAMED_PIPE}" ]; then | |||
exit 1 | |||
fi | |||
|
|||
distro=$(cat /etc/os-release | grep -E "^ID=" | cut -d= -f2 | sed -e 's/"//g') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a global variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely no, I'm not very into bash scripting. Thanks for looking, I'll fix in a bit :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there's already global variable called distro
so we can just use it. I removed mine completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there's not a global variable. Instead there's a helper function used as:
distro=$(getDistro)
however, mc-send-to-console
doesn't currently import start-utils, which would need this at the top
. "/start-utils"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird. I rebuilt the container and the command seems to work just fine wihout declaring own distro
root@7b2c0b045c7c:/data# cat /usr/local/bin/mc-send-to-console
#!/bin/bash
: "${CONSOLE_IN_NAMED_PIPE:=/tmp/minecraft-console-in}"
if [ $# = 0 ]; then
echo "ERROR: pass console commands as arguments"
exit 1
fi
if [ ! -p "${CONSOLE_IN_NAMED_PIPE}" ]; then
echo "ERROR: named pipe ${CONSOLE_IN_NAMED_PIPE} is missing"
exit 1
fi
if [ "$(id -u)" = 0 ]; then
if [[ $distro == alpine ]]; then
exec su-exec minecraft bash -c "echo $* > '${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}'"
else
exec gosu minecraft bash -c "echo $* > '${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}'"
fi
else
echo "$@" >"${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}"
fi
root@7b2c0b045c7c:/data# mc-send-to-console op CDFN
root@7b2c0b045c7c:/data#
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since distro
is unset, it'll be an empty string. So it'll be going in the else
block, using gosu
without any errors on a debian based image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... I forgot that when you won't set --build-args it uses debian by default so that would be why 🤦 I'll re-test with alpine based image, sorry for that 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...fyi if you're doing a docker build with the default, then it's building a debian image. Add the build args BASE_IMAGE=openjdk:8-jdk-alpine3.8; DISTRO=alpine
to build a java8 alpine image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be sorted now :)
bin/mc-send-to-console
Outdated
if [ "$(id -u)" = 0 ]; then | ||
gosu minecraft bash -c "echo $* > '${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}'" | ||
if [[ $distro == alpine ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know enough here, but is there more than just this one command that needs to get flipped? I can do some searching too. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at other scripts, I just came accross this one when using on own server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cdfn@cdfn-ryzen dev/docker-minecraft-server (fix/mc-send-to-console-alpine %) » grep -r "gosu"
scripts/start: exec gosu ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
build/ubuntu/install-packages.sh: gosu \
bin/mc-send-to-console: exec gosu minecraft bash -c "echo $* > '${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}'"
It looks like there are only 3 usages, first one is covered with check already, second one is installation script for debian based distros and third is corrected via this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only other use of gosu
is in start
, which is already wrapped in a conditional:
docker-minecraft-server/scripts/start
Lines 48 to 53 in 901b889
distro=$(getDistro) | |
if [[ $distro == alpine ]]; then | |
exec su-exec ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@" | |
else | |
exec gosu ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@" | |
fi |
bin/mc-send-to-console
Outdated
@@ -13,7 +13,11 @@ if [ ! -p "${CONSOLE_IN_NAMED_PIPE}" ]; then | |||
fi | |||
|
|||
if [ "$(id -u)" = 0 ]; then | |||
gosu minecraft bash -c "echo $* > '${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}'" | |||
if [[ getDistro == alpine ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will need to be the following to actually run the function and not be a bare string "getDistro", which will never equal "alpine":
if [[ getDistro == alpine ]]; then | |
if [[ $(getDistro) == alpine ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, again I have tested with wrong command zsh suggested me and ran build without args 🤦 Commit fixing it is there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested (with correct image 😉) and ready to merge?
Yes 😇 |
Fixes #1480