Friday, February 17, 2023

How to Create a Docker Image for Springboot App and Push Docker image into Amazon ECR from Azure DevOps Pipelines | Azure DevOps Pipelines to Build and Push a Docker image to AWS ECR

Amazon Elastic Container Registry (ECR) is a fully managed Docker container registry that makes it easy to store, share, and deploy container images. We will learn how to build docker image for a springboot microservices app using Azure DevOps(ADO) build pipeline and push docker image into AWS ECR.



What are we going to do in this lab?
1. Create a Repository in AWS ECR for storing docker images
2. Create an IAM user and AmazonEC2ContainerRegistryFullAccess policy.
3. Create access keys for IAM user in AWS console
4. Create service connection in AzureDevOps to connect to AWS using IAM user access & secret keys.
5. Create Azure DevOps Build pipeline with below tasks:
  • maven build for building JAR
  • build docker image
  • push docker image into ECR
6. Verify if docker image has been pushed to AWS ECR

Pre-requisites:

Watch Steps in YouTube channel:

Step 1 - Create a repo in ECR 

Go to AWS console, type ECR



Click on Create Repository

Enter name for your repo - all lower case and Click create repository


Create an IAM user

Go to AWS console --> IAM --> Add Users

Enter name for the user
Search for EC2 and choose AmazonEC2ContainerRegistryFullAccess
Click on Create User

Create security credentials

Click on user name ecr-user
Click on Security credentials



Create Access key

Create Service connection 

Go to Project settings --> Service Connections


Enter Access keys and Secret keys

Enter Connect name and select Grant access to all pipelines
Click on save

Create a classic Azure Build pipeline

Click on use the classic editor

Select GitHub and choose your spring-boot project and click continue



Choose a template for the pipeline, type docker and select docker container

Click on Apply

Select build Agent for the Pipeline
Choose Ubuntu latest as build agent


Add Pipeline variables
imageName as springboot-app
repoName as my-springboot-repo

Add Maven task for building springboot JAR file
Make sure Maven task is moved up..it should be a first task

enter maven goas as install


Customize build an image Task 

start customizing the task, choose the version as 2.0
Enter $(imageName) as  Container repository 
Select build as command from drop down
Tags as it have shown below
Remove push an image task



Add ECR push task


now configure the task

Select as shown in screenshot
Choose aws service connection from drop down
select region as per your settings.
select Image ID
enter as $(imageName):$(Build.BuildId)


Repo Name as $(repoName)
$(Build.BuildId) as tar repo tag


Save and Queue
Select ubuntu latest as build agent..do NOT select window agents.

Now make sure build is successful.



Verify if Docker image has been pushed into AWS ECR

Now login to AWS console --> Go to ECR--> select your repo. verify if image has been uploaded successfully.

Monday, February 13, 2023

How to integrate SonarQube with Azure DevOps | SonarQube Integration with Azure DevOps Classic Pipeline | Automate Code Scan using SonarQube In Azure Classic Pipelines

Please find steps below for integrating SonarQube with Azure DevOps, Previously known as Visual Studio Team Services:


Pre-requisites:

https://marketplace.visualstudio.com/acquisition?itemName=SonarSource.sonarqube


Once added SonarQube plug-in, click on proceed to Organization..



Watch Steps in YouTube channel:

How to integrate SonarQube with Azure DevOps:

Create Token in SonarQube to authenticate with Azure DevOps
You need to login to SonarQube using your admin password. admin/admin123 and click on Admin on your top side.
Click on My Account, Security. 
Under Tokens, Give some value for token name and choose Global analysis token, click on generate Tokens. Copy the token value generated.


Create Service Connections in Azure DevOps 

Login to Azure DevOps. Select your project dashboard.



Click on Project settings --> Service connections


click on New service connection

Type SonarQube and Click Next

Enter SonarQube server url and enter Token created 
Give name for service connection and select Grant access permission to all pipelines.
Click on Save.

Create a Pipeline in Azure DevOps

1. Login to Azure DevOps. Go to Azure Pipelines. Click on create a new pipeline, use classic editor 
Select your Azure Repos
Type Maven and choose maven template as shown below


2. Click on Add tasks
3. Type Sonar











4. Add Prepare Analysis on SonarQube task
5. move up this task to all the way up.
And also search for Java tool installer task and add it


It should be like shown below:



6. Click on prepare sonar analysis configuration task

select Integrate with Maven or Gradle option

7.Click on Java tool installer and change to 11 instead of 8


8. Edit maven task & add install sonar:sonar and also select the path of pom.xml under MyWebApp/pom.xml



















Click on Save and Queue to kick start build.
9. Now login to SonarQube dashboard, click on Projects


Saturday, February 11, 2023

How to fix bugs found during SonarQube code analysis | How to resolve defects found in Java Web App during Sonar Scan

Let's say you have configured a build job in Jenkins to implement CI and you are performing code scan using SonarQube. Code scan results shown some defects(bugs) in your Java Code.

If you look at Jenkins console output, you can see analysis was successful.


If you look at SonarQube project dashboard, you are seeing defects like shown below. How do fix those defects? Let's see the steps to fix those defects.



Pre-requisites:
  • Sonarqube is setup and running
  • Jenkins is up and running
  • Java WebApp setup in GitHub
  • build job configured in Jenkins to perform code scan
Now login to SonarQube
Click on Project name MyWebApp


Click on Overall code, click on 3 Bugs
Now this shows what is the issue with code. it needs <!DOCTYPE> declaration before <html> tag


Click on Why this an issue to learn more about the issue and how you can fix it.
Now code to GitHub where Java WebApp is configured, edit the index.jsp under MyWebApp/src/main/webapp

Fix for bug # 1

add <!DOCTYPE html> above <html> tag

Fix for bug # 2

add <html lang="en">

Fix for bug # 3
    <head>
          <title>My WebApp</title>
          <meta content="text/html; charset=utf-8" />
    </head>  


Now commit the code changes.

run the build in Jenkins by clicking on Build now.
Login to SonarQube, now you will see no bugs.


This is how you can fix defects found by SonarQube.

Wednesday, February 8, 2023

How to Setup SonarQube on a Virtual Machine in Azure Cloud | Install SonarQube on Ubuntu 24.0.4 Virtual Machine in Azure Cloud

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.

Watch steps in YouTube channel:

Please find steps for installing SonarQube on Ubuntu 24.0.4 in Azure Cloud. Make sure port 9000 is opened in firewall rules.

Click here to learn How to setup Virtual Machine in Azure cloud.

How to open port 9000 in Azure VM?

1. Select VM, under Settings--> choose Network


2. Click on Add inbound security role

 
3. Make sure you add entries like below: 
9000 as Destination port ranges
TCP as protocol
310 as priority number
port_9000 as Name

 4. Click on Add, once you add it should be like below:


Pre-requisites:
Instance should have at least 4 GB RAMMake sure port 9000 is opened as port 9000 is default port for SonarQube.

  • Make sure below is taken care off.
Login to instance where you will be installing SonarQube, perform the below command:
sudo vi /etc/sysctl.conf

Add the following lines to the bottom of that file:

vm.max_map_count=262144
fs.file-max=65536

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 
(Copy the entire content high lighted below in yellow color)

version: "3"
services:
  sonarqube:
    image: sonarqube:community
    restart: unless-stopped
    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
    restart: unless-stopped
    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:

Save the file by entering :wq!

Now execute the compose file using Docker compose command:
sudo docker-compose up -d 


Make sure SonarQube is up and running by checking the logs
sudo docker-compose logs --follow


Once you see the message, that's it. SonarQube is been installed successfully. press control C and enter.
Now access sonarQube UI by going to browser and enter public dns name with port 9000

Tuesday, February 7, 2023

DevOps BootCamp by Coach AK on AWS and Azure Cloud Computing Online Classes | Dec 2023 Schedule

The DevOps requirements in the IT market space is expected to grow by 35% by 2024. Getting a DevOps education now is a great investment into your future, which will pay off very fast!


Are you in IT? Tired of your work? Are you not able to make any good progress in your career? 

Are you not having a job? Looking for a break in IT? Are you interested in learning DevOps? 
 
Did you get laid off from your previous job due to Covid-19
 
You are in the right place to kick start your career in DevOps. DevOps is one of the top and hot IT skills right now. Currently almost all the employers are struggling to get right resources in their teams who can do the DevOps and automation work..You could be that person by attending this coaching program.

DevOps Coaching Classes schedules for Dec 2023:
DateTimeTypeWhen?
Dec 20th6:00 to 8:00 PM CSTWeekdaysMondays/Wednesdays    
Dec 9th09:45 AM CST to 11:35 AM on Saturdays
10:30 AM CST to 12:30 PM CST on Sundays    
WeekendsSat/Sundays

DevOps Coaching Highlights:

- Comprehensive hands on knowledge on Git, Jenkins, Maven, SonarQube, Nexus, Terraform, Ansible, Docker, Kubernetes, Helm, AWS IAM, ECR, Docker registry, AWS and Azure cloud platforms.

- Coach is having about 23+ yrs of professional IT experience, 8+ Yrs in DevOps/Cloud/Automation.

- Many students already got placed in reputed companies from this coaching program successfully.

- Working as a Sr.DevOps Coach/Architect in a one of the top IT services companies in USA.

- Unique program...less theory, more hands on lab exercises.
 
Resume preparation will be done with candidates personally.

One-to-one Interview coaching.

- Coaching is purely hands on with 101% job relevant.

100% Job assistance.

- Coached about 17
00+ students successfully for past five years and many of my students got placed with many large enterprises in DFW, Charlotte, Houston, Austin, Chicago, Florida, Seattle, Bay area, Ohio, NJ and NY areas..

To join coaching classes, please contact Coach AK below through email or phone number:
Contact # : +1(469) 850-6424
WhatsApp #: +1 (469) 733-5248
Email id: devops.coaching@gmail.com
Contact: Coach AK

Complete AI-Enabled DevOps Learning Roadmap for 2026 | Skills Required to Become a Modern DevSecOps Engineer

🚀  AI-Enabled DevOps Engineer Roadmap for 2026 The future belongs to AI-Enabled DevOps Engineers, not AI-only Engineers. Strong DevOps fund...