Skip to content

Deployment

Andrew Field edited this page Apr 20, 2020 · 17 revisions

Deployment

This document describes how the repository-validator can be deployed to Azure.

Project ValidationLibrary.AzureFunctions can be deployed to Azure as an Azure Function. This function validates repositories and reports to a configured channel when it receives HTTP POST with json content from GitHub (Webhook).

These deployment examples uses powershell, but this can also be done otherwise.

NOTE: Azure PowerShell needs to have an authenticated sessions. This can be done with Connect-AzAccount.

For linux users wanting to use the powershell scripts:

  1. Install PowerShell Core for your distribution.
  2. Install Azure PowerShell module.
$ pwsh
PS> Install-Module -Name Az -AllowClobber -Scope CurrentUser

See https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-3.5.0 for more info.

  1. Run the connect account command.
PS> Connect-AzAccount

To quickly create & deploy to the environment, use Deployment\Prepare-Environment.ps1. Prepare the azure development environment by creating your own version of developer-settings.example.json as developer-settings.json and configure the file correctly.

./Deployment/Prepare-Environment.ps1

E.g.,

pwsh ./Deployment/Prepare-Environment.ps1

For testing, you can move ahead to Testing the deployment. The following are some of the individual steps.

Creating environment with Powershell

Deployment\azuredeploy.json contains definition of environment. It can be deployed in multiple ways, but here are few examples. Read Deployment\azuredeploy.json for additional parameters and documentation.

Handle secrets with care, the following secure string example is just for convience.

Azure PowerShell module

New-AzResourceGroupDeployment `
    -Name 'deployment-name' `
    -TemplateFile 'Deployment/azuredeploy.json' `
    -ResourceGroupName 'my-resource-group' `
    -appName 'my-app-name' `
    -gitHubToken (ConvertTo-SecureString -String "your github token here" -AsPlainText -Force) `
    -gitHubOrganization 'your github organization here' `
    -environment 'Development'

Deploying site

Build and pack ValidationLibrary.AzureFunctions into a directory

dotnet publish -c Release -o my-publish-directory ValidationLibrary.AzureFunctions

Create Zip file for deployment

Compress-Archive `
    -DestinationPath "publish.zip" `
    -Path "ValidationLibrary.AzureFunctions/my-publish-directory/*"

Use Publish-AzWebApp to deploy the application

Publish-AzWebApp -ResourceGroupName $ResourceGroup -Name $WebAppName -ArchivePath $fullZipTarget -Force

Testing the deployment

To test the deployment, you can use Test-Validation.ps1. This calls the validation endpoint with example json, which validates this repository

./Testing/Test-Validation.ps1 -ResourceGroup 'resource-group-name'

or

pwsh ./Testing/Test-Validation.ps1 -ResourceGroup 'resource-group-name'

This will also call the status check endpoint and output the configuration of the repository validator.