diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 00000000..3e64fdab --- /dev/null +++ b/.github/workflows/workflow.yml @@ -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: "" # set this to your application's name + LOAD_TEST_RESOURCE: "" + 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 diff --git a/SampleApp.yaml b/SampleApp.yaml new file mode 100644 index 00000000..90701e72 --- /dev/null +++ b/SampleApp.yaml @@ -0,0 +1,5 @@ +version: v0.1 +testName: SampleAppTest +testPlan: SampleApp.jmx +description: 'SampleApp Test Run' +engineInstances: 1 \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..0f2adb97 --- /dev/null +++ b/azure-pipelines.yml @@ -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: '' + serviceConnection: '' + azureSubscriptionId: '' + loadTestResource: '' + loadTestResourceGroup: '' + 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 diff --git a/config.json b/config.json index ef7ec377..5a9d8ecf 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,4 @@ { "enableSecretsFeature": false, "secretHeaderValue": "1797669089" -} \ No newline at end of file +} diff --git a/windows-webapp-template.json b/windows-webapp-template.json index 7916a195..0633f246 100644 --- a/windows-webapp-template.json +++ b/windows-webapp-template.json @@ -166,4 +166,4 @@ "type": "string" } } -} \ No newline at end of file +}