Skip to content

Latest commit

 

History

History
569 lines (388 loc) · 18.5 KB

project-1.md

File metadata and controls

569 lines (388 loc) · 18.5 KB

Poshem Azure DevOps Project

Project Requirements

  • Set up an Azure DevOps organization and create new project: If you don't already have an Azure DevOps organization that you can use for this project or use an existing organization and new project
  • Git for Windows
  • Visual Studio Code
  • Install Terraform

Task 1 Generate a Sample dotnetCore Project and fork a Python Sample app from a git repository

  • make a new directory and cd into it use the command below to generate a sample dotnet template
dotnet new webapp

Alt text

fork a Python Sample app from a git repository

From here Alt text

Link to repo: https://github.com/RussMaxwell/PythonWebApp

Task 2 Create a New Azure Repo in Azure DevOps and clone your existing .Net Core App source code

  • Create a microsoft account

  • Create a new AzureDevops account

  • create an organisation

  • create a project I'll be naming mine POSHEM Alt text

  • click on repo Alt text

  • copy the push an existing repository from command line

Alt text

  • on the termnal initialize the repo
git init

Then stage all the changes by using:

git add .

commit those changes:

git commit -m "commit message"
  • now paste the previously copied code from the project repo to the Terminal
  • it should bring a git credential page login, input your details
  • refresh the web browser, you should see the files Alt text

Task 3 Integrate SonarCloud into your Azure Devops and integrate it into the pull request process

  • We go to the market place and install the sonar cloud extention Alt text Alt text Alt text

  • Let's get our PAT(Personal Access Token) Alt text

Alt text

  • we can actualy define the permission in the custom option but for this project we will go with full access Alt text

  • Vist https://sonarcloud.io/signin and sigin in with your Azure devops account

  • Analyse a new project Alt text

  • import the project you want by filling up the below:

Alt text

  • We are to fill the name of our oganisation and the previously copied PAT and proceed to next page Alt text Alt text

  • Go to the pipeline a build a new one with classic editor Alt text Alt text Alt text Alt text

  • Scroll and pick the NetCore sonar cloud Alt text

  • Now we set it up, pick the Azure pool and Agent specification you want the code to run there's Mac,Linux and Windows with various Specifications. I am using Windows Latest Alt text

  • here i define the parameter where it should restore and build csporj Alt text

  • We shall be creating sonarcloud service connection here Alt text Alt text Alt text Alt text

  • Here we will be add the token given from sonarcloud.io here and give our connection on a name Alt text Alt text

  • We'll set the Prepare analysis on the cloud job and fill the highlited boxes with the data given from the sonarcloud.io Alt text Alt text Incase your build fails try rearrangeing the agent order like this : Alt text

  • Our build is succesful now let's return to sonarcloud.io and refresh Alt text

  • Resfresh the webpage Alt text

  • Steps to take to setup Build validation

Alt text Alt text Alt text Alt text Alt text Alt text Alt text

  • We going to set up pull request in the sonar cloud setting Administration > General settings > Pull request

Alt text Alt text Alt text

we are gonna see the pull request scan in out sonarcloud

  • Now we create a branch Alt text Alt text Alt text

  • make an edit in the C file Alt text Alt text Alt text

  • create a pull request
    Alt text Alt text

  • Wait for the build to complete Alt text Alt text

  • merge it to the master branch Alt text Alt text

  • check sonarcloud webpage Alt text

  • we'll see we have fully integrated sonarcloud it into the pull request process Alt text

Task 4 - Integrate Mend (Formerly White-source) for code quality and vulnerabilities issues with your code.

  • We go to the Market place and install MEND formerly know as white source bolt Alt text

  • Select the free version and install inside your organisation Alt text

  • Go to organisation settings and under extention see MEND Alt text

  • Set it up Alt text

  • Go to pipeline and edit pipeline Alt text

  • add mend bolt to agent job Alt text

  • search and add mend bolt Alt text

  • save and queue Alt text

  • after a successful build check: Alt text Alt text Alt text

  • Mend results Alt text

**Task 5 Create a basic build pipeline from a template and set the trigger settings to invoke a continuous integration build and verify the build completed successfully along with the code quality result from sonar-cloud and mend-bolt **

  • From the previous task we have built a dotnet pipeline an have intergrated sonarcloud and Mend bolt.

Now to set a trigger to invole a continuous intergration build

  • Firstly go to pipeline Alt text

  • edit the existing pipline

Alt text

  • go to the triger tab and enable continous intergration Alt text Alt text

  • add a commit message and click run Alt text

  • after a successful build let's check out Mend bolt and sonarcloud

  • Mend Bolt result: Alt text

  • Sonarcloud result: Alt text Alt text

Task 6 Install Terraform on your Local computer on Google or using Chocolatey

I'll be installing terraform using chocolatey from my terminal

  • go to the official chocolatey website

  • using the powershell with administrative access paste:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
  • after chocolatey is installed use te below command to install Terraform on windows

To install it

choco install terraform

Alt text

To update it

choco upgrade terraform

To uninstall it

choco uninstall terraform

Task 7

Set the Terraform Backends and Provider and Provision :

  • An Azure App Service Plan and an Azure App Service
  • An Azure App Service for container,
  • Azure Container Registry,
  • Azure Container instance
  • Azure Kubernetes Service

Firstly we need a resource group

refrence: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group Alt text

  • After setting up the main.tf and variable.tf

  • run a terraform build if there is no error

  • run a terraform apply

  • type yes

Alt text

Alt text

Alt text

  • check the azure portal for the new created resource Alt text

  • Azure App Service Plan and An Azure App Service

refrence: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service

Alt text

  • After setting up the main.tf and variable.tf

  • run a terraform plan if there is no error

  • run a terraform apply

  • type yes Alt text

  • check the azure portal for the new created resource Alt text

An Azure App Service for container

refrence: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_app

  • After setting up the main.tf and variable.tf Alt text

  • run a terraform plan if there is no error Alt text

  • run a terraform apply

  • type yes Alt text

  • check the azure portal for the new created resource Alt text

Azure Container Registry

refrence: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry

  • After setting up the main.tf and variable.tf Alt text

  • run a terraform plan if there is no error Alt text

  • run a terraform apply

  • type yes Alt text

  • check the azure portal for the new created resource Alt text

Task 8 Create a Release Pipeline and create Three different stage for DEV, QA & Production

DEV Alt text

QA Alt text

PRODUCTION Alt text All environment: Alt text

Task 9

To implement the code quality restriction on the release pipeline,

  • From our previoulsy created repo, let's add a text in the index.cshtml file: Alt text

  • Go to pipeline and classic editor

Alt text

  • click on continue Alt text

  • select empty job Alt text

  • agent job and select dotnet build,restore and publish Alt text

  • add dotnet core agent job 3 times, edit it add restore and publish Alt text

  • add use dotnet core to the agent job Alt text Alt text

  • add publish build artifact to agent job Alt text

  • set dotnet build and restore agent jobs path to **/*.csproj Alt text Alt text

  • set version of use dotnet job to 7.0x Alt text

  • paste this in the argument:

--configuration $(BuildConfiguration) --output
 $(Build.ArtifactStagingDirectory)

Alt text Alt text Alt text Alt text Alt text

  • create a service plan in the pipeline settings: Alt text Alt text Alt text Alt text

  • Create a release pipeline with the below steps: Alt text

Alt text

Alt text

Alt text

Alt text

Alt text

Alt text

Alt text

Alt text

After a succesful Dev environment deployment

  • check the app service for the dev environment and check the domain site Alt text Alt text

Set a pre-deployment approval in the QA stage.

  • Fristly set up QA app service Alt text

  • go to azure devops/project/to the release pipeline and enable continous deployment trigger Alt text

  • set a pre-deployement method Alt text Alt text Alt text Alt text

  • set QA predeployment Alt text

Alt text

Alt text

Alt text

  • edit the repo index.cshtml Alt text Alt text

  • back to the release pipeline Alt text Alt text

Alt text

Alt text Alt text Alt text

create a deployment slot (staging slot) in the Production stage

  • we create production app service plan Alt text

  • go to deployment slot Alt text

  • upgrade the spec to an higher service plan, after the project enusre to terminate all provisoned resources to avoid billings Alt text

  • add slot Alt text

  • choose a name and add Alt text Alt text

  • go to the project azure devops release pipeline Alt text

  • edit and add production stage Alt text

  • configure job task and add deployment slot to job tasks Alt text

  • go to the repo and make a new commit in the index.cshtml file Alt text

  • wait for the build to complete Alt text

  • go check the release pipeline if it completed Alt text

  • go to azureportal, to the production app service and under deployment slot, click swap Alt text

  • swap from target = Staging env to target poshemprod Alt text

  • after a success message Alt text

  • check the default domain in the over view section Alt text

  • result Alt text

Task 10 Integrate Azure pipeline with Slack

  • Navigate to Organization Settings > Security > Policies, and turn on the Third-party application access via OAuth

Alt text Alt text

  • open a slack account and sign in using the app or your web browser

  • create a new workspace or use an existing one, i'm creating a new one

  • go to the settings and add azure pipelines to any channel of choice using these steps: Alt text Alt text Alt text Alt text Alt text Alt text Alt text

  • sign in to azure pipeline from the channel Alt text Alt text Alt text Alt text

Alt text Alt text

  • connect and specify what results you want to see build pipelines or release pipelines and can even specify the exvcat build form the numerous ones you have Alt text
/azpipelines subscribe <build or release url>
  • now let's trigger a build in our pipeline and see the result reflect in our slack app Alt text Alt text