generated from DTS-STN/next-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #961 from DTS-STN/azure-pipelines
Azure pipelines 👍
- Loading branch information
Showing
3 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
trigger: | ||
- main | ||
|
||
pr: develop | ||
|
||
variables: | ||
azureContainerRegistry.repository: 'eligibilityestimator' | ||
azureContainerRegistry.name: 'DTSShared-December/2023' | ||
azureContainerRegistry.domain: 'dtsshared.azurecr.io' | ||
tag: 'ADO-$(Build.BuildId)' | ||
System.Debug: false | ||
|
||
stages: | ||
- stage: Build | ||
displayName: Build and Push to ACR | ||
jobs: | ||
- job: Build | ||
displayName: Build and Push Container | ||
steps: | ||
- task: Docker@2 | ||
inputs: | ||
containerRegistry: '$(azureContainerRegistry.name)' | ||
repository: '$(azureContainerRegistry.repository)' | ||
command: 'login' | ||
- script: "docker pull $(azureContainerRegistry.domain)/$(azureContainerRegistry.repository):latest" | ||
displayName: Pull latest for layer caching | ||
continueOnError: true | ||
- task: Docker@2 | ||
inputs: | ||
containerRegistry: '$(azureContainerRegistry.name)' | ||
repository: '$(azureContainerRegistry.repository)' | ||
command: 'build' | ||
Dockerfile: './Dockerfile' | ||
tags: | | ||
$(tag) | ||
latest | ||
release-candidate | ||
arguments: | | ||
--pull | ||
--cache-from $(azureContainerRegistry.domain)/$(azureContainerRegistry.repository):latest | ||
- task: Docker@2 | ||
inputs: | ||
containerRegistry: '$(azureContainerRegistry.name)' | ||
repository: '$(azureContainerRegistry.repository)' | ||
command: 'push' | ||
tags: | | ||
$(tag) | ||
latest | ||
release-candidate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
trigger: | ||
- main | ||
|
||
pr: none | ||
|
||
variables: | ||
azureContainerRegistry.repository: 'eligibilityestimator' | ||
azureContainerRegistry.name: 'DTSShared-December/2023' | ||
azureContainerRegistry.domain: 'dtsshared.azurecr.io' | ||
tag: 'ADO-$(Build.BuildId)' | ||
|
||
stages: | ||
- stage: Build | ||
displayName: Build and Push to ACR | ||
jobs: | ||
- job: Build | ||
displayName: Build and Push Container | ||
steps: | ||
- task: Docker@2 | ||
inputs: | ||
containerRegistry: '$(azureContainerRegistry.name)' | ||
repository: '$(azureContainerRegistry.repository)' | ||
command: 'login' | ||
- script: "docker pull $(azureContainerRegistry.domain)/$(azureContainerRegistry.repository):latest" | ||
displayName: Pull latest for layer caching | ||
continueOnError: true | ||
- task: Docker@2 | ||
inputs: | ||
containerRegistry: '$(azureContainerRegistry.name)' | ||
repository: '$(azureContainerRegistry.repository)' | ||
command: 'build' | ||
Dockerfile: './Dockerfile' | ||
tags: | | ||
$(tag) | ||
latest | ||
release-candidate | ||
arguments: | | ||
--pull | ||
--cache-from $(azureContainerRegistry.domain)/$(azureContainerRegistry.repository):latest | ||
- task: Docker@2 | ||
inputs: | ||
containerRegistry: '$(azureContainerRegistry.name)' | ||
repository: '$(azureContainerRegistry.repository)' | ||
command: 'push' | ||
tags: | | ||
$(tag) | ||
latest | ||
release-candidate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
trigger: | ||
- none | ||
|
||
pr: develop | ||
|
||
variables: | ||
azure.servicePrincipal: '' | ||
webapp.name: '' | ||
webapp.resourceGroup: '' | ||
webapp.slotName: null | ||
azureContainerRegistry.name: '' | ||
azureContainerRegistry.repository: '' | ||
azureContainerRegistry.domain: '' | ||
azureContainerRegistry.tag: '' | ||
System.Debug: false | ||
|
||
steps: | ||
- task: Docker@2 | ||
inputs: | ||
containerRegistry: '$(azureContainerRegistry.name)' | ||
repository: '$(azureContainerRegistry.repository)' | ||
command: 'login' | ||
- script: "docker pull $(azureContainerRegistry.domain)/$(azureContainerRegistry.repository):latest" | ||
displayName: Pull latest for layer caching | ||
continueOnError: true | ||
|
||
- task: Docker@2 | ||
displayName: "Build image" | ||
inputs: | ||
containerRegistry: '$(azureContainerRegistry.name)' | ||
repository: '$(azureContainerRegistry.repository)' | ||
command: 'build' | ||
Dockerfile: '**/Dockerfile' | ||
tags: | | ||
$(azureContainerRegistry.tag) | ||
latest | ||
arguments: | | ||
--cache-from $(azureContainerRegistry.domain)/$(azureContainerRegistry.repository):latest | ||
- task: Docker@2 | ||
displayName: "Push image" | ||
inputs: | ||
containerRegistry: '$(azureContainerRegistry.name)' | ||
repository: '$(azureContainerRegistry.repository)' | ||
command: 'push' | ||
tags: | | ||
$(azureContainerRegistry.tag) | ||
latest | ||
- task: PowerShell@2 | ||
displayName: 'Decide which AppService slot to put this preview in' | ||
inputs: | ||
targetType: 'inline' | ||
script: | | ||
[int] $slotNumber = $(System.PullRequest.PullRequestId) % 4 | ||
Write-Host "Generated slot number:" | ||
Write-Host "$slotNumber" | ||
Write-Host "From PRID" | ||
Write-Host "$(System.PullRequest.PullRequestId)" | ||
Write-Host "##vso[task.setvariable variable=webapp.slotName]$slotNumber" | ||
- task: AzureCLI@2 | ||
displayName: 'Create new slot in App Service' | ||
inputs: | ||
azureSubscription: $(azure.servicePrincipal) | ||
scriptType: 'bash' | ||
scriptLocation: 'inlineScript' | ||
inlineScript: | | ||
az webapp deployment slot create \ | ||
--name $(webapp.name) \ | ||
--resource-group $(webapp.resourceGroup) \ | ||
--slot pr-preview-$(webapp.slotName) \ | ||
--configuration-source $(webapp.name) | ||
az webapp identity assign \ | ||
-g $(webapp.resourceGroup) \ | ||
-n $(webapp.name) \ | ||
--slot pr-preview-$(webapp.slotName) \ | ||
--identities /subscriptions/400c5730-25f5-4ee6-a933-8b289b9ccb0d/resourcegroups/rg-dts-id-shared/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id-SCLabs-Shared | ||
- task: AzureCLI@2 | ||
displayName: 'Deploy pr image to new slot' | ||
inputs: | ||
azureSubscription: $(azure.servicePrincipal) | ||
scriptType: 'bash' | ||
scriptLocation: 'inlineScript' | ||
inlineScript: | | ||
az webapp config container set \ | ||
--docker-custom-image-name $(azureContainerRegistry.domain)/$(azureContainerRegistry.repository):$(azureContainerRegistry.tag) \ | ||
--name $(webapp.name) \ | ||
--slot pr-preview-$(webapp.slotName) \ | ||
--resource-group $(webapp.resourceGroup) | ||
- task: GitHubComment@0 | ||
displayName: "Post a comment with a link to the new PR preview" | ||
inputs: | ||
gitHubConnection: 'Adam''sGitHub-9/15/2023' | ||
repositoryName: '$(Build.Repository.Name)' | ||
comment: 'Check out a preview of your pull request here: https://$(webapp.name)-pr-preview-$(webapp.slotName).azurewebsites.net' |