Closed avoidik closed 7 years ago
My fault underlying alpine image doesn't have bash at all
If you are talking about this project, bash is included at this line.
how to reproduce this behavior
#!/usr/bin/env bash
set -x
su-exec "${GERRIT_USER}" java "${JAVA_OPTIONS}" "${JAVA_MEM_OPTIONS}" -jar "${GERRIT_WAR}" init --batch --no-auto-start -d "${GERRIT_SITE}" "${GERRIT_INIT_ARGS}"
is that su-exec issue or bash?
This has nothing to do with su-exec
and you have same problem without it. When you use quotes you will always expand it as a single argument, with spaces preserved. So JAVA_OPTIONS="--option1 --option2"; ... java "${JAVA_OPTIONS}"
will pass one single option with a space to java. (--option1 --option2
instead of --option1
+ --option2
)
The behavior is equal in busybox ash and bash (but bash's set -x
does a better job in displaying what goes on by displaying the ''
)
My guess is that this is what you want:
... java ${JAVA_OPTIONS} ${JAVA_MEM_OPTIONS} -jar "${GERRIT_WAR}" init --batch --no-auto-start -d "${GERRIT_SITE}" ${GERRIT_INIT_ARGS}
That way you can have multiple JAVA_OPTIONS, JAVA_MEM_OPTIONS and GERRIT_INIT_ARGS, but you cannot have spaces in those, as space will be separator. At the same time you can have "${GERRIT_WAR}" in a path with spaces (eg GERRIT_WAR="/path/to/my folder with wars/foo.war") and have spaces in the GERRIT_SITE
.
Yes, I agree with @ncopa . "${VAR}" is a good practice when you want to quote a path which may has spaces between it. But it doesn't mean you must use this format everywhere.
In entrypoint here we have a generic template like:
And then during execution this expands to:
So no problem here.
If we change template above to template below (switch to bash, and properly enclose variables into a quotes):
Then this one will be expanded to:
As you can see some variables has been expanded with the single quotes and this issue causes a lot of problems with proper Gerrit startup.
Could someone suggest something about this problem?