Skip to content

Instantly share code, notes, and snippets.

@tarunxsh
Created January 18, 2024 13:10
Show Gist options
  • Select an option

  • Save tarunxsh/af94671877309ae46f2dec34efc99ef6 to your computer and use it in GitHub Desktop.

Select an option

Save tarunxsh/af94671877309ae46f2dec34efc99ef6 to your computer and use it in GitHub Desktop.

source https://gist.github.com/Swiss-Mac-User/8cc5a5e688f1b22d2c17b865649201d8#file-c_sonarqube-setup-md

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

  1. mkdir ~/Downloads/sonarqube-arm
  2. git clone https://github.com/SonarSource/docker-sonarqube ~/Downloads/sonarqube-arm/
  3. 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

http://localhost:9000

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

  1. Click on «Create a project manually»
  2. Fill-in a project name and project key
  • NOTE: you will need this project key later!
  1. Click on «Analyze your project locally»
  2. Fill-in a Token name
  • NOTE: copy the generated Token, you will need this later!
  1. Click on «Other (for JS, TS, Go, Python, PHP, ...)» and select your OS preferences
  2. Follow the on-screen instructions

Add a SonarScanner project configuration-file to the desired code project

  1. Go to the intended project directory
  2. Create a new file named sonar-project.properties
  3. 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

http://localhost:9000/dashboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment