SonarQube is static code analysis tool. It is open source and Java based tool. SonarQube can be setup 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. Since Docker Compose lets you configure related containers in a single YAML file, you get the same Infrastructure-as-Code abilities as Kubernetes. But they come in a simpler system that’s more suited to smaller applications that don’t need Kubernetes’ resiliency and scaling.
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:
New Ubuntu 24.0.4 EC2 instance with at least t2.medium (4 GB RAM)
Port 9000 is opened in security firewall rule
Make sure below is taken care off.
Login to SonarQube EC2 instance using git bash or iTerm, perform below command to configure virtual memory permanently for SonarQube to function:
sudo nano /etc/sysctl.conf
Add the following lines to the bottom of that file by scrolling all the way down:
vm.max_map_count=262144 fs.file-max=65536
Press Ctrl + O and Enter for saving the file.
Press Ctrl + X for exiting the file after saving.
To make sure changes are getting into effect:
sudo sysctl -p
Change Host Name to SonarQube sudo hostnamectl set-hostname SonarQube
Perform System update
sudo apt update
Install Docker-Compose
sudo apt install docker-compose -y
Create docker-compose.yml
this yml has all configuration for installing both SonarQube and Postgresql:
sudo vi docker-compose.yml
(press I or insert button and then Copy the below code high-lighted in yellow color)
How to migrate a Git Repo from GitHub to Azure Repos including all history?
Pre-requisites:
1. GitHub repo setup in GitHub
2. Azure DevOps account setup and project dashboard created.
Steps to migrate an existing repo from GitHub to Azure Repos
There are many ways to migrate from one Git repo to another Git repo. We will learn how to migrate using UI.
Using import option You can easily migrate or import a Repo from GitHub into Azure Repos using import option. This will include importing all the branches and history.
1. Login to Azure Repos first. Create a target repo. You will be importing a GitHub Repo into this Repo.
2. Do not check Add a README file option, click on Create
3. Click on import repo
4. Enter source repo details like GitHub Repo url, and select Requires authentication checkbox.
enter username and Personal Access Token or password.
5. Click Import
6. Now you will see GitHub repo fully imported here including history + all the branches.
We are going to learn how to deploy Docker containers into Azure Kubernetes Cluster(AKS) using Azure pipelines. We will take a simple python app, create docker image and deploy docker image into AKS cluster using Azure pipelines.
Watch the steps in YouTube channel:
Pre-requisites:
1. AKS cluster needs to be up running. You can create AKS cluster using one of the below options:
When you're using Azure Container Registry (ACR) with Azure Kubernetes Service (AKS), an authentication mechanism needs to be established.
To allow an AKS cluster to interact with ACR, an Azure Active Directory managed identity is used.
Create Resource Group
Make sure you are login to Azure portal first.
az login
You need to create a resource group first.
az group create --name myResourceGroup --location southcentralus
Create AKS cluster with 2 worker nodes
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 2 --enable-addons monitoring --generate-ssh-keys
az aks show --name myAKSCluster --resource-group myResourceGroup
The above command should display Cluster exists in Azure portal
Create Azure Container Registry
Run the below command to create your own private container registry using Azure Container Registry (ACR).
az acr create --resource-group myResourceGroup --name myacrrepo31 --sku Standard --location southcentralus
Connect to the cluster
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster --overwrite-existing
To verify the connection to your cluster, use the kubectl get command to return a list of the cluster nodes.
kubectl get nodes
For Deploying Docker images from ACR into AKS Cluster
The following command allows you to authorize an existing ACR in your subscription and configures the appropriate ACRPull role for the managed identity.
az aks update -n myAKSCluster -g myResourceGroup --attach-acr myacrrepo31
To Detach ACR from AKS use below command
az aks update -n myAKSCluster -g myResourceGroup --detach-acr myacrrepo31
SonarQube is one of the popular static code analysis tools. SonarQube enables developers to write cleaner, safer code. SonarQube is open-source, Java based tool. SonarQube uses database for storing analysis results. Database can be MS SQL, Oracle or PostgreSQL. We will use PostgreSQL as it is open source as well.
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.
Please find steps for installing SonarQube on Ubuntu 18.0.4 in Azure Cloud. Make sure port 9000 is opened in firewall rules.
Pre-requisites: Instance should have at least 2 GB RAM. Make sure port 9000 is opened as port 9000 is default port for SonarQube.
sudo useradd -c "user to run SonarQube" -d /opt/sonarqube -g sonarGroup sonar
sudo chown sonar:sonarGroup /opt/sonarqube -R
Modify sonar.properties file sudo vi /opt/sonarqube/conf/sonar.properties uncomment the below lines by removing # and add values highlighted yellow sonar.jdbc.username=sonar sonar.jdbc.password=password
Next, add the below line: sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
Now press escape button, and enter :wq! to come out of the above screen.
Edit the sonar script file and set RUN_AS_USER
sudo vi /opt/sonarqube/bin/linux-x86-64/sonar.sh
Add enable the below line
RUN_AS_USER=sonar
Setup SonarQube as a service(this will enable to start automatically when you restart the server)
Execute the below command:
sudo vi /etc/systemd/system/sonar.service
add the below code in green color: [Unit] Description=SonarQube service After=syslog.target network.target