Using SonarQube in Azure Container Instances

Hi! In this article, I'm going to talk about SonarQube running at Azure Container Instances and using Azure SQL for persistent data. This scenario is most used in the Production Environment.

SonarQube is an open-source platform for continuous inspection. It’s used to analyze the code and verify its quality (bugs, code smells and vulnerabilities).

I like to work with SonarQube, it is efficient, fast and easy to include in a development pipeline because it supports many languages and it has easy integration with the best build systems and CI engines in the market.

Create an Environment

At this point, we will use Azure CLI to create objects in Azure, but first, we need to authenticate in Azure. There are several ways to authenticate a user and we will use the default authenticate in the Azure CLI, the interactive sign in. In this mode, the default browser is opened for you to enter credentials and sign-in.

After you sign in Azure we will organize objects through Resource Group and all created objects will be put inside it.

Now we have a Resource Group named rg-sonarqube, it’s created at Azure Datacenter in United States East where all objects will be created for lower latency.

SonarQube uses an embedded memory database called H2, it’s installed when you use a default option during the installation, but not recommended in a production environment because all data are lost when a host is down or powering off. For production, scenarios are must recommended using persistence databases, like SQL Server, Postgres, and MySQL to save all data.

In this article, we will use an Azure SQL it’s a database as a service (DBaaS) and a good choice for persisting the data at the cloud.

Using Azure CLI we will create a logical server in previously created Resource Group, define a firewall rule to allow Azure Services access to the server and database. We will create a database specificating the database collation as SQL_Latin1_General_CP1_CS_AS. This collation is required to install the SonarQube in Azure SQL.

As a final part of the article, we will create a container instance using an official SonarQube image. In this image, environment variables use a dot in the name, but Azure Container Instances don’t support environment variable names using a dot, therefore, we will use environment variables using underscore it’s marked as deprecated, but it’s still working at 7.7-community image.

We will create a container instance with 2 CPU, 3.5GB of memory, using a Linux OS type, exposing a 9000 TCP port, a public IP for external access and connected to Azure SQL. This container will be created inside the same resource group previously created.

When we executing the command above the SonarQube will be installed at the Azure Container Instance and you could access through the public IP assigned by Azure and you will see SonarQube about page. To Log In on SonarQube click on the right top corner and enter with the default credentials (admin/admin).

Now, its time to enjoy the SonarQube!!!

In another article, I will talk about how-to configure SonarQube to receive an Azure DevOps C# project for code analysis.

See you next!!

Solutions Architect with more than 15 years in software development. In love for Docker and Kubernetes, a specialist in .NET and SQL Server.