Photo by charlesdeluvio / Unsplash

Deploy Sonarqube on Azure Webapps using a Docker container for a simple and efficient setup.

Codequaility Oct 18, 2023

Sonarqube is a nice program, so we use it in our development process. We "can" install it in our development environment but can host it on a server. The Server must not be a virtual machine, so I used an Azure Webapp running a container. Let me show how I did this with azure SaaS solutions.

/

Create a SQL Server Database

Of course, you can use every database for this, but I want to use an SQL Server Database for this example. So let's create a Database in Azure, you can choose a plan that fits your needs.

Important! Use the collation SQL_Latin1_General_CP1_CS_A

After SQL database creation you must fetch the correct JDBC connection string

Create a user and configure the database

After the creation of the Database, you can set up a specific user for the Database.

So on your master Database on the server, you must execute the following command

CREATE LOGIN sonarqube WITH PASSWORD = ‘StrongPassword’;

This will create the user sonarqube on the database server. No switch to the sonarqube database in this you must execute the following script

CREATE USER sonarqube FOR LOGIN SonarQube WITH DEFAULT_SCHEMA = dbo;
ALTER ROLE db_owner ADD MEMBER sonarqube;

This will assign the user sonarqube to your database, and it will apply the db_owner rights to him. For now, you can log in with this user to the database.

Now you must execute the following

ALTER DATABASE sonarqube SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE;

This will set the READ_COMMITED_SNAPSHOT on every transaction on the database. This is required to get the maximum performance on this application.

Configuring the Webapp

I use the sonarqube official image to run the sonarqube instance. For this, I must use the docker-compose deployment feature

In this, I will place the following YAML definition

version: "3.3"
services:
  sonarqube:
    image: sonarqube:lts-community
    ports:
      - "9000:9000"
    environment:
      - SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true
      - SONAR_JDBC_USERNAME=YOUR DB USER
      - SONAR_JDBC_PASSWORD=YOUR DB PASSWORD
      - SONAR_JDBC_URL= YOUR JDBC CONNECTIONSTRING;

This will install the community version that will be long-term supported. It will also expose the right port to use it against your webapplication. The environment variables will be used to configure the database connection.

Additionally, you must set the username and password too.

Let's Run!

Now open up the webpage and it will take a while to load because it will load the image, start it, and install the database.

After waiting a while you will be prompted with a nice login like this

Final words

To be honest, I tried several howtos that use the Webbapp configuration, using custom images or custom startup scripts. Yes there was a solution the would install the sonarqube onto the server, but I wanted a container solution. So I ended up in this, I think that it will be the best solution for my needs.


Did you like this article? Then maybe you can send me some Ko-fi

Tags