Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI/CD Pipeline test #7

Merged
merged 6 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
}
}