Unit 5 - DO Notes
Unit 5 - DO Notes
Step 3: Give a suitable name to your organization and confirm the information.
Then select Continue.
Step 4: The pop-up window of processing will appear.
Step 5: Once the organization is created, it will prompt you to enter the Project
name. Enter any suitable project name and set the visibility to Public or
Private. Normally for small development purposes or for learning purposes we
keep the visibility as Private. Then click on the Create Project button.
The window will appear highlighting the project name. Now we can create Repos
and Pipeline for this project.
AZURE PIPELINE:
Azure pipeline is an automated set of processes that help. developers to compile,
build and deploy codes on other computational platforms.
It is a continuous integration tool like Jenkins. The purpose of this tool is that there
should not be manual intervention, all the changes are automatically executed in the
project.
This pipeline can be used with many application types such as Java, Go, Python,
JavaScript, Node.js, .Net, C++ and Xcode.
Tasks are the building blocks that define pipeline automation. A task is a packaged
script or procedure that is abstracted as a set of inputs. When a job is executed, all
tasks defined within it are executed sequentially.
This pipeline is based on the strong foundations of CI/CD pipelines which
consistently test, build and deploy. They also perform constant deliveries
automatically by continuous testing and deploying the codes to the desired targets in
the project.
The pipeline is broken down into following categories
1. Source control
2. Build tools
3. Package creation
4. Configuration management
5. Monitoring
Continuous Integration (CI): Continuous Integration (CI) is the process of
automating the build and testing of code, every time a team member commits
changes to version control. All the changes made by the development and testing
team are committed to the master branch to bring out a clean and unambiguous
code.
Continuous Development (CD): Continuous Delivery (CD) is the process to build,
test, configure and deploy from a build to a production environment.
Advantages:
Reliability: Monitoring and logging practices help you stay informed about
performance in real-time.
Improved Collaboration: With DevOps and a single combined platform developers
and operation, teams collaborate easily. They are no longer isolated from-each other
and share responsibilities and feedback.
Rapid Delivery of Code: DevOps combines tools and all processes in the cloud so
starting from developing the apps and testing it in the cloud by using automated
tools and deploying as soon as code commit happens. This enables rapid delivery.
Accessibility: Azure DevOps users get access to new features every three weeks.
Microsoft is transparent.
Scaling: Infrastructure as code helps you manage your development, testing and
production environments in a repeatable and more efficient manner.
Security: Automated compliance policies, fine-grained controls and configuration
management techniques can define and then track compliance at scale.
Flexibility: If a DevOps team doesn't want or need the full suite of services, they can
acquire them independently.
CREATE A PIPELINE:
Pipeline allows us to build and deploy the application automatically. If we commit
any changes to the code, then those changes are also reflected automatically to the
final output.
We will first build a sample application and then create a pipeline for building and
deploying that application on the web server.
Build a Sample Code:
We will discuss how to create a Maven based Web application using Eclipse.
This is a simple web app, in which we have simply written an index.jsp file,
displaying some messages.
Stage 1: Create a Maven Web Application Project
Step 1: Click on File->New->Maven Project. Following pop-up window will appear -
Just click next button without selecting any archetype over here. Another window will
appear as given below - Select the maven-archetype-webapp
Then click the Next button. Provide the Group Id and Artifact Id as per your choice.
Click the finish button.
Step 2: In the project explorer window, right-click on the project select properties->
Java Build Path.
Click on libraries path and click on JRE System Libraries and edit it by giving the
path of JDK.
Click on Finish button. Then click on apply and close.
Step 3: The project structure of your Maven web application project.
Just open the index.jsp file and edit it. I have edited it as follows-
index.jsp
<!DOCTYPE html>
<html>
<body>
<h2> Welcome Anuradhal!</h2>
<h2> Enjoy!!</h2>
</body>
</html>
Step 4: Now edit pom.xml by adding some dependencies.
Add Jakarta Servlet dependency in the pom.xml file. The dependency code can be
obtained-from mvnrepository.com. The code for the dependency is as follows -
<!-- https://mvrepository .com/artifact/jak arta.servlet/j akarta.servlet-api -->
<dependency>
<groupId>jakarta. servlet </groupld>
<artifactld> jakarta.servlet-api</artifactld>
<version>6.0.0</version>
<scope > provided</scope>
</dependency>
Step 5: This application can be run using Maven Build.
Step 6: Create a GitHub repository named My WebApp and push this application in
the Git Hub repository.
Stage 2: Push Maven Web App on GitHub
Step 1: Sign in the Github.com by entering your username and password.
Give the repository name. Note that this name must be the same name as of your
Maven project (we have created in stage1). Click on New and then type the name of
the repository
Step 2: Now click on Settings -> Developer Settings, click on Personal access
tokens.
click on generate new token in order to create a token. This token is generated so
that any third party application can access this repository without re-entering the
login name and password.
I have given the token name as mytoken and no-expiration to this token. Selected
the repo checkbox.
Then click on the Generate Token button. A token will get generated.
Step 3: Now in the eclipse IDE, from the menu bar, click on Window->Show view-
>other. Select the Git Repositories.
Step 4: On github.com, just copy the URL link of your repositories.
Now type some commit message and click on Commit and Push.
Then a pop up window will appear on which as a user-name we have to enter the
Github’s user email id. And as a password it has to copy the Personal access token
from Github.
Thus the copied token is pasted as a password in eclipse. Check the checkbox Store
in Secure Store. Then click Login button.
Step 6: Now, in the web browser just refresh GitHub.com. we can now see our web
application on GitHub.
That’s it, we have pushed our application on GitHub.
Modify Azure-Pipelines.yaml File:
Stage 1: Creation of Azure Web App Service
Step 1: Login to the microsoft azure cloud portal. You can log-in using GitHub account
also. Click on app-services.
Step 2: Then select Create->Web App. The create web app page will appear. Enter the
name of the resource group of your choice. Then give any suitable web app name.
Step 3: Select the runtime stack as Java, as I have to deploy a Java based web
application. The tomcat container is used to run the Java application. Hence selected the
Apache Tomcat 9.0. The operating system on which the web app is running is Linux.
Rest of the parameters are kept as default. Click the on Review + Create button. Then
click on Create.
This will start the deployment process. You will get deployment successful message as
follows -
Step 4: Now click on the Go to resource button. We will get the default domain name.
Here I will get the domain name as noonewebapp.azurewebsites.net
Stage 2: Create Azure Pipeline using Azure DevOps
Troubleshooting: When we start creating a azure pipeline using azure DevOps, normally
we get the error “No hosted parallelism” error. To fix this error, the solution is simple,
visit https://aka.ms/azpipelines-parallelism-request site. Fill the details as asked in the
form, for betterment fill the form once with private projects and again with a public
project option selected. Within one or two days, Microsoft grants you the permission.
This arrangement is for security reasons. That’s it.
In this application, we have simply written an index.jsp page, displaying some header
messages.
This pipeline will build our web application and deploy it automatically to the web app
service, created in stage 1 (given above).
Step 1: Open the azure DevOps page and create a New Project. And give a suitable
name to your project. I have given the name SampleWebApp.
Step 2: Click on repos, to select the existing repository.
Click on the Import repository option. Now go to GitHub.com and copy the URL of the
repository of your choice. I have created a simple Java Web application in the repository
named MyWebApp. I will copy the URL.
and paste it in the Clone URL text box of azure DevOps. Then click on the Import
button.
Step 3: Now click on Pipelines and click on Create Pipeline. Then select the repository.
Then configuration page appears. Select Maven Package Java Project Web app to
Linux on Azure.
Step 4: Select the subscription (Free Trial). This is the subscription which you have
selected on your Azure cloud services.
Once you click Create button. It will prompt you to enter microsoft username to login.
Once you login, It will allow to select the web App name that comes automatically on
Azure DevOps. Click on Validate and Configure button. It will then start generating the
yaml file automatically for your web app. Note that, everything is automatic over here, we
simply need to configure our repository.
Step 5: The yaml file named azure-pipelines.yml gets generated. Just edit the location
of pom.xml as My WebApp/pom.xml Just click the Save and Run button. The yaml file
is as follows
trigger:
- master
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: ‘b2e71b79-27af-4ade-9493-33852b2e0ae8’
# Web app name
webAppName: ‘NoOneWebApp’
# Environment name
environmentName: ‘NoOneWebApp’
# Agent VM image name
vmImageName: ‘ubuntu-latest’
stages:
- stage: Build
displayName: Build stage
jobs:
- job: MavenPackageAndPublishArtifacts
displayName: Maven Package and Publish Artifacts
pool:
vmImage: $(vmImageName)
steps:
- task: Maven@3
displayName: ‘Maven Package’
inputs:
Set the exact
location of your
mavenPomFile: ‘MyWebApp/pom.xml’
- task: CopyFiles@2
displayName: ‘Copy Files to artifact staging directory’
inputs:
SourceFolder: $(System.DefaultWorkingDirectory)’
Contents: ‘**/target/*.?(war|jar)’
TargetFolder: $(Build.ArtifactStagingDirectory)
- upload: $(Build.ArtifactStagingDirectory)
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded ()
jobs:
- deployment: DeployLinuxWebApp
displayName: Deploy Linux Web App
environment: $(environmentName)
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
displayName: ‘Azure Web App Deploy: NoOneWebApp’
inputs:
azureSubscription : $(azureSubscription)
appType : webAppLinux
appName: S(webAppName)
package: ‘$(Pipeline.Workspace)/drop/**/target/*.?(war|jar)’
Step 6: It will start working in two stages Build Stage and Deployment Stage.
Step 7: For the deployment stage, it will ask for permission. Just permit it by clicking on
it and then clicking on the View button.
After granting the permission, the deployment stage starts. On successful completion of
deployment stage we get following output.
Thus both the build stage and deployment stages are completed.
Step 8: Now, go to azure cloud and click on the URL to get the output as follows - Note
that we have to add the name of the GitHub repository to the domain name to get the
output.
Step 9: Just edit index.jsp in our repository of azure DevOps.
Again build and deploy the azure DevOps pipeline, we will get the changes reflected on
the web page.
Thus, azure DevOps and azure cloud web service allows us to automate the building and
deployment of the web application.