Skip to content

Instantly share code, notes, and snippets.

@jyotsnaravikumar
Last active August 11, 2022 03:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jyotsnaravikumar/c9b8d3dd123c98273729ecc89c01fb7c to your computer and use it in GitHub Desktop.
Save jyotsnaravikumar/c9b8d3dd123c98273729ecc89c01fb7c to your computer and use it in GitHub Desktop.
Programmatically Purge Frontdoor CDN
## Programmatically Purging Azure Frontdoor CDN With AzDevops
1. Create a Azure Service Connection by creating a service principal so that devops process has access to perform pruging operation on frontdoor resource
1. Create a App Registration -> as spn-devops-dev
2. Goto Certificates and Secrets -> Add secret , note the ApplicationId and Secret
3. Goto Frontdoor instance -> open Access Control (IAM) -> Add Role Assignment -> Role as "Contributor" -> Assign Access To-> "user, groups or service principal" -> Select -> search for service principal spn-devops-dev -> Select
4. Note the Azure Service Connection name - as mymap-dev-service-connection
2. Add environment variables for Azure FrontDoor, ResourceGroup and Service Connection
3. Add a purging step which depends on the successly deploy. This ensure the cdn cache is refreshed with newer contents from the build after every build.
```yaml
trigger:
branches:
include:
- develop
pool: mymap-agent-pool-01
variables:
- group: viz-variables-develop
schedules:
- cron: "0 0 * * *"
displayName: Daily midnight build - develop
branches:
include:
- develop
always: true
stages:
- stage: package_build
jobs:
- template: azure-pipelines/templates/build-template.yml
parameters:
map_subscription_key: $(NEXT_PUBLIC_AZURE_MAP_SUBSCRIPTION_KEY)
appinsights_instrumentation_key: $(NEXT_PUBLIC_APPINSIGHTS_INSTRUMENTATIONKEY)
build_id: $(Build.BuildId)
- stage: deploy
dependsOn: package_build
jobs:
- template: azure-pipelines/templates/deploy-template.yml
parameters:
app_name: "mymap-dev"
azure_service_connection: 'mymap-dev - Azure-PublishProfile'
- stage: purge
dependsOn: deploy
jobs:
- template: azure-pipelines/templates/purge-template.yml
parameters:
front_door: $(AZURE_FRONTDOOR)
resource_group: $(AZURE_RESOURCE_GROUP)
azure_service_connection: 'mymap-dev-service-connection'
```
purge-template.yml
```yaml
jobs:
- job: purge
pool:
vmImage: ubuntu-16.04
steps:
- task: AzureCLI@2
inputs:
azureSubscription: ${{ parameters.azure_service_connection }}
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az extension add --name front-door
az network front-door purge-endpoint --resource-group ${{ parameters.resource_group}} --name ${{ parameters.front_door}} --content-paths "/"
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment