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

Fix alpine incompatibility #1481

Merged
merged 4 commits into from Apr 19, 2022
Merged

Conversation

CDFN
Copy link
Contributor

@CDFN CDFN commented Apr 18, 2022

Fixes #1480

@@ -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')
Copy link
Contributor

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?

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

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.

Copy link
Owner

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"

Copy link
Contributor Author

@CDFN CDFN Apr 18, 2022

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# 

Copy link
Owner

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.

Copy link
Contributor Author

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 😅

Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be sorted now :)

if [ "$(id -u)" = 0 ]; then
gosu minecraft bash -c "echo $* > '${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}'"
if [[ $distro == alpine ]]; then
Copy link
Contributor

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. :)

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Owner

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:

distro=$(getDistro)
if [[ $distro == alpine ]]; then
exec su-exec ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
else
exec gosu ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
fi

@@ -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
Copy link
Owner

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":

Suggested change
if [[ getDistro == alpine ]]; then
if [[ $(getDistro) == alpine ]]; then

Copy link
Contributor Author

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.

Copy link
Owner

Choose a reason for hiding this comment

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

Totally understand. I am grateful that IntelliJ makes it easy for me to switch between build types:

image

Copy link
Owner

@itzg itzg left a 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?

@CDFN
Copy link
Contributor Author

CDFN commented Apr 19, 2022

Yes 😇

@itzg itzg merged commit 7e843ea into itzg:master Apr 19, 2022
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.

mc-send-to-console doesn't work with alpine
3 participants