Skip to content

Commit

Permalink
CI/CD Pipeline test (#7)
Browse files Browse the repository at this point in the history
* Secrets changes, config.json

* Bugfix

* Review comments

* SampleApp secret

* Added azure-pipelines, GitHub workflow and SampleApp.yaml (#6)

* Create main.yml

* Create azure-pipelines.yml

* Update main.yml

* Update windows-webapp-template.json

* Set up CI with Azure Pipelines

[skip ci]

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update main.yml

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update main.yml

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update main.yml

* Update main.yml

* Update config.json

* Update config.json

* Update config.json

* Add files via upload

* Update azure-pipelines.yml

* Update and rename main.yml to workflow.yml

* Update config.json

* Update windows-webapp-template.json

Co-authored-by: Example man <[email protected]>
Co-authored-by: Nikita Nallamothu <[email protected]>
  • Loading branch information
3 people authored Nov 23, 2021
1 parent f6fc8a8 commit 2326a2a
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 2 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# This is a basic workflow to help you get started with Actions

name: Sample App deploy

# Controls when the workflow will run
on:
workflow_dispatch:

env:
AZURE_WEBAPP_NAME: "<Name of your webapp>" # set this to your application's name
LOAD_TEST_RESOURCE: "<Name of your load test resource>"
LOAD_TEST_RESOURCE_GROUP: "<Name of your load test resource group>"
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '14.15.1' # set this to the node version to use
LOCATION: "West US"
APPINSIGHTLOCATION: "West US"
DATABASEACCOUNTLOCATION: "westus"

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build-and-deploy:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout GitHub Actions
uses: actions/checkout@v2

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION }}

- name: npm install and build
continue-on-error: false
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Login to Azure
uses: azure/login@v1
continue-on-error: false
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

# Deploy Arm template
- name: Deploy ARM Template
uses: azure/powershell@v1
continue-on-error: false
with:
inlineScript: |
az group create --name "${{ env.AZURE_WEBAPP_NAME }}-rg" --location "${{ env.LOCATION }}"
$deploymentOutputs = az deployment group create --resource-group "${{ env.AZURE_WEBAPP_NAME }}-rg" --mode Incremental --template-file ./windows-webapp-template.json --parameters webAppName="${{ env.AZURE_WEBAPP_NAME }}" --parameters hostingPlanName="${{ env.AZURE_WEBAPP_NAME }}-host" --parameters appInsightsLocation="${{ env.APPINSIGHTLOCATION }}" --parameters databaseAccountId="${{ env.AZURE_WEBAPP_NAME }}db" --parameters databaseAccountLocation="${{ env.DATABASEACCOUNTLOCATION }}" -o json
$deploymentOutputs = $deploymentOutputs | ConvertFrom-Json
$connectionString = [String]$deploymentOutputs.properties.outputs.azureCosmosDBAccountKeys.value
$setConnectionString = az webapp config appsettings set --name "${{ env.AZURE_WEBAPP_NAME }}" --resource-group "${{ env.AZURE_WEBAPP_NAME }}-rg" --settings CONNECTION_STRING="$connectionString"
$setAppSettings = az webapp config appsettings set --name "${{ env.AZURE_WEBAPP_NAME }}" --resource-group "${{ env.AZURE_WEBAPP_NAME }}-rg" --settings MSDEPLOY_RENAME_LOCKED_FILES=1
$setAppSettings = az webapp config appsettings set --name "${{ env.AZURE_WEBAPP_NAME }}" --resource-group "${{ env.AZURE_WEBAPP_NAME }}-rg" --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
azPSVersion: "latest"

- name: 'Deploy to Azure WebApp'
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

loadTest:
name: Load Test
needs: build-and-deploy
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Actions
uses: actions/checkout@v2

- name: Login to Azure
uses: azure/login@v1
continue-on-error: false
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: 'Azure Load Testing'
uses: azure/load-testing@v1
with:
loadTestConfigFile: 'SampleApp.yaml'
loadTestResource: ${{ env.LOAD_TEST_RESOURCE }}
resourceGroup: ${{ env.LOAD_TEST_RESOURCE_GROUP }}

- uses: actions/upload-artifact@v2
with:
name: loadTestResults
path: ${{ github.workspace }}/loadTest
5 changes: 5 additions & 0 deletions SampleApp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: v0.1
testName: SampleAppTest
testPlan: SampleApp.jmx
description: 'SampleApp Test Run'
engineInstances: 1
155 changes: 155 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- main

pool:
vmImage: ubuntu-latest

variables:
webAppName: '<Name of your webapp>'
serviceConnection: '<Name of your webARM Service connection>'
azureSubscriptionId: '<Azure subscriptionId>'
loadTestResource: '<Name of your load test resource>'
loadTestResourceGroup: '<Name of your load test resource group>'
location: 'EAST US'


stages:
- stage: Build
displayName: Build
jobs:
- job: Build
displayName: Build
pool:
vmImage: windows-latest

steps:
- task: NodeTool@0
inputs:
versionSpec: '14.15.1'
displayName: 'Install Node.js'

- script: |
npm install
npm run build
displayName: 'npm install and build'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true

- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop

- stage: Deploy
displayName: Deploy
dependsOn: Build
condition: succeeded()
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: windows-latest

steps:
- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: $(serviceConnection)
subscriptionId: $(azureSubscriptionId)
action: 'Create Or Update Resource Group'
resourceGroupName: '$(webAppName)-rg'
location: 'East US'
templateLocation: 'Linked artifact'
csmFile: '$(System.DefaultWorkingDirectory)/windows-webapp-template.json'
overrideParameters: '-webAppName $(webAppName) -hostingPlanName $(webAppName)-host -appInsightsLocation "East US" -databaseAccountId $(webAppName)db -databaseAccountLocation "East US"'
deploymentMode: 'Incremental'
deploymentOutputs: 'output'

- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$deploymentOutput= ConvertFrom-Json '$(output)'
$connectionStringValue= $deploymentOutput.azureCosmosDBAccountKeys.value
Write-Host "##vso[task.setvariable variable=connectionString;issecret=true;]$connectionStringValue"
- task: AzureAppServiceSettings@1
inputs:
azureSubscription: $(serviceConnection)
appName: '$(webAppName)'
resourceGroupName: '$(webAppName)-rg'
appSettings: |
[
{
"name": "CONNECTION_STRING",
"value": "$(connectionString)",
"slotSetting": false
},
{
"name": "MSDEPLOY_RENAME_LOCKED_FILES",
"value": 1,
"slotSetting": false
},
{
"name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
"value": true,
"slotSetting": false
}
]
- task: DownloadPipelineArtifact@2
inputs:
artifact: drop

- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: $(serviceConnection)
appType: 'webApp'
WebAppName: $(webAppName)
packageForLinux: '$(Pipeline.Workspace)/$(Build.BuildId).zip'
ScriptType: 'Inline Script'
InlineScript: 'npm install'
- task: DownloadPipelineArtifact@2
inputs:
artifact: drop
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: $(serviceConnection)
appType: 'webApp'
WebAppName: $(webAppName)
packageForLinux: '$(Pipeline.Workspace)/$(Build.BuildId).zip'
enableCustomDeployment: true
DeploymentType: 'zipDeploy'
TakeAppOfflineFlag: false

- stage: LoadTest
displayName: Load Test
dependsOn: Deploy
condition: succeeded()
jobs:
- job: LoadTest
displayName: Load Test
pool:
vmImage: ubuntu-latest
steps:
- task: AzureLoadTest@1
inputs:
azureSubscription: $(serviceConnection)
loadTestConfigFile: 'SampleApp.yaml'
resourceGroup: $(loadTestResourceGroup)
loadTestResource: $(loadTestResource)

- publish: $(System.DefaultWorkingDirectory)/loadTest
artifact: results
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"enableSecretsFeature": false,
"secretHeaderValue": "1797669089"
}
}
2 changes: 1 addition & 1 deletion windows-webapp-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@
"type": "string"
}
}
}
}

0 comments on commit 2326a2a

Please sign in to comment.