1
0
mirror of synced 2026-01-07 09:01:31 -05:00

Improve Azure staging deployment concurrency (#24625)

* Improve azure staging deployment concurrency

* update workflow-lint to ignore undeploy
This commit is contained in:
Mike Surowiec
2022-01-25 12:41:42 -06:00
committed by GitHub
parent 8374263842
commit 837e8364bc
3 changed files with 21 additions and 5 deletions

View File

@@ -38,6 +38,7 @@ jobs:
url: ${{ steps.deploy.outputs.defaultHostName }}
env:
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
RESOURCE_GROUP: docs-nonprod
NONPROD_REGISTRY_USERNAME: ghdocs
# Image tag is unique to each workflow run so that it always triggers a new deployment
DOCKER_IMAGE: ${{ secrets.NONPROD_REGISTRY_SERVER }}/${{ github.repository }}/pr-${{ github.event.number }}:${{ github.event.pull_request.head.sha }}-${{ github.run_number }}-${{ github.run_attempt }}
@@ -48,6 +49,7 @@ jobs:
run: |
REPO_NAME=${GITHUB_REPOSITORY#*\/}
echo "REPO_NAME=${REPO_NAME}" >> $GITHUB_ENV
echo "DEPLOYMENT_NAME=${REPO_NAME}-pr-${GITHUB_EVENT_NUMBER}" >> $GITHUB_ENV
echo "APP_NAME=gh${REPO_NAME}-staging-${GITHUB_EVENT_NUMBER}" >> $GITHUB_ENV
- name: 'Az CLI login'
@@ -99,15 +101,21 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
# Succeed despite any non-zero exit code (e.g. if there is no deployment to cancel)
- name: 'Cancel any existing deployments for this PR'
run: |
az deployment group cancel --name ${{ env.DEPLOYMENT_NAME }} -g ${{ env.RESOURCE_GROUP }} || true
# Deploy ARM template is idempotent
# Note: once the resources exist the image tag must change for a new deployment to occur (the image tag includes workflow run number, run attempt, as well as sha)
- name: Run ARM deploy
id: deploy
uses: azure/arm-deploy@841b12551939c88af8f6df767c24c38a5620fd0d
with:
resourceGroupName: docs-nonprod
resourceGroupName: ${{ env.RESOURCE_GROUP }}
subscriptionId: ${{ secrets.NONPROD_SUBSCRIPTION_ID }}
template: ./staging-azure-deploy-template.json
deploymentName: ${{ env.DEPLOYMENT_NAME }}
parameters: appName="${{ env.APP_NAME }}"
location="East US"
linuxFxVersion="DOCKER|${{ env.DOCKER_IMAGE }}"

View File

@@ -17,6 +17,8 @@ jobs:
timeout-minutes: 5
env:
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
RESOURCE_GROUP: docs-nonprod
NONPROD_REGISTRY_NAME: ghdocs
IMAGE_REPO: ${{ github.repository }}/pr-${{ github.event.number }}
steps:
@@ -24,6 +26,7 @@ jobs:
id: vars
run: |
REPO_NAME=${GITHUB_REPOSITORY#*\/}
echo "DEPLOYMENT_NAME=${REPO_NAME}-pr-${GITHUB_EVENT_NUMBER}" >> $GITHUB_ENV
echo "APP_NAME=gh${REPO_NAME}-staging-${GITHUB_EVENT_NUMBER}" >> $GITHUB_ENV
- name: 'Az CLI login'
@@ -31,19 +34,24 @@ jobs:
with:
creds: ${{ secrets.NONPROD_AZURE_CREDENTIALS }}
# Succeed despite any non-zero exit code (e.g. if there is no deployment to cancel)
- name: 'Cancel any in progress deployments'
run: |
az deployment group cancel --name ${{ env.DEPLOYMENT_NAME }} -g ${{ env.RESOURCE_GROUP }} || true
# Delete web app (which will also delete the App Service plan)
# This will succeed even if the app doesn't exist / has already been deleted
- name: 'Delete App Service App (which will also delete the App Service plan)'
run: |
az webapp delete -n $APP_NAME -g docs-nonprod
az webapp delete -n ${{ env.APP_NAME }} -g ${{ env.RESOURCE_GROUP }}
# Untag all images under this PR's container registry repo - the container registry will automatically remove untagged images.
# This will fail if the IMAGE_REPO doesn't exist, but we don't care
- name: 'Untag all docker images for this PR'
run: |
az acr repository delete -n ghdocs --repository ${{ env.IMAGE_REPO }} -y || true
az acr repository delete -n ${{ env.NONPROD_REGISTRY_NAME }} --repository ${{ env.IMAGE_REPO }} -y || true
# Remove all deployments from this environment and remove the environment
# Remove all GitHub deployments from this environment and remove the environment
- uses: strumwolf/delete-deployment-environment@45c821e46baa405e25410700fe2e9643929706a0
with:
token: ${{ secrets.DOCUBOT_REPO_PAT }}

View File

@@ -30,4 +30,4 @@ jobs:
- name: Run linter
uses: cschleiden/actions-linter@caffd707beda4fc6083926a3dff48444bc7c24aa
with:
workflows: '[".github/workflows/*.yml", ".github/workflows/*.yaml", "!.github/workflows/remove-from-fr-board.yaml", "!.github/workflows/staging-deploy-pr.yml", "!.github/workflows/triage-issue-comments.yml", "!.github/workflows/staging-build-and-deploy-azure.yml"]'
workflows: '[".github/workflows/*.yml", ".github/workflows/*.yaml", "!.github/workflows/remove-from-fr-board.yaml", "!.github/workflows/staging-deploy-pr.yml", "!.github/workflows/triage-issue-comments.yml", "!.github/workflows/staging-build-and-deploy-azure.yml", "!.github/workflows/staging-undeploy-azure.yml"]'