SonarQube Configuration , Installation ,Deployment via one-click-integration-script in Azure DevOps using Docker

SonarQube Configuration , Installation ,Deployment via one-click-integration-script in Azure DevOps using Docker

SonarQube manual installation is always a pain for any DevOps Engineer wanting to do a DevSecOps testing on his ongoing code getting build, released and deployed via Azure Pipelines in the Production.

Instead of doing installation and configurations which includes running scripts, setting up environment variables ,followed by troubleshooting in the linked Postgres DB and integration, getting things done spending some days, what if I say can be done within 15 mins ?

Yes it is possible .

Whenever wanting to avoid the configuration and installation steps to be done repeatedly avoiding the environment setting up issues, we will go with the best container tools in the market which is Docker. I would highly recommend any person implement this should have some basic knowledge about Docker Containers. To just go through the basics of Docker and standard Docker commands you can refer to this blog .

Since deployment of SonarQube requires Postgres to be on the backend ,we will be going with Docker-Compose deploying both the services via single yaml file.

Lets get started :

We will be using the SonarQube Developer Edition 8.4, for this we need to make a customized docker image.All the zip files for installing SonarQube can be found on this link:

Lets see how we can generate this image, for this we can have JDK installation, creation of some users and groups like sonarqube.

We will be using the concept of Dockerfiles ,its a script used to generate the images of Docker containers. The source code for the Dockerfile is in this git repository.

Dockerfile for the SonarQube image

As you can see in the Dockerfile I am using the base image of OpenJDK ,setting the environment variables ,mentioning the port (9000) creating the group of SonarQube user ,installing dependencies and finally running the script.

In order to store all the issues and reports generated by SonarQube , we will use Postgres, whose image is mentioned along with the relevant environment variables and mounting paths as volumes mentioned in the docker-compose.yml file

About Docker-Compose:

It is a Docker tool used to define and run multi-container applications. With Compose, you use a YAML file to configure your application’s services and create all the app’s services from that configuration.

Think of docker-compose as an automated multi-container workflow. Compose is an excellent tool for development, testing, CI workflows, and staging environments. According to the Docker documentation, the most popular features of Docker Compose are:

1)Multiple isolated environments on a single host
2)Preserve volume data when containers are created
3)Only recreate containers that have changed
4)Variables and moving a composition between environments
5)Orchestrate multiple containers that work together

Compose uses the Docker Engine, so you’ll need to have the Docker Engine installed on your device. You can run Compose on Windows, Mac, and 64-bit Linux. Installing Docker Compose is actually quite easy.

On desktop systems, such as Docker Desktop for Mac and Windows, Docker Compose is already included. No additional steps are needed. On Linux systems, you’ll need to:

Install the Docker Engine

Run the following command to download Docker Compose.

“sudo curl -L “ (uname -s)-(unames)−(uname -m)” -o /usr/local/bin/docker-compose”

followed by “sudo chmod +x /usr/local/bin/docker-compose” and checking the docker-compose version.

Docker-Compose Installation

Docker Compose file

Running the Docker Compose file

Once we have these files ready , we will go to the command line and run “docker-compose up -d”.

It will get built in 17 steps layerwise.

Once you do a “docker ps”:

You should be able to see two containers running, which will get created immediately.

Accessing the SonarQube

Once it starts working : you should be able to access it by using :”hostname:9000" on the port 9000.

In order to have a smooth functioning of the docker contianers I would highly recommend to configure a restart policy and some prerequisites to run SonarQube via script.

In case of restart of the machine, and getting back the same environment with the relevant prerequisites I would also recommend to place this into a cron task.

For Part 2: refer to this link.

For any further Queries or anything related to DevOps or troubleshooting or specialized Docker queries you can DM me on Linkedin or instagram id=acanubhav94.

Happy Hacking !