-
Notifications
You must be signed in to change notification settings - Fork 442
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
exec: line 1: /opt/docker/jre/bin/java: not found
when trying to use docker image build with jlink
#1506
Comments
I was having the same kind of issue, maybe this would help you: #1449 (comment) |
In my case I am building on linux and running on linux 🤔 . The java version is
although i don't think that should matter? |
Looking closer, it does seem like my error is fundamentally different: here is the text version rather than the image i linked above
|
@Christewart Can you maybe give us the content of your |
|
Here is
|
I don't understand where to find this in the staged directory, or else maybe it doesn't exist? |
It's a bash script that you can find in this directory: |
#!/bin/sh
realpath () {
(
TARGET_FILE="$1"
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE=$(basename "$TARGET_FILE")
COUNT=0
while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ]
do
TARGET_FILE=$(readlink "$TARGET_FILE")
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE=$(basename "$TARGET_FILE")
COUNT=$(($COUNT + 1))
done
if [ "$TARGET_FILE" = "." -o "$TARGET_FILE" = ".." ]; then
cd "$TARGET_FILE"
fi
TARGET_DIR="$(pwd -P)"
if [ "$TARGET_DIR" = "/" ]; then
TARGET_FILE="/$TARGET_FILE"
else
TARGET_FILE="$TARGET_DIR/$TARGET_FILE"
fi
echo "$TARGET_FILE"
)
}
# Allow user and template_declares (see below) to add java options.
addJava () {
java_opts="$java_opts $1"
}
addApp () {
app_commands="$app_commands $1"
}
addResidual () {
residual_args="$residual_args \"$1\""
}
# Allow user to specify java options. These get listed first per bash-template.
if [ -n "$JAVA_OPTS" ]
then
addJava "$JAVA_OPTS"
fi
# Loads a configuration file full of default command line options for this script.
loadConfigFile() {
cat "$1" | sed '/^\#/d;s/\r$//' | sed 's/^-J-X/-X/' | tr '\r\n' ' '
}
# Detect which JVM we should use.
get_java_cmd() {
# High-priority override for Jlink images
if [ -n "$bundled_jvm" ]; then
echo "$bundled_jvm/bin/java"
elif [ -n "$JAVA_HOME" ] && [ -x "$JAVA_HOME/bin/java" ]; then
echo "$JAVA_HOME/bin/java"
else
echo "java"
fi
}
# Processes incoming arguments and places them in appropriate global variables. called by the run method.
process_args () {
local no_more_snp_opts=0
while [ $# -gt 0 ]; do
case "$1" in
--) shift && no_more_snp_opts=1 && break ;;
-h|-help) usage; exit 1 ;;
-v|-verbose) verbose=1 && shift ;;
-d|-debug) debug=1 && shift ;;
-no-version-check) no_version_check=1 && shift ;;
-mem) echo "!! WARNING !! -mem option is ignored. Please use -J-Xmx and -J-Xms" && shift 2 ;;
-jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
-main) custom_mainclass="$2" && shift 2 ;;
-java-home) require_arg path "$1" "$2" && jre=`eval echo $2` && java_cmd="$jre/bin/java" && shift 2 ;;
-D*|-agentlib*|-XX*) addJava "$1" && shift ;;
-J*) addJava "${1:2}" && shift ;;
*) addResidual "$1" && shift ;;
esac
done
if [ $no_more_snp_opts ]; then
while [ $# -gt 0 ]; do
addResidual "$1" && shift
done
fi
}
app_commands=""
residual_args=""
real_script_path="$(realpath "$0")"
app_home="$(realpath "$(dirname "$real_script_path")")"
lib_dir="$(realpath "${app_home}/../lib")"
app_mainclass=-jar "$lib_dir/org.bitcoin-s.bitcoin-s-server-1.9.1-67-55506f28-SNAPSHOT-launcher.jar"
script_conf_file="${app_home}/../conf/application.ini"
app_classpath=""
bundled_jvm="$(realpath "${app_home}/../jre")"
if [[ "$OS" == "OSX" ]]; then
#mac doesn't allow random binaries to be executable
#remove the quarantine attribute so java is executable on mac
xattr -d com.apple.quarantine jre/bin/java
fi
chmod +x jre/bin/java #make sure java is executable
process_args "$@"
java_cmd="$(get_java_cmd)"
# If a configuration file exist, read the contents to $opts
[ -f "$script_conf_file" ] && opts=$(loadConfigFile "$script_conf_file")
eval "exec $java_cmd $java_opts -classpath $app_classpath $opts $app_mainclass $app_commands $residual_args" |
This part looks weird to me:
It's not using the |
That part is a custom bash script addition needed to get the desktop app working on mac. This script
Here is a link to the script. If I replace the references to |
Are you not creating a Docker image? What is this a concern in the Docker world?
Well at least, you script is incorrect right now. The |
We need to deliver the software in the form of docker images and desktop applications. The desktop applications require the usage of bash script additions due to the problems I detail above. Is there a way to omit bash script additions with the docker plugin? |
Make two "build modules": One with the constraints/configuration of your desktop app, the other one with constraints/configuration of a Docker image lazy val myApp = ...
lazy val myDesktopApp =
project
.enablePlugins(JavaAppPackaging, JlinkPlugin)
.settings(jlinkSettings: _*)
.settings(desktopSettings: _*)
.settings(Compile / mainClass := Some("my.app.Main"))
.dependsOn(myApp)
lazy val myDockerApp =
project
.enablePlugins(JavaAppPackaging, JlinkPlugin, DockerPlugin)
.settings(jlinkSettings: _*)
.settings(dockerSettings: _*)
.settings(Compile / mainClass := Some("my.app.Main"))
.dependsOn(myApp) |
I just removed the extra bash script stuff for now, I get the exact same error after removing it. Here is the new bash script after disabling the bash script additions. The error
The new bash script without the extra additions. #!/bin/sh
realpath () {
(
TARGET_FILE="$1"
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE=$(basename "$TARGET_FILE")
COUNT=0
while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ]
do
TARGET_FILE=$(readlink "$TARGET_FILE")
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE=$(basename "$TARGET_FILE")
COUNT=$(($COUNT + 1))
done
if [ "$TARGET_FILE" = "." -o "$TARGET_FILE" = ".." ]; then
cd "$TARGET_FILE"
fi
TARGET_DIR="$(pwd -P)"
if [ "$TARGET_DIR" = "/" ]; then
TARGET_FILE="/$TARGET_FILE"
else
TARGET_FILE="$TARGET_DIR/$TARGET_FILE"
fi
echo "$TARGET_FILE"
)
}
# Allow user and template_declares (see below) to add java options.
addJava () {
java_opts="$java_opts $1"
}
addApp () {
app_commands="$app_commands $1"
}
addResidual () {
residual_args="$residual_args \"$1\""
}
# Allow user to specify java options. These get listed first per bash-template.
if [ -n "$JAVA_OPTS" ]
then
addJava "$JAVA_OPTS"
fi
# Loads a configuration file full of default command line options for this script.
loadConfigFile() {
cat "$1" | sed '/^\#/d;s/\r$//' | sed 's/^-J-X/-X/' | tr '\r\n' ' '
}
# Detect which JVM we should use.
get_java_cmd() {
# High-priority override for Jlink images
if [ -n "$bundled_jvm" ]; then
echo "$bundled_jvm/bin/java"
elif [ -n "$JAVA_HOME" ] && [ -x "$JAVA_HOME/bin/java" ]; then
echo "$JAVA_HOME/bin/java"
else
echo "java"
fi
}
# Processes incoming arguments and places them in appropriate global variables. called by the run method.
process_args () {
local no_more_snp_opts=0
while [ $# -gt 0 ]; do
case "$1" in
--) shift && no_more_snp_opts=1 && break ;;
-h|-help) usage; exit 1 ;;
-v|-verbose) verbose=1 && shift ;;
-d|-debug) debug=1 && shift ;;
-no-version-check) no_version_check=1 && shift ;;
-mem) echo "!! WARNING !! -mem option is ignored. Please use -J-Xmx and -J-Xms" && shift 2 ;;
-jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
-main) custom_mainclass="$2" && shift 2 ;;
-java-home) require_arg path "$1" "$2" && jre=`eval echo $2` && java_cmd="$jre/bin/java" && shift 2 ;;
-D*|-agentlib*|-XX*) addJava "$1" && shift ;;
-J*) addJava "${1:2}" && shift ;;
*) addResidual "$1" && shift ;;
esac
done
if [ $no_more_snp_opts ]; then
while [ $# -gt 0 ]; do
addResidual "$1" && shift
done
fi
}
app_commands=""
residual_args=""
real_script_path="$(realpath "$0")"
app_home="$(realpath "$(dirname "$real_script_path")")"
lib_dir="$(realpath "${app_home}/../lib")"
app_mainclass=-jar "$lib_dir/org.bitcoin-s.bitcoin-s-server-1.9.1-67-55506f28-20220523-1201-SNAPSHOT-launcher.jar"
script_conf_file="${app_home}/../conf/application.ini"
app_classpath=""
bundled_jvm="$(realpath "${app_home}/../jre")"
process_args "$@"
java_cmd="$(get_java_cmd)"
# If a configuration file exist, read the contents to $opts
[ -f "$script_conf_file" ] && opts=$(loadConfigFile "$script_conf_file")
eval "exec $java_cmd $java_opts -classpath $app_classpath $opts $app_mainclass $app_commands $residual_args" |
Well, now it's |
Are we allowed to have such a user name in Linux: |
Also, I'd recommand you to avoid |
For context, all of these docker images worked perfectly fine when using |
@guizmaii or anyone else that is curious: I finally got to the bottom of this. It appears that builds cannot be automated to produce jlink'd jres on github actions. This is because github actions does not support bitcoin-s/bitcoin-s#4369 (comment) Here is a stackoverflow question that really helped me get to the root cause: https://stackoverflow.com/questions/63544874/jlink-does-not-produce-redistributable-image/63595415#63595415 A request: It would be nice to be able to disable the jlink build based on an environment variable or predefined sbt native packager setting. This would allow my docker containers targeting arm64 to not use the jlink'd jre. I can just revert to using Here is my suggested workaround for our specific project if it is of interest of anyone else. |
Good to hear :) |
Can you link to the guides you followed to set this up? Would be much appreciated :-) |
@Christewart I didn't do it. One of my Ops did it. But here's the documentation https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners |
Our workaround in bitcoin-s: bitcoin-s/bitcoin-s#4377 |
Expected behaviour
Generate a docker image with the stripped down jre built by jlink. This is useful as slim images can be used as the base image such as alpine, rather than large jdk docker images.
Actual behaviour
When building the docker image with the jlink plugin, I get this error
Information
What sbt-native-packager are you using
1.9.9
What sbt version
1.6.2
What is your build system (e.g. Ubuntu, MacOS, Windows, Debian )
linux
What package are you building (e.g. docker, rpm, ...)
docker image with jlink
As a side note, #1437 would be very useful to have for this build too.
Here is my branch where I am building this from. You can build the image locally with
sbt appServer/docker:publishLocal
https://github.com/Christewart/bitcoin-s-core/tree/2022-05-22-alpine-base-image
The text was updated successfully, but these errors were encountered: