Persistent SonarQube installation with Docker.
Install docker:
sudo apt update
sudo apt install docker.io
sudo usermod -aG docker $USER
Logout/login to read the new groups.
Configure your system as described in https://hub.docker.com/_/sonarqube:
sudo sysctl -w vm.max_map_count=262144
sudo sysctl -w fs.file-max=65536
Create persistent volumes:
docker volume create sonarqube_conf
docker volume create sonarqube_extensions
docker volume create sonarqube_logs
docker volume create sonarqube_data
First start to let SonarQube create the configuration:
docker run --rm -p 9000:9000 \
-v sonarqube_conf:/opt/sonarqube/conf \
-v sonarqube_extensions:/opt/sonarqube/extensions \
-v sonarqube_logs:/opt/sonarqube/logs \
-v sonarqube_data:/opt/sonarqube/data \
sonarqube
Login to http://X.X.X.X:9000 , change admin password and enable "Force user authentication". After that, you can force-exit (ctrl+c) in the terminal.
Use a dummy alpine image to mount the volume, download the plugin, and set the proper permissions:
docker run --rm --name dummy \
-v sonarqube_extensions:/opt/sonarqube/extensions \
alpine \
sh -c 'wget https://github.com/VillageChief/sonarqube-csv-export-plugin/releases/download/v0.4.1/sonar-csv-export-plugin-0.4.1.jar \
-O /opt/sonarqube/extensions/plugins/sonar-csv-export-plugin-0.4.1.jar && chown 999:999 /opt/sonarqube/extensions/plugins/sonar-csv-export-plugin-0.4.1.jar'
Run SonarQube:
docker run --rm -d -p 9000:9000 \
-e sonar.jdbc.username=sonar \
-e sonar.jdbc.password=sonar \
-v sonarqube_conf:/opt/sonarqube/conf \
-v sonarqube_extensions:/opt/sonarqube/extensions \
-v sonarqube_logs:/opt/sonarqube/logs \
-v sonarqube_data:/opt/sonarqube/data \
sonarqube
Login to http://X.X.X.X:9000 and setup a new project.
Enter in your src directory:
cd my-project-master
Run scan with maven:
docker run -it --rm --name my-maven-project \
-v "$(pwd)":/usr/src/mymaven \
-w /usr/src/mymaven maven:3.3-jdk-8 \
mvn -e clean compile sonar:sonar \
-Dsonar.projectKey=my-project-master \
-Dsonar.host.url=http://X.X.X.X:9000 \
-Dsonar.login=YOUR_SONARQUBE_TOKEN
Run scan with sonar-scanner:
docker run -it --rm --name sonar-scanner \
-v $(pwd):/usr/src \
newtmitch/sonar-scanner \
sonar-scanner -X \
-Dsonar.host.url=http://X.X.X.X:9000 \
-Dsonar.projectKey=my-project-master \
-Dsonar.login=YOUR_SONARQUBE_TOKEN