Skip to content

Commit

Permalink
Merged PR 9846: Add deployment pipeline
Browse files Browse the repository at this point in the history
Pipeline files for a UAT and production deployment, including:

- .NET Core Webapp
- Nextjs Node App
- .NET Functions App

And new pipeline environments: `NUH RedCap Monitor UAT` + `NUH RedCap Monitor Prod`, checks needed to be added on the production environment by an admin.

Also:
- Updates an incorrect typescript import
- Removes Cors Framework package.
- Removes the npm workspaces for now, as deploying with this is not easy, see: npm/rfcs#287
Hopefully can come back to implementing it with workspaces, but this is the most direct route to urgent deployment.
- Adds a `server.js` file for the app service to run the Next app as, via PM2: https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs?pivots=platform-linux#run-with-pm2

Related work items: #125090, #125102
  • Loading branch information
Andy Rae authored and Andy Rae committed Sep 14, 2023
1 parent 59c9de5 commit 794f23a
Show file tree
Hide file tree
Showing 19 changed files with 9,564 additions and 14,819 deletions.
23 changes: 23 additions & 0 deletions .azure/pipelines/build.backend-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# We only use isolated builds for PR validation

trigger: none # so no CI triggers

pool:
vmImage: ubuntu-latest

variables:
project: ./app/Monitor/Monitor.csproj
build-config: release

steps:
- task: UseDotNet@2
inputs:
packageType: sdk
version: 7.x
displayName: Setup .NET

- bash: >-
dotnet build
$(project)
-c $(build-config)
displayName: dotnet build
11 changes: 11 additions & 0 deletions .azure/pipelines/build.client-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# We only use isolated builds for PR validation

trigger: none # so no CI triggers

pool:
vmImage: ubuntu-latest

steps:
- template: templates/build-js.steps.yml
parameters:
packageName: client-app
23 changes: 23 additions & 0 deletions .azure/pipelines/build.function.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# We only use isolated builds for PR validation

trigger: none # so no CI triggers

pool:
vmImage: ubuntu-latest

variables:
project: ./app/Functions/Functions.csproj
build-config: release

steps:
- task: UseDotNet@2
inputs:
packageType: sdk
version: 7.x
displayName: Setup .NET

- bash: >-
dotnet build
$(project)
-c $(build-config)
displayName: dotnet build
48 changes: 48 additions & 0 deletions .azure/pipelines/deploy.client-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
trigger:
- main

pool:
vmImage: ubuntu-latest

variables:
# deploy
azureSubscription: Research Unmanaged NUH (R02287-1)
uatEnv: NUH RedCap Monitor UAT
prodEnv: NUH RedCap Monitor Prod

stages:
- stage: Publish_Web
jobs:
- job: Publish_WebApp
displayName: Publish Web App
steps:
# Build the client-app
- template: templates/build-js.steps.yml
parameters:
packageName: client-app

- stage: Deploy_Uat
displayName: Deploy UAT
dependsOn: Publish_Web
jobs:
- template: templates/deploy-app-service.jobs.yml
parameters:
jobName: DeployWebApp
displayName: Deploy Web App
environment: $(uatEnv)
artifact: drop
azureSubscription: $(azureSubscription)
appName: uat-monitor-frontend

- stage: Deploy_Prod
displayName: Deploy Prod
dependsOn: Publish_Web
jobs:
- template: templates/deploy-app-service.jobs.yml
parameters:
jobName: DeployWebApp
displayName: Deploy Web App
environment: $(prodEnv)
artifact: drop
azureSubscription: $(azureSubscription)
appName: prod-monitor-frontend
64 changes: 64 additions & 0 deletions .azure/pipelines/deploy.functions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
trigger:
- main

pool:
vmImage: ubuntu-latest

variables:
# build / publish
function-project: ./app/Functions/Functions.csproj
dotnet-buildConfig: release

# deploy
azureSubscription: Research Unmanaged NUH (R02287-1)
uatEnv: NUH RedCap Monitor UAT
prodEnv: NUH RedCap Monitor Prod

stages:
- stage: Publish
jobs:
- job:
displayName: Publish function app
steps:
- task: UseDotNet@2
inputs:
packageType: sdk
version: 7.x
displayName: Setup .NET

- bash: >-
dotnet publish
$(function-project)
-c $(dotnet-buildConfig)
-o $(Build.StagingDirectory)
displayName: dotnet publish
- publish: $(Build.StagingDirectory)
artifact: function
displayName: Publish function artifact

- stage: Deploy_Uat
displayName: Deploy UAT
dependsOn: Publish
jobs:
- template: templates/deploy-functions-app.jobs.yml
parameters:
jobName: DeployFunctionsApp
displayName: Deploy Functions App
environment: $(uatEnv)
artifact: function
azureServiceConnection: $(azureSubscription)
appName: uat-monitor-worker

- stage: Deploy_Prod
displayName: Deploy Prod
dependsOn: Publish
jobs:
- template: templates/deploy-functions-app.jobs.yml
parameters:
jobName: DeployFunctionsApp
displayName: Deploy Functions App
environment: $(prodEnv)
artifact: function
azureServiceConnection: $(azureSubscription)
appName: prod-monitor-worker
108 changes: 108 additions & 0 deletions .azure/pipelines/deploy.webapp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
trigger:
- main

pool:
vmImage: ubuntu-latest

variables:
# build / publish
data-project: ./app/Data/Data.csproj
webapp-project: ./app/Monitor/Monitor.csproj
dotnet-buildConfig: release

# deploy
azureSubscription: Research Unmanaged NUH (R02287-1)
azureResourceGroup: rg-prj-rum-we-R02287-1
dbServer: monitor-uat # default to uat
uatEnv: NUH RedCap Monitor UAT
prodEnv: NUH RedCap Monitor Prod

stages:
- stage: Publish
jobs:
- template: templates/publish-migrations-bundle.jobs.yml
parameters:
migrationsProject: $(data-project)
project: $(webapp-project)
buildConfig: $(dotnet-buildConfig)

- job: Publish_WebApp
displayName: Publish Web App
steps:
# Get short Git Commit Hash
- bash: |
echo "##vso[task.setvariable variable=GitHash]$(git describe --always)"
displayName: Get git commit hash
# Publish the .NET App
- task: UseDotNet@2
inputs:
packageType: sdk
version: 7.x
displayName: Setup .NET

- bash: >-
dotnet publish
$(webapp-project)
-c $(dotnet-buildConfig)
-o $(Build.StagingDirectory)
-p:GitHash=$(GitHash)
displayName: dotnet publish
- publish: $(Build.StagingDirectory)
artifact: webapp
displayName: Publish webapp artifact

- stage: Deploy_Uat
displayName: Deploy UAT
dependsOn: Publish
jobs:
# Db Migrations should depend on ALL app deployment jobs
# if those jobs are part of templates,
# get the job names from the templates or their parameters :)
- template: templates/deploy-migrations-bundle.jobs.yml
parameters:
dependsOn:
- DeployWebApp
environment: $(uatEnv)
azureSubscription: $(azureSubscription)
resourceGroup: $(azureResourceGroup)
dbServerName: $(dbServer)
keyVaultName: monitor-uat

- template: templates/deploy-app-service.jobs.yml
parameters:
jobName: DeployWebApp
displayName: Deploy Web App
environment: $(uatEnv)
artifact: webapp
azureSubscription: $(azureSubscription)
appName: uat-monitor

- stage: Deploy_Prod
displayName: Deploy Prod
dependsOn: Publish
variables:
dbServer: monitor-prod
jobs:
# Db Migrations should depend on ALL app deployment jobs
# if those jobs are part of templates,
# get the job names from the templates or their parameters :)
- template: templates/deploy-migrations-bundle.jobs.yml
parameters:
dependsOn:
- DeployWebApp
environment: $(prodEnv)
azureSubscription: $(azureSubscription)
resourceGroup: $(azureResourceGroup)
dbServerName: $(dbServer)
keyVaultName: monitor-prod

- template: templates/deploy-app-service.jobs.yml
parameters:
jobName: DeployWebApp
displayName: Deploy Web App
environment: $(prodEnv)
artifact: webapp
azureSubscription: $(azureSubscription)
appName: prod-monitor
37 changes: 37 additions & 0 deletions .azure/pipelines/templates/build-js.steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
parameters:
- name: nodeVersion
type: string
default: 18.12.x
- name: packageName
type: string
- name: buildScript
type: string
default: build

steps:
- bash: |
if [ -z "$PACKAGE_NAME" ]; then
echo "##vso[task.logissue type=error;]Missing template parameter \"packageName\""
echo "##vso[task.complete result=Failed;]"
fi
env:
PACKAGE_NAME: ${{ parameters.packageName }}
displayName: Check for required parameters
- task: NodeTool@0
inputs:
versionSpec: ${{ parameters.nodeVersion }}
displayName: Setup Node.js

- script: |
npm ci --prefix app/${{ parameters.packageName }}
displayName: npm ci
- script: npm run build
workingDirectory: app/${{ parameters.packageName }}
displayName: npm run build

- task: PublishPipelineArtifact@1
inputs:
targetPath: "app/${{ parameters.packageName }}"
artifact: "drop"
34 changes: 34 additions & 0 deletions .azure/pipelines/templates/deploy-app-service.jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
parameters:
- name: environment
type: string
- name: azureSubscription
type: string
- name: artifact
type: string
- name: appName
type: string
- name: displayName
type: string
default: Deploy App Service
- name: jobName
type: string
default: DeployAppService

jobs:
- deployment: ${{ parameters.jobName }}
displayName: ${{ parameters.displayName }}
environment: ${{ parameters.environment }}

strategy:
runOnce:
deploy:
steps:
- download: current
artifact: ${{ parameters.artifact }}
- task: AzureRmWebAppDeployment@4
displayName: Deploy Azure AppService
inputs:
azureSubscription: ${{ parameters.azureSubscription }}
appType: webAppLinux
WebAppName: ${{ parameters.appName }}
packageForLinux: $(Pipeline.Workspace)/${{ parameters.artifact }}/
Loading

0 comments on commit 794f23a

Please sign in to comment.