Monday, December 20, 2021

Install SonarQube using Docker | Install SonarQube using Docker on Ubuntu 18.0.4 | Install SonarQube using Docker-Compose

How to setup SonarQube using Docker compose?

SonarQube is static code analyis tool. It is open source and Java based tool. It can be installed quickly using Docker Compose with less manual steps.

What is Docker Compose?
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
 
The purpose of docker-compose is to function as docker cli but to issue multiple commands much more quickly. To make use of docker-compose, you need to encode the commands you were running before into a docker-compose.yml file
 
Run docker-compose up and Compose starts and runs your entire app.

SonarQube Architecture



SonarQube have three components namely
1. Scanner - This contains scanner and analyser to scan application code.
2. SonarQube server - contains Webserver(UI) and search server 
3. DB server - used for storing the analysis reports.

Watch steps in YouTube channel:


Pre-requisites:

  • Ubuntu EC2 up and running with at least t2.small
  • Port 9000 is opened in security firewall rule
  • Make sure maximum number of 
Login to instance where you will be installing SonarQube, perform below command:
sudo vi /etc/sysctl.conf

Add the following lines to the bottom of that file:

vm.max_map_count=262144
fs.file-max=65536

To make sure changes are getting into effect:
sudo sysctl -p

Perform System update
sudo apt-get update

Install Docker
sudo apt-get install docker -y

Install Docker-Compose
sudo apt-get install docker-compose -y

Add current user to docker group
sudo usermod -aG docker $USER

Create docker-compose.yml
this yml has all configuration for installing both SonarQube and Postgresql:
sudo vi docker-compose.yml 

(Copy the below code high-lighted in yellow color)
version: "3"

services:
  sonarqube:
    image: sonarqube:lts-community
    container_name: sonarqube
    restart: unless-stopped
    environment:
      - SONARQUBE_JDBC_USERNAME=sonar
      - SONARQUBE_JDBC_PASSWORD=password123
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonarqube
    ports:
      - "9000:9000"
      - "9092:9092"
    volumes:
      - sonarqube_conf:/opt/sonarqube/conf
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins

  db:
    image: postgres:12
    container_name: db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=password123
      - POSTGRES_DB=sonarqube
    volumes:
      - sonarqube_db:/var/lib/postgresql10
      - postgresql_data:/var/lib/postgresql10/data

volumes:
  postgresql_data:
  sonarqube_bundled-plugins:
  sonarqube_conf:
  sonarqube_data:
  sonarqube_db:
  sonarqube_extensions:

Save the file by entering :wq!

Now execute the compose file using Docker compose command:
sudo docker-compose up -d 


Make sure SonarQube is up and running
sudo docker-compose logs --follow



Once you see the message, that's it. SonarQube is been installed successfully. press control C and enter.
Now access sonarQube UI by going to browser and enter public dns name with port 9000

Please follow steps for integrating SonarQube with Jenkins
https://www.coachdevops.com/2020/04/how-to-integrate-sonarqube-with-jenkins.html

No comments:

Post a Comment

Install Helm 3 Linux - Setup Helm 3 on Linux | Install Helm 3 on Ubuntu | Setup Helm 3 on Linux | Setup Helm 3 on Ubuntu

What is Helm and How to install Helm  version  3? Helm is a package manager for Kubernetes. Helm is the K8s equivalent of yum or apt. I t a...