SonarQube is an open-source platform used for continuous inspection of code quality. It helps developers and teams analyze code, detect bugs, security vulnerabilities, and code smells, and enforce coding standards. It supports multiple programming languages, including Java, JavaScript, Python, C#, and more.
Run the update command
sudo apt update -y
Now install docker and docker-compose, for this run the below set of commands one by one.
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update -y
sudo apt-get install docker-ce docker-ce-cli docker-compose -y
Now confirm that docker and docker-compose are installed and docker service is running
sudo docker --version
sudo docker-compose --version
sudo service docker status
Now update sysctl config file, add below 2 lines and run sysctl again to verify that the file is updated
sudo vi /etc/sysctl.conf
vm.max_map_count=262144 # This defines the maximum number of memory map areas a process may have. It’s often adjusted to accommodate applications like Elasticsearch that require a high number of memory-mapped files.
fs.file-max=65536 # This parameter sets the maximum number of open files the system can handle at one time.
sudo sysctl -p
Next, we will add the Ubuntu user to a docker group so that we can run our docker commands without using the “sudo” prefix.
sudo groupadd docker
sudo usermod -aG docker ubuntu
In order to quickly configure and manage the SonarQube server we will be using the docker-compose file which will set up a sonar instance along with the postgres database. Create a file and enter below code.
nano docker-compose.yml
version: "3"
services:
sonarqube:
image: sonarqube:community
depends_on:
- db
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
ports:
- "9000:9000"
db:
image: postgres:12
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data
volumes:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
postgresql:
postgresql_data:
To set up the sonar server along with Postgres just run the below command which will pull in all the specified images for Sonar and Postgres and will start up the containers using which we can access our server.
docker-compose up -d
Post running the above command, verify if images are downloaded and containers are up and running using the below commands.
docker images
Connect to our Sonar server using the instance public-ip address along with the port that we had specified: 9000
In our case, it will be http://192.168.56.10 :9000
Add a Comment