Installing SonarQube on Docker and SonarScanner using Homebrew on macOS · GitHub
source link: https://gist.github.com/Swiss-Mac-User/8cc5a5e688f1b22d2c17b865649201d8
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Docker setup
Install the Docker UI application for macOS
brew install docker --cask
Open the Docker.app
from /Applications/Docker.app
Go to the Docker Dashboard
Wait until the "Docker Dashboard starting…"-message disappears (= Setup complete)
«SonarScanner» - SonarQube Code Analyser
Install the SonarScanner (SonarQube Code Analyser)
brew install sonar-scanner
Add the SonarScanner bin-directory to $PATH
Find the SonarScanner bin
-directory (can be taken from the homebrew package installation information)
- Should be something like:
/usr/local/Cellar/sonar-scanner/4.7.0.2747/libexec/bin
Edit the current User's bash source
nano ~/.zshrc
Add these line somewhere:
# === SonarQube ===
# NOTE: sonar-scanner Version in dir-path may change!
export PATH=/usr/local/Cellar/sonar-scanner/4.7.0.2747/libexec/bin:$PATH
Save and close.
Install and run SonarQube on Docker
Installing SonarQube
On Intel based Macs (x86_64)
Install the Docker image from Docker Hub
docker pull sonarqube
Start the x86_64 SonarQube Server
docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest
On ARM based Macs (Apple Silicon)
Install the Docker image from a custom build
mkdir ~/Downloads/sonarqube-arm
git clone https://github.com/SonarSource/docker-sonarqube ~/Downloads/sonarqube-arm/
docker build -t sonarqube-arm ~/Downloads/sonarqube-arm/docker-sonarqube/9/community
Start the compiled ARM SonarQube Server
docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube-arm:latest
Open SonarQube in the webbrowser
Login with default credentials
- User:
admin
- Pass:
admin
…and as instructed, set a new password.
Add a code project to SonarQube
On the SonarQube Dashboard…
- Click on «Create a project manually»
- Fill-in a project name and project key
- NOTE: you will need this project key later!
- Click on «Analyze your project locally»
- Fill-in a Token name
- NOTE: copy the generated Token, you will need this later!
- Click on «Other (for JS, TS, Go, Python, PHP, ...)» and select your OS preferences
- Follow the on-screen instructions
Add a SonarScanner project configuration-file to the desired code project
- Go to the intended project directory
- Create a new file named
sonar-project.properties
- Add and modify the following contents to the sonar-project file:
# must be unique in a given SonarQube instance
sonar.projectKey=my_project_key_as_defined_on_sonarqube_web
# --- optional properties ---
# defaults to project key
#sonar.projectName=My project
# defaults to 'not provided'
#sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Defaults to .
#sonar.sources=.
#sonar.sources=src
# path to test source directories (optional)
#sonar.tests=tests
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
Run the SonarScanner Code Analysis for this project
HINT: You can copy this command from the last step in the SonarQube project setup!
sonar-scanner \
-Dsonar.projectKey=my_project_key_as_defined_on_sonarqube_web \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=my_sonarqube_project_token
…or using a simplified command, which reads other settings from the sonar-project file:
sonar-scanner -Dsonar.login=my_sonarqube_project_token
DONE - see the results on the SonarQube web dashboard
Export and transfer the SonarQube Docker container
E.g. to be used with same settings on another Mac.
- Make sure the Docker.app is running and the Desktop was started!
Stop the server (if running)
docker stop sonarqube
Create an image file from the Docker container
docker commit sonarqube mysonarqube
- NOTE: this can take a moment (or two)…
Save the image file to any user accessible folder in macOS Finder e.g. to the «Downloads»-folder, using:
- Default Docker file (tar, uncompressed):
docker save mysonarqube -o ~/Downloads/SonarQube-DockerBackup.tar
- Gzipped (compressed) Docker file:
docker save mysonarqube | gzip > ~/Downloads/SonarQube-DockerBackup.tar.gz
Transfer the Docker container file to where you need it…
Import a Docker container file
E.g. on the second Mac.
Start the Docker.app, if not running…
Load the Docker container file
docker load < /path/to/SonarQube-DockerBackup.tar.gz
Loading layer [==================================================>] 337.9MB/337.9MB
Loaded image: mysonarqube:latest
- NOTE: this can take a moment (or two)…
Run the imported SonarQube Docker image
NOTE: must use the image file reference, instead of sonarqube:latest
!
docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 mysonarqube:latest
DONE - see the results on the SonarQube web dashboard
http://localhost:9000/dashboard
- NOTE: may take a moment (or two) until accessible…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK