Installing sonar-scanner in Alpine Linux / Docker

scanner
docker
(Idan Adar) #1

In my company we are shifting from our local build machines to Docker Swarm. As such I am re-creating our build environment in a Dockerfile, where the image produced by it will be the Jenkins agent used for the job run.

As part of this I am also trying to install sonar-scanner. The relevant part is this:

RUN curl -s -L https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip -o sonarscanner.zip \
  && unzip -qq sonarscanner.zip \
  && rm -rf sonarscanner.zip \
  && mv sonar-scanner-3.3.0.1492-linux sonar-scanner

COPY sonar-scanner.properties sonar-scanner/conf/sonar-scanner.properties
ENV SONAR_RUNNER_HOME=sonar-scanner
ENV PATH $PATH:sonar-scanner/bin

It seems to be installed properly because when testing it is found, however… it also returns an error:

docker run -it jenkins:test sh
/ # sonar-scanner
sonar-scanner/bin/sonar-scanner: exec: line 66: /sonar-scanner/jre/bin/java: not found

But Java is present:

/ # java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (IcedTea 3.10.0) (Alpine 8.191.12-r0)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

And:

/ # ls -l /usr/bin/java
lrwxrwxrwx    1 root     root            35 Feb 19 07:26 /usr/bin/java -> ../lib/jvm/default-jvm/jre/bin/java

What am I missing in my setup in order for sonar-scanner to work w/out the error above?

(Eugene Dubrovka) #2

Sonar-scanner uses embedded jre. You will see that in the bin/sonar-scanner.
SONAR_RUNNER_HOME is not used in run script.
uncomment echo commands in the startup that will report current setup.
Try setting JAVA_HOME in environment explicitly.

(Idan Adar) #3

I have set the following in the Dockerfile, which helped.

RUN sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /bin/sonar-scanner/bin/sonar-scanner
(Scott) #4

Since you don’t want to use the embedded JRE, you could use https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492.zip instead of sonar-scanner-cli-3.3.0.1492-linux.zip. It’s a 551KB download, it’ll reduce the size of the docker container. :wink:

1 Like