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

Azure pipelines 👍 #961

Merged
merged 5 commits into from
Dec 7, 2023
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
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'