diff --git a/.azuredevops/build-and-push-dev.yml b/.azuredevops/build-and-push-dev.yml new file mode 100644 index 000000000..139c5d4d4 --- /dev/null +++ b/.azuredevops/build-and-push-dev.yml @@ -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 diff --git a/.azuredevops/build-and-push-prod.yml b/.azuredevops/build-and-push-prod.yml new file mode 100644 index 000000000..d9ef5145e --- /dev/null +++ b/.azuredevops/build-and-push-prod.yml @@ -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 diff --git a/.azuredevops/dynamic-branches.yml b/.azuredevops/dynamic-branches.yml new file mode 100644 index 000000000..9a27c7ef9 --- /dev/null +++ b/.azuredevops/dynamic-branches.yml @@ -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' \ No newline at end of file