Either make SonarQube not create a cache directory, or use a shared one

We are using SonarQube 9.7.1.

We run SonarQube on our CI server. Lately, we’ve been running our tools in the build inside an image, including the “sonar:sonar” goal from mvn. It turns out that that’s been running in a way that “user.home” ends up being deduced as “?”, because the running user isn’t in a passwd file. As a result, it’s been saying:

User cache: ?/.sonar/cache

I’m not sure what that does, but it doesn’t cause any obvious harm. If it’s simply not caching anything, that probably isn’t going to give great performance, but at least it works.

I’m now testing a change that results in “user.home” being set to “/” because I’m mapping the ~/.m2 directory on the host to “/.m2”. This makes my maven cache fast, but now SonarQube fails with

Unable to create user cache: /.sonar/cache

I believe I can change my docker mapping so that I not only map the “~/.m2” directory into the container, but also “~/.sonar”, although I’m not certain it will exist, so I guess I’ll have to manually create it empty on the host if it doesn’t exist before the scan.

One thing I’m wondering, however, is whether the “~/.sonar/cache” directory intended to be shared between multiple processes. I would think it would be, but I’d better be sure.

1 Like

Hello,

One usual source of such behavior is when docker is running with an anonymous user (only a uid), it will have no home folder. In this case, when a program needs a home folder (like sonar or maven to store the cache), it will create a ? folder in the current folder. I believe that could explain what you are seeing currently.

If you are mapping your ~ on your host machine to / in the docker, then a failure to create a .sonar folder could be explained by the user in the container not having the privilege to write into your host ~ folder.

I had a look at the code and documentation. This cache seems to be used to store analyzers that have been downloaded from the SonarQube instance and should be safe to be shared.

If you have any question, feel free to reach out with more details!

1 Like