Git Product home page Git Product logo

azureproj3's Introduction

Deployment of Java application through Azure Devops Pipeline, Azure Repos, ACR, Docker in VM.

We have deployed insurance application in capstone project2 using jenkins, github, dockerhub,docker in AWS EC2 Machine, we will take the same application and deploy through Azure Devops, Azure Repos, Azure container registry, docker in VM machine. I have done the below steps to complete this project:

1. Import the resository:

We will create a new project in Azure DevOps and then go to Repo and click on Import a Repository:

We have already created gihub repo for the capstone2 project:

https://github.com/kotianrakshith/CapstoneProject2

We will import this:

We can see after the import all the files are imported:

(Later we will delete all the files not needed ex. Jenkinsfile,ansible playbook)

2. Build the java application

We wiill go to pipeline and create a new pipeline:

Then select your repo and the code:

Then we will chose maven and only chose package:

So our code till the build stage will be as below: (I have used self hosted pool instead of microsoft as Im not yet approved for it)

Now lets save and run:

As I'm using self hosted agent it will ask for permision:

Once you permit, it will run and we can see that it has sucessfully run and maven has build package to be deployed.

3. Build and push the image to azure container registry

First let us create a container registry:

Go to container registries in azure portal and click create container registry:

Give all the details and click review+create

Now we will go the pipeline and add the build and push to container regstry steps:

Edit the pipeline and add the task buildandpush docker:

The code will be as below:

We have made sure docker is running locally and we will save the pipeline and it should run successfully:

Now let us check the Azure Container Registry if the image has been stored or not.

Go to the registry and navigate to Repositories, you should be able to see newly create ‘insuranceapp’ image

4. Create a virtual machine and install docker:

Now since we have to deploy the docker container in a virtual machine, we will create a virtual machine. Go to virtual machine in azure and click create new:

We will give sufficient details:

Then we will review and create.

Once created, we will go to the networking and all inbound rule:

Then we will add inbound 8081 as this is the port we will be exposing our docker container application.

Now there should be SSH port and 8081 port :

Now lets connect to the VM and install docker.

In this case we are connecting through bastion as its safer. In the bastion, it may ask you to setup bastion, you can click on deploy bastion which automatically will set it up and add new subnet:

Once deployed you can connect using your ssh key

Your vm will open in the new browser tab:

Now let us install docker.

First we upgrade the system

sudo apt update && sudo apt upgrade -y

Now we install the packages, keys, required repositories:

sudo apt install ca-certificates curl gnupg lsb-release

sudo mkdir -p /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb\_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Now run the update command again('sudo apt update')

Now install the docker ce: sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Now check the docker version:

docker -v

If you check the docker you see it is running:

Then you can add your user for docker group(This may not be needed, but if you use different user it is helpful)

sudo usermod -aG docker $USER

Then reload the session using command: newgrp docker

Now we will also do docker login to login to azure container registry:

First we will go to access keys and enable admin user which will give us username and password

We wll use this to login to login server.

docker login kotianrakshith.azurecr.io

5. Add SSH service connection in Azure DevOps to the VM:

Go to the Project Settings-> Service connections-> click New service connection:

Search for SSH:

Give all the required details:

Then save and it should be added:

6. Update pipeline to deploy docker contianer in VM:

We will deploy docker container through docker commands given SSH connections to the VM.

Go to the pipline and edit the pipeline. Search for SSH:

We will select the service connection we added and add following command as a scirpt:

docker stop insuranceapp 2>/dev/null

docker rm insuranceapp 2>/dev/null

docker run -itd -p 8081:8081 --name insuranceapp kotianrakshith.azurecr.io/insuranceapp 

(We need stop and rm if we want to run this pipeline repeatedly as once run there will be container present and we are using 2>/dev/null so it can ignore the errors)

Now lets save and it will run:

We see that it has run sucessfully.

7. Check if app is deployed sucessfully:

First lets go and check the VM if the app is deployed in docker:

We can see from docker ps command that it has been created and running correctly.

Now let us access the app and check. To access it we need to use ip:port so here it is

<http://20.115.123.210:8081/>

We can see that we are able to access it correctly:

That completes this project. We have used the same code from capstone2 but we have used azure tools like Azure Devops, Azure Repos, Azure container registry, docker in VM machine to achive the same results much easily.

azureproj3's People

Contributors

kotianrakshith avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.