spring-cloud / spring-cloud-cli

Spring Cloud CLI features
Apache License 2.0
156 stars 80 forks source link

Cannot install Spring Cloud CLI in OpenShift Container #78

Closed DennisD2 closed 5 years ago

DennisD2 commented 6 years ago

Hi, I tried to install the Spring Cloud CLI in an OpenShift Container. While Spring Boot CLI installs well and can run test application, Spring Cloud CLI install fails.

It looks as if maven dependencies are installed in a directory called '?' and later searched for in another directory '%3F' (which is ASCII HEX for '?').

I tried the same things on a non container Linux and windows with no problems. So the issue comes up from execution inside anOpenShift v3.7.23 Container (this container runs RedHat Enterprise Linux 7).

Is there a workaround or so for that situation?

I add the session below which shows the fail:

sh-4.2$ cd /tmp
sh-4.2$ mkdir sb
sh-4.2$ cd sb
sh-4.2$ tar xvzf ../spring-boot-cli-2.0.5.RELEASE-bin.tar.gz
sh-4.2$ cd spring-2.0.5.RELEASE/
sh-4.2$ export SPRING_HOME=`pwd`
sh-4.2$ export PATH=$SPRING_HOME/bin:${PATH}
sh-4.2$ export HOME=/tmp/sb 

sh-4.2$ cat >app.groovy
@RestController
class WebApplication {
@RequestMapping("/")
String home() {
"Hello world!"
}
}

sh-4.2$ spring run app.groovy
Resolving dependencies......

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.5.RELEASE)

2018-10-09 06:55:05.216  INFO 284 --- [       runner-0] o.s.boot.SpringApplication               : Starting application on sb-cli-20-kfr2j-debug with PID 284 (started by ? in /tmp/sb)
2018-10-09 06:55:05.238  INFO 284 --- [       runner-0] o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
2018-10-09 06:55:05.777  INFO 284 --- [       runner-0] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1b3f44fe: startup date [Tue Oct 09 06:55:05 UTC 2018]; root of context hierarchy
2018-10-09 06:55:08.438  INFO 284 --- [       runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-10-09 06:55:08.483  INFO 284 --- [       runner-0] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-10-09 06:55:08.484  INFO 284 --- [       runner-0] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-10-09 06:55:08.499  INFO 284 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2018-10-09 06:55:08.577  INFO 284 --- [ost-startStop-1] org.apache.catalina.loader.WebappLoader  : Unknown loader org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@49a189b class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader
2018-10-09 06:55:08.635  INFO 284 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-10-09 06:55:08.636  INFO 284 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2859ms
2018-10-09 06:55:08.766  INFO 284 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-10-09 06:55:08.774  INFO 284 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-10-09 06:55:08.775  INFO 284 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-10-09 06:55:08.775  INFO 284 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-10-09 06:55:08.775  INFO 284 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-10-09 06:55:09.006  INFO 284 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-09 06:55:09.311  INFO 284 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1b3f44fe: startup date [Tue Oct 09 06:55:05 UTC 2018]; root of context hierarchy
2018-10-09 06:55:09.425  INFO 284 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String WebApplication.home()
2018-10-09 06:55:09.430  INFO 284 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-10-09 06:55:09.431  INFO 284 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-10-09 06:55:09.514  INFO 284 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-09 06:55:09.515  INFO 284 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-09 06:55:10.126  INFO 284 --- [       runner-0] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-10-09 06:55:10.221  INFO 284 --- [       runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-10-09 06:55:10.230  INFO 284 --- [       runner-0] o.s.boot.SpringApplication               : Started application in 5.919 seconds (JVM running for 14.893)
^Z
[1]+  Stopped(SIGTSTP)        spring run app.groovy
sh-4.2$ bg
[1] spring run app.groovy &

sh-4.2$ spring install org.springframework.cloud:spring-cloud-cli:2.0.0.RELEASE
Installing into: /tmp/sb/spring-2.0.5.RELEASE/lib/ext
Resolving dependencies...

Up to here all went well. Spring Boot CLI was installed, can resolve dependencies and can start a simple test application. Spring Cloud CLI also was installed without errors.

Now I tried to start the config server, which fails:

sh-4.2$ spring cloud configserver
Oct 09, 2018 6:56:30 AM org.springframework.cloud.launcher.cli.LauncherCommand$LauncherOptionHandler run
SEVERE: Error running spring cloud
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.cloud.launcher.cli.LauncherCommand$LauncherOptionHandler.run(LauncherCommand.java:115)
        at org.springframework.boot.cli.command.options.OptionHandler.run(OptionHandler.java:84)
        at org.springframework.boot.cli.command.OptionParsingCommand.run(OptionParsingCommand.java:54)
        at org.springframework.boot.cli.command.CommandRunner.run(CommandRunner.java:219)
        at org.springframework.boot.cli.command.CommandRunner.runAndHandleErrors(CommandRunner.java:171)
        at org.springframework.boot.cli.SpringCli.main(SpringCli.java:63)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.wrapper.ThinJarWrapper.launch(ThinJarWrapper.java:125)
        at org.springframework.boot.loader.wrapper.ThinJarWrapper.main(ThinJarWrapper.java:97)
        ... 18 more
Caused by: java.lang.IllegalArgumentException: File /tmp/sb/%3F/.m2/repository/org/springframework/cloud/launcher/spring-cloud-launcher-deployer/2.0.0.RELEASE/spring-cloud-launcher-deployer-2.0.0.RELEASE.jar must exist
        at org.springframework.boot.loader.data.RandomAccessDataFile$FileAccess.openIfNecessary(RandomAccessDataFile.java:234)
        at org.springframework.boot.loader.data.RandomAccessDataFile$FileAccess.<init>(RandomAccessDataFile.java:216)
        at org.springframework.boot.loader.data.RandomAccessDataFile$FileAccess.<init>(RandomAccessDataFile.java:206)
        at org.springframework.boot.loader.data.RandomAccessDataFile.<init>(RandomAccessDataFile.java:49)
        at org.springframework.boot.loader.jar.JarFile.<init>(JarFile.java:86)
        at org.springframework.boot.loader.archive.JarFileArchive.<init>(JarFileArchive.java:60)
        at org.springframework.boot.loader.archive.JarFileArchive.<init>(JarFileArchive.java:56)
        at org.springframework.boot.loader.thin.ArchiveUtils.getArchive(ArchiveUtils.java:55)
        at org.springframework.boot.loader.thin.ThinJarLauncher.computeArchive(ThinJarLauncher.java:413)
        at org.springframework.boot.loader.thin.ThinJarLauncher.<init>(ThinJarLauncher.java:143)
        at org.springframework.boot.loader.thin.ThinJarLauncher.main(ThinJarLauncher.java:139)
        ... 24 more

sh-4.2$ ls /tmp/sb/spring-2.0.5.RELEASE/lib/ext
bcpkix-jdk15on-1.56.jar             spring-cloud-launcher-cli-2.0.0.RELEASE.jar
bcprov-jdk15on-1.56.jar             spring-security-crypto-5.0.8.RELEASE.jar
spring-cloud-cli-2.0.0.RELEASE.jar  spring-security-rsa-1.0.5.RELEASE.jar
sh-4.2$

Ok, the lines above are saying that the following file is not there:

 /tmp/sb/%3F/.m2/repository/org/springframework/cloud/launcher/spring-cloud-launcher-deployer/2.0.0.RELEASE/spring-cloud-launcher-deployer-2.0.0.RELEASE.jar

This is correct. The dependencies were installed to another place (namely /tmp/sb/\?/.m2/repository/org/springframework/cloud/launcher/spring-cloud-launcher-deployer/2.0.0.RELEASE/spring-cloud-launcher-deployer-2.0.0.RELEASE.jar) , as can be seen below:

h-4.2$ pwd
/tmp/sb
sh-4.2$ ls -a
.  ..  ?  app.groovy  spring-2.0.5.RELEASE
sh-4.2$ ls \?/.m2/
repository
sh-4.2$ ls \?/.m2/repository/
ch  com  io  javax  net  org
sh-4.2$ ls \?/.m2/repository/org/springframework/cloud/launcher/spring-cloud-launcher-deployer/2.0.0.RELEASE/
_remote.repositories
spring-cloud-launcher-deployer-2.0.0.RELEASE.jar
spring-cloud-launcher-deployer-2.0.0.RELEASE.jar.sha1
spring-cloud-launcher-deployer-2.0.0.RELEASE.pom
spring-cloud-launcher-deployer-2.0.0.RELEASE.pom.sha1

The directories are different:

/tmp/sb/%3F

/tmp/sb/\?

leading to the error...

DennisD2 commented 6 years ago

One additional step...

I tried to "quick fix" the issue with a symbolical link:

sh-4.2$ cd /tmp/sb
sh-4.2$ ln -s \? %3F

Then spring-cloud-launcher-deployer-2.0.0.RELEASE.jar is obviously found, but I get the next error in an unresolved dependency/class (org/slf4j/LoggerFactory): . When examining the local repository, this dependency was not downloaded/resolved.

sh-4.2$ spring cloud configserver -- --spring.cloud.maven.proxy.host=localhost --spring.cloud.maven.proxy.port=3128
Oct 09, 2018 11:09:50 AM org.springframework.cloud.launcher.cli.LauncherCommand$LauncherOptionHandler run
SEVERE: Error running spring cloud
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.cloud.launcher.cli.LauncherCommand$LauncherOptionHandler.run(LauncherCommand.java:115)
        at org.springframework.boot.cli.command.options.OptionHandler.run(OptionHandler.java:84)
        at org.springframework.boot.cli.command.OptionParsingCommand.run(OptionParsingCommand.java:54)
        at org.springframework.boot.cli.command.CommandRunner.run(CommandRunner.java:219)
        at org.springframework.boot.cli.command.CommandRunner.runAndHandleErrors(CommandRunner.java:171)
        at org.springframework.boot.cli.SpringCli.main(SpringCli.java:63)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.wrapper.ThinJarWrapper.launch(ThinJarWrapper.java:125)
        at org.springframework.boot.loader.wrapper.ThinJarWrapper.main(ThinJarWrapper.java:97)
        ... 18 more
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
        at org.springframework.cloud.launcher.deployer.DeployerApplication.<clinit>(DeployerApplication.java:42)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.thin.ThinJarLauncher.launch(ThinJarLauncher.java:192)
        at org.springframework.boot.loader.thin.ThinJarLauncher.main(ThinJarLauncher.java:139)
        ... 24 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
        at org.springframework.boot.loader.thin.ThinJarLauncher$ThinJarClassLoader.loadClass(ThinJarLauncher.java:449)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 34 more
dsyer commented 5 years ago

The "?" should be your home directory. Maybe the JVM is weird in this container and doesn't expose $HOME as System.getProperty("user.home")? Some steps to reproduce would be helpful. I suspect it's to do with your base image though.

P.S. please learn to format your code and logs. You obviously already know about Markdown because you use it to (annoyingly) highlight parts of your issue description, so it should be easy to find docs on the other features that you aren't using.

remyma commented 5 years ago

Hello @DennisD2, I guess it may be related to security context policies from your openshift cluster. Can you tell us which user is running your container (by using command whoami in your pod terminal)?

If openshift security context restricted is configured to run containers with a range uid user (MustRunAsRange), then openshift will run the container with a numeric user from the configured range that has no home folder.

To overcome that, you can test by adding scc anyuid to the default service account in your openshift namespace (if you have cluster-admin permissions):

oc adm policy add-scc-to-user anyuid -z default -n <your_namespace>

This way your container will start with default parametered user (or root if no default user specified in your docker file)

DennisD2 commented 5 years ago

Hi, @remyma, you're right with the guess that the user has no home directory. This is OpenShift default behaviour and each build is executed with another generated non-persistent user.

From the lines above it can be seen that $HOME was defined pointing to an existing writable directory without improving the issue (so, a home folder was defined).

I understand that maybe this can be solved by tweaking the OpenShift cluster policies.

I would prefer to have a simple configuration option, e.g. in an environment variable or whatever, to point to a file system path that can be used by SB Cloud CLI and everyone is fine.

But this issue is some months old and I finally stayed away from using the CLI in OpenShift clusters.