SonarQube stands tall as an indispensable tool for ensuring code quality in software development. Leveraging its capabilities through Docker simplifies the setup process, enabling a seamless integration into your project workflow. By following a few straightforward steps, you can effortlessly deploy and harness the power of SonarQube within a Docker container.
Let's dive into the process together!
Step 1:
Setup SonarQube Docker
$ sudo docker pull sonarqube
$ sudo docker pull sonarsource/sonar-scanner-cli:latest
$ sudo docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube
$ sudo docker logs -f sonarqube
Step 2:
Access SonarQube Web Interface Open your web browser and navigate to http://localhost:9000. The default credentials (username / password) are: admin / admin
Step 3:
Create Local Project in SonarQube
Step 4:
Generate Tokens for Local Project After setting up the project, you'll be prompted to generate a token. Enter a name for the token and click on the "Generate" button. Note down the generated token. This token is needed for authentication during the analysis.
Step 5:
Set Up Your React-Node Project Navigate to your project directory and create a sonar-project.properties.
Note: Project key and sonar token are necessary. See below example for file contents:
Step 6:
Run Sonar Scan Through Docker Image
$ hostname -I | awk '{print $1}'
$ sudo docker run --rm --network=host -e SONAR_HOST_URL=
"http://<ip- address>:9000/" -e SONAR_TOKEN="<your-sonar-token>"
-v $(pwd):/usr/src/ sonarsource/sonar-scanner-cli
Step 7:
View Results in SonarQube Web Interface
Conclusion:
By following these steps and harnessing the combined power of SonarQube and Docker, you've established a robust foundation for maintaining high code quality standards. This foundation paves the way for smoother development cycles, fewer bugs, and ultimately, more reliable software that stands the test of time.
Continue this journey of code excellence by integrating regular Sonar scans into your development pipeline. Your commitment to quality ensures that your software not only meets but exceeds expectations, setting you on a path towards unparalleled success.