1
0
mirror of synced 2026-01-05 21:04:17 -05:00

Append unique identifier to app name (#24971)

* append unique identifier to app name

* obfuscate the preview url and clean up staging naming

* tighter link between obfuscated app name and pr app name
This commit is contained in:
Mike Surowiec
2022-02-03 08:33:24 -06:00
committed by GitHub
parent c3faa4a88e
commit ea6896489f
4 changed files with 38 additions and 27 deletions

View File

@@ -1,7 +1,7 @@
name: Staging - Azure Deploy App Service
name: Deploy Azure Preview Environment
# **What it does**: Build and deploy staging PRs to Azure
# **Why we have it**: It's our new staging deployment mechanism, only applicable to docs-internal
# **What it does**: Build and deploy to an Azure preview environment
# **Why we have it**: It's our preview environment deploy mechanism, only applicable to docs-internal
# **Who does it impact**: All contributors.
# This whole workflow is only guaranteed to be secure in the *private
@@ -28,18 +28,19 @@ concurrency:
cancel-in-progress: true
jobs:
build-and-deploy-staging-azure:
build-and-deploy-azure-preview:
if: ${{ github.repository == 'github/docs-internal' }}
name: Build and deploy image to staging App Service
name: Build and deploy image to Azure
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: staging-pr-${{ github.event.number }}
name: preview-env-${{ github.event.number }}
url: ${{ steps.deploy.outputs.defaultHostName }}
env:
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
STAGING_RESOURCE_GROUPS: 4
PREVIEW_ENV_RESOURCE_GROUPS: 4
NONPROD_REGISTRY_USERNAME: ghdocs
APP_LOCATION: eastus
ENABLE_EARLY_ACCESS: ${{ github.repository == 'github/docs-internal' }}
# 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 }}
@@ -51,8 +52,8 @@ jobs:
REPO_NAME=${GITHUB_REPOSITORY#*\/}
echo "REPO_NAME=${REPO_NAME}" >> $GITHUB_ENV
echo "DEPLOYMENT_NAME=${REPO_NAME}-pr-${GITHUB_EVENT_NUMBER}" >> $GITHUB_ENV
echo "RESOURCE_GROUP=preview-env-${REPO_NAME}-$((${GITHUB_EVENT_NUMBER} % ${STAGING_RESOURCE_GROUPS}))" >> $GITHUB_ENV
echo "APP_NAME=gh${REPO_NAME}-staging-${GITHUB_EVENT_NUMBER}" >> $GITHUB_ENV
echo "RESOURCE_GROUP=preview-env-${REPO_NAME}-$((${GITHUB_EVENT_NUMBER} % ${PREVIEW_ENV_RESOURCE_GROUPS}))" >> $GITHUB_ENV
echo "APP_NAME=${REPO_NAME}-preview-${GITHUB_EVENT_NUMBER}" >> $GITHUB_ENV
- name: 'Az CLI login'
uses: azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf
@@ -152,10 +153,10 @@ jobs:
with:
resourceGroupName: ${{ env.RESOURCE_GROUP }}
subscriptionId: ${{ secrets.NONPROD_SUBSCRIPTION_ID }}
template: ./staging-azure-deploy-template.json
template: ./azure-preview-env-template.json
deploymentName: ${{ env.DEPLOYMENT_NAME }}
parameters: appName="${{ env.APP_NAME }}"
location="East US"
location="${{ env.APP_LOCATION }}"
linuxFxVersion="DOCKER|${{ env.DOCKER_IMAGE }}"
dockerRegistryUrl="https://${{ secrets.NONPROD_REGISTRY_SERVER }}"
dockerRegistryUsername="${{ env.NONPROD_REGISTRY_USERNAME }}"

View File

@@ -1,7 +1,7 @@
name: Staging - Undeploy Azure PR
name: Destroy Azure Preview Env
# **What it does**: To undeploy PRs from Azure staging environment, i.e. destroy the App and associated resources.
# **Why we have it**: To save money spent on deployments for closed PRs.
# **What it does**: Destroys resources associated with a PRs Azure preview environment
# **Why we have it**: Closed PRs don't need apps
# **Who does it impact**: All contributors.
on:
@@ -11,13 +11,13 @@ on:
- locked
jobs:
undeploy:
name: Undeploy
destory-azure-preview-env:
name: Destroy
runs-on: ubuntu-latest
timeout-minutes: 5
env:
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
STAGING_RESOURCE_GROUPS: 4
PREVIEW_ENV_RESOURCE_GROUPS: 4
NONPROD_REGISTRY_NAME: ghdocs
IMAGE_REPO: ${{ github.repository }}/pr-${{ github.event.number }}
@@ -26,9 +26,9 @@ jobs:
id: vars
run: |
REPO_NAME=${GITHUB_REPOSITORY#*\/}
echo "RESOURCE_GROUP=preview-env-${REPO_NAME}-$((${GITHUB_EVENT_NUMBER} % ${STAGING_RESOURCE_GROUPS}))" >> $GITHUB_ENV
echo "RESOURCE_GROUP=preview-env-${REPO_NAME}-$((${GITHUB_EVENT_NUMBER} % ${PREVIEW_ENV_RESOURCE_GROUPS}))" >> $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
echo "APP_NAME=${REPO_NAME}-preview-${GITHUB_EVENT_NUMBER}" >> $GITHUB_ENV
- name: 'Az CLI login'
uses: azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf
@@ -40,11 +40,18 @@ jobs:
run: |
az deployment group cancel --name ${{ env.DEPLOYMENT_NAME }} -g ${{ env.RESOURCE_GROUP }} || true
# The full app name is obfuscated by an identifier, so we need to query to find the one for this PR
- name: 'Get full app name'
id: full-app-name
run: |
FULL_APP_NAME=$(az webapp list -g ${{ env.RESOURCE_GROUP }} --query "[?tags.DocsAppName == '${{ env.APP_NAME }}'})].name | [0]")
echo "::set-output name=result::${FULL_APP_NAME}"
# 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 ${{ env.APP_NAME }} -g ${{ env.RESOURCE_GROUP }}
az webapp delete -n ${{ steps.full-app-name.result }} -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
@@ -56,4 +63,4 @@ jobs:
- uses: strumwolf/delete-deployment-environment@45c821e46baa405e25410700fe2e9643929706a0
with:
token: ${{ secrets.DOCUBOT_REPO_PAT }}
environment: staging-pr-${{ github.event.number }}
environment: preview-env-${{ github.event.number }}

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", "!.github/workflows/staging-undeploy-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/azure-preview-env-deploy.yml", "!.github/workflows/azure-preview-env-destroy.yml"]'