Tuesday, August 3, 2021

Creating the azure pipeline and configuring python application in azure webapp

 What is an azure pipeline 

Azure pipeline automatically builds, tests the codes and makes them available to others. In a conventional SDLC environment we have to manually test the code in different environment before getting it to the production. But in azure pipe line everything will be done automatically with the pipe line . Azure pipe line has two parts  CI ( Continues Integration ) and CD ( continues deployment) . 

Continues Integration is the practice used by the development teams to merge and test the code. This will help us to fix the bugs in the early stage and move on .Continuous Delivery (CD) is a process by which code is built, tested, and deployed to one or more test and production environments.CI systems produce the deployable artifacts including infrastructure and apps. Automated release processes consume these artifacts to release new versions and fixes to existing systems. Monitoring and alerting systems run continually to drive visibility into the entire CD process

Next thing is the version control systems. The starting to configure the CI CD pipe line is pushing the source code the version control systems like GIT, Bit bucket etc. Each changes in the code will be committed as different versions in the version control system and pushed to the pipe line for CI CD process.

Languages : Azure pipe line can accommodate most of the languages like java, .net, python, nodeJS, C++, Go etc. 

Deployment Targets: We can deploy the code in many components using azure pipeline like VM's, containers, on permises and cloud platforms.Once you have continuous integration in place, the next step is to create a release definition to automate the deployment of your application to one or more environments

Continues Testing: Continues testing in the devops server help us to maintain the quality of the code after each changes we are performing in the code. Rich and actionable reporting felicities which is included in the pipeline help us identify the errors and solve it before committing the changes  . Also we can use package formats like NuGet, npm, or Maven packages to the built-in package management repository in Azure Pipelines.

The basic things which we needed for azure pipeline is 


  • An organization in Azure DevOps.
  • To have your source code stored in a version control system.


The basic architecture of the azure devops pipeline is given below 










Now Let's create the first pipe line . We are choosing python language as the code for this pipe line 

1. Login to the GIT  and fork the below repository in your account ( you can see the for button at top right corner of the GIT

https://github.com/rathishvd/python-flask-azure-devops











2. Next step is to create the azure devops organisation as below and create the project . We have created a project called "flask-webapp"




 

 






3. Once we will click the create pipeline option it will ask the repository details and once we login with the GIT credentials we have to choose the correct repository 









4. Now let us import the repository as below from the GIT HUB 









5. Let us import the repository as blow 










Once the code is imported we have below file layout available in azure repo 










6. Next let us create a new pipe line as below , select pipeline- new pipeline and classic view 










7. Add a new agent job and select python version as below 



















8. Next step is add command line tools and install the dependencies 






 















9. Execute the tests as below ..

Add Command line task as above

  • Enter below details
  • Display name: Pytest
  • Script: pip install pytest && pytest Tests/unit_tests –junitxml=../TestResults/test-results.xml && pip install pycmd && py.cleanup Tests/










10.  Next step is publich the test results by adding the same 










11. Add archive file task to add the application 


  • Display name: Archive application
  • Root folder or file to archive: $(System.DefaultWorkingDirectory)/Application
  • Archive file to create: $(Build.ArtifactStagingDirectory)/Application$(Build.BuildId).zip











12 . Add another archive files tasks as below and fill the details as below 


  • Display name: Archive tests
  • Root folder or file to archive: $(System.DefaultWorkingDirectory)/Tests
  • Archive file to create: $(Build.ArtifactStagingDirectory)/Tests$(Build.BuildId).zip









13. Next step is copy ARM templates 

  • Display name: Copy ARM templates
  • Source Folder: ArmTemplates
  • Target Folder: $(build.artifactstagingdirectory)











14. Add publish artifacts as below 














15 . Now we have to save and run  the CI build as below ...











16. Next step is configuring the continues intergration  ( CI ) part 


Login to Azure portal and and create a resource group first called " flask-webapp-rg"













17. Select an Empty Job and crate a release pipe line 




















18. Give the stage name as Dev ..























19. Next step is to provision azure webapps as below ..
























Go back to release defenition and refresh the subescription 








Add the below details on the task and install the python extension ..

  • Location: South Central US
  • Template: $(System.DefaultWorkingDirectory)/**/windows-webapp-template.json
  • Override template parameters: -webAppName python-flask-mur -hostingPlanName python-flask-mur-plan -appInsightsLocation “South Central US” -sku “S1 Standard” (NOTE – REPLACE PYTHON-FLASK-MUR with your UNIQUE APP NAME)












Install azure python extension in azure app service manager task 












Deploy the application in webapp with below datails..

  • Connection type: Azure Resource Manager
  • Azure Subscription: python-flask-devops
  • App Service type: Web App on Windows
  • App Service name: python-flask-mur ENTER YOUR UNIQUE APP NAME CONFIGURED IN PREVIOUS STEP
  • Package or folder: $(System.DefaultWorkingDirectory)\**\Application*.zip
















Post deployment session need to be configured as below 

  • Deployment script type: Inline Script
  • Inline Script: @echo off
    echo Installing dependencies
    call “D:\home\python353x86/python.exe” -m pip install -U setuptools
    if %errorlevel% NEQ 0 (
    echo Failed to install setuptools >&2
    EXIT /b 1
    )




Under output variables session add the below details 














Publish the test results 







Save the changes and create the release 















Run the release 









Now deployment is scucceded and login to azure portal and check the application  with webapp link 







We have succesfully created the python with azure webapp using azure pipe line ..


Thank you for reading .. 

















Tuesday, July 27, 2021

configuring azure update manager for azure VM patching

 Patching the VM's in azure is one of the most important task in cloud operations to treat vulnerability fixes. We have a service called "update manager" is available for the same in azure portal. An effective software update management process is necessary to maintain operational efficiency, overcome security issues, and reduce the risks of increased cyber security threats. However, because of the changing nature of technology and the continual appearance of new security threats, effective  update management requires consistent and continual attention.

The basic architecture of azure update management is given below. The solution can be used to push updates for on premises and azure VM's 











Let's configure update management in azure portal step by step and test the patching in a linux VM.

  • The following steps highlight the actual implementation
  • Create an Automation account.
  • Add the Log analytics account with automation account 
  • Link the Automation account with the Log Analytics workspace.
  • Enable Update Management for Azure VMs.
  • Add the VM's to the update manager 
  • Patch the VM's using update manager 

Login to the azure portal and select the "automation account" from the search bar . Create the "automation account" as below . Create azure run as account is optional as it is used to manage azure resources from azure runbooks . I am keeping this as default "yes" . Please keep it in mind that name of the "Automation account" should be unique 

















We have succesfully created the Automation account called "unixchipsac" in the same resource group which log analytics workspace contains 















Next step is to add the  Log analytics workspace with the automation account . Select the Automation account which we created and go to update management , we may need a separate log analytics account for the update manager which can be created along with the update manager configuration .














So configured "update management" profile will be as below













Next step is to create a virtual machine in linux as below , i have created a virtual machine in linux named as  "unixchips1" and same is available in update manager portal when we click add VM option 








































Now we have to patch the VM using update manager . If you click on the "missing update" tab you can see the missing updates for the particular VM.














We have to schedule the patching by providing details like deployment name, VM name, groupname ( this option is useful where we can add the machines to different groups and patch together) , pre or post scripts for patching 















So we have successfully scheduled the patching window as below 















After the patching if we click the jobs we can see the patching is completed successfully


 











If we check the Job statistics , we can see the report as below . So we have successfully patched the VM using azure update management 
















Thank you for Reading this blog and feel free to post your feedback and comments