Installing sonar-scanner in Alpine Linux / 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 -o \
  && unzip -qq \
  && rm -rf \
  && mv sonar-scanner- sonar-scanner

COPY sonar-scanner/conf/
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)


/ # 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 instead of It’s a 551KB download, it’ll reduce the size of the docker container. :wink:

1 Like