Skip to content

Commit

Permalink
Merge pull request #961 from DTS-STN/azure-pipelines
Browse files Browse the repository at this point in the history
Azure pipelines 👍
  • Loading branch information
andr0272 authored Dec 7, 2023
2 parents 4c4d014 + f7d268a commit 120950e
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .azuredevops/build-and-push-dev.yml
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
49 changes: 49 additions & 0 deletions .azuredevops/build-and-push-prod.yml
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
98 changes: 98 additions & 0 deletions .azuredevops/dynamic-branches.yml
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'

0 comments on commit 120950e

Please sign in to comment.