Warmup sonar scanner

scanner

(ESD) #1

Description

I’d like the ability to warmup the sonar scanner in my pre-built docker image so I don’t waste valuable build minutes fetching/loading plugins and settings from sonarcloud/sonar-server.

While this is possible today, it’s not an intended feature :slight_smile:

Dockerfile

RUN sonar-scanner; exit 0

Notice the ; exit 0 which has to be there for the build to not fail. It’s a hacky workaround if anything.

Output

Scanner configuration file: /opt/sonar-scanner/sonar-scanner-3.1.0.1141/conf/sonar-scanner.properties
Project root configuration file: NONE
SonarQube Scanner 3.1.0.1141
Java 1.8.0_171 Oracle Corporation (64-bit)
Linux 4.4.0-93-generic amd64
User cache: /root/.sonar/cache
SonarQube server 7.1.1
Default locale: “en_US”, source code encoding: “US-ASCII” (analysis is platform dependent)
Publish mode
Load global settings
Load global settings (done) | time=981ms
Server id: AWHW8ct9-T_TB3XqouNu
User cache: /root/.sonar/cache
Load plugins index
Load plugins index (done) | time=326ms
Load/download plugins
Load/download plugins (done) | time=51592ms
Process project properties

EXECUTION FAILURE

Total time: 1:18.198s
Final Memory: 19M/104M

Note that it took quite a long time to finish.

While this example is for the non-msbuild scanner, the same applies there.

A sonar-scanner warmup or dotnet sonarscanner warmup would be nice :slight_smile:


(Tibor Blenessy) #2

Hello,

what you can try to do, is to preserve contents of this directory /root/.sonar/cache in your container. sonar-scanner will first check if the analyzers are available there and avoid downloading them if unnecessary.

Otherwise so far we didn’t feel the need for such warm-up feature.


(ESD) #3

How do I trigger the downloading of analyzers etc in an intetned manner without “faking” a scan?

The root/.sonar/cache directory is perserved in my docker image, however the container is only used once then thrown away. So every run (on build server/CI) is a fresh container. Hence the scanner needs to download the analyzers every single time.


(ESD) #4

I just realized that I can probably use BitBucket pipelines cache to solve this. https://confluence.atlassian.com/bitbucket/caching-dependencies-895552876.html


(Simon Brandhof) #5

Keeping a cache between analyses should be the responsibility of runtime environment. Putting cache in a Dockerized scanner brings complexity and is irrelevant each time SonarQube/SonarCloud is upgraded.
I recommend to use the cache feature provided by most of build cloud providers, like TravisCI (doc) or the mentioned BitBucket Pipelines.