-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5425 from dfe-analytical-services/EES-5446-preven…
…t-function-app-slot-swap-until-orchestrations-complete Ees 5446 prevent function app slot swap until orchestrations complete
- Loading branch information
Showing
21 changed files
with
470 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ parameters: | |
jobs: | ||
- deployment: DeployPublicDataProcessor | ||
displayName: Deploy Public Data Processor | ||
condition: and(succeeded(), eq(variables.deployDataProcessor, true)) | ||
dependsOn: ${{ parameters.dependsOn }} | ||
environment: ${{ parameters.environment }} | ||
strategy: | ||
|
@@ -42,9 +43,11 @@ jobs: | |
--resource-group $(resourceGroupName) \ | ||
--slot staging \ | ||
--settings \ | ||
"[email protected](VaultName=$(keyVaultName); SecretName=$(coreStorageConnectionStringSecretKey))" \ | ||
"App__MetaInsertBatchSize=1000" \ | ||
"App__EnableThemeDeletion=$(enableThemeDeletion)" \ | ||
"[email protected](VaultName=$(keyVaultName); SecretName=$(coreStorageConnectionStringSecretKey))" \ | ||
"AZURE_CLIENT_ID=$(dataProcessorFunctionAppManagedIdentityClientId)" \ | ||
"AzureWebJobs.TriggerLongRunningOrchestration.Disabled=true" \ | ||
"DataFiles__BasePath=$(dataProcessorPublicApiDataFileShareMountPath)" | ||
az webapp config connection-string set \ | ||
|
@@ -63,28 +66,6 @@ jobs: | |
--settings \ | ||
"[email protected](VaultName=$(keyVaultName); SecretName=$(dataProcessorPsqlConnectionStringSecretKey))" | ||
# TODO EES-5128 | ||
# Add Private Endpoint to Data Processor Function App into the VMSS VNet to allow | ||
# DevOps to deploy the Data Processor Function App without having to temporarily | ||
# make it publicly accessible. | ||
- task: AzureCLI@2 | ||
displayName: Temporarily enable public network access before deploy | ||
retryCountOnTaskFailure: 1 | ||
inputs: | ||
azureSubscription: ${{ parameters.serviceConnection }} | ||
scriptType: bash | ||
scriptLocation: inlineScript | ||
inlineScript: | | ||
set -e | ||
az functionapp update \ | ||
--name $(dataProcessorFunctionAppName) \ | ||
--resource-group $(resourceGroupName) \ | ||
--slot staging \ | ||
--set \ | ||
publicNetworkAccess=Enabled \ | ||
siteConfig.publicNetworkAccess=Enabled | ||
|
||
# TODO EES-5128 | ||
# Retry deploying the Function App in order to allow the staging slot the time to | ||
# fully restart after config and network settings have been updated prior to deploy. | ||
|
@@ -112,29 +93,21 @@ jobs: | |
--resource-group $(resourceGroupName) \ | ||
--slot staging | ||
# TODO EES-5128 | ||
# Add Private Endpoint to Data Processor Function App into the VMSS VNet to allow | ||
# DevOps to deploy the Data Processor Function App without having to temporarily | ||
# make it publicly accessible. | ||
- task: AzureCLI@2 | ||
displayName: Disable public network access after deploy | ||
retryCountOnTaskFailure: 1 | ||
condition: always() | ||
inputs: | ||
azureSubscription: ${{ parameters.serviceConnection }} | ||
scriptType: bash | ||
scriptLocation: inlineScript | ||
inlineScript: | | ||
set -e | ||
az functionapp update \ | ||
--name $(dataProcessorFunctionAppName) \ | ||
--resource-group $(resourceGroupName) \ | ||
--slot staging \ | ||
--set \ | ||
publicNetworkAccess=Disabled \ | ||
siteConfig.publicNetworkAccess=Disabled | ||
- template: ../tasks/wait-for-endpoint-success.yml | ||
parameters: | ||
serviceConnection: ${{ parameters.serviceConnection }} | ||
displayName: Waiting for staging slot to start successfully | ||
accessTokenScope: $(dataProcessorAppRegistrationClientId) | ||
endpoint: $(dataProcessorFunctionAppStagingUrl)/api/HealthCheck | ||
|
||
- template: ../tasks/wait-for-orchestrations-to-complete.yml | ||
parameters: | ||
serviceConnection: ${{ parameters.serviceConnection }} | ||
displayName: Waiting for active orchestrations in the production slot to complete | ||
accessTokenScope: $(dataProcessorAppRegistrationClientId) | ||
endpoint: $(dataProcessorFunctionAppUrl)/api/StatusCheck | ||
condition: eq(variables.awaitActiveOrchestrations, true) | ||
|
||
- task: AzureCLI@2 | ||
displayName: Swap slots | ||
retryCountOnTaskFailure: 1 | ||
|
@@ -149,3 +122,10 @@ jobs: | |
--resource-group $(resourceGroupName) \ | ||
--slot staging \ | ||
--target-slot production | ||
- template: ../tasks/wait-for-endpoint-success.yml | ||
parameters: | ||
serviceConnection: ${{ parameters.serviceConnection }} | ||
displayName: Checking that production slot is healthy after slot swap | ||
accessTokenScope: $(dataProcessorAppRegistrationClientId) | ||
endpoint: $(dataProcessorFunctionAppUrl)/api/HealthCheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
infrastructure/templates/public-api/ci/tasks/wait-for-endpoint-success.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
parameters: | ||
- name: serviceConnection | ||
type: string | ||
- name: displayName | ||
type: string | ||
default: Waiting for a successful response from endpoint | ||
- name: accessTokenScope | ||
type: string | ||
default: null | ||
- name: pollingDelaySeconds | ||
type: number | ||
default: 5 | ||
- name: maxAttempts | ||
type: number | ||
default: 50 | ||
- name: endpoint | ||
type: string | ||
|
||
steps: | ||
- task: AzureCLI@2 | ||
displayName: ${{ parameters.displayName }} | ||
inputs: | ||
azureSubscription: ${{ parameters.serviceConnection }} | ||
scriptType: bash | ||
scriptLocation: inlineScript | ||
inlineScript: | | ||
if [ -n "${{ parameters.accessTokenScope }}" ]; then | ||
accessToken=`az account get-access-token \ | ||
--resource ${{ parameters.accessTokenScope }} \ | ||
--query "accessToken" \ | ||
-o tsv` | ||
fi | ||
for attempt in $(seq 1 ${{ parameters.maxAttempts }}); | ||
do | ||
echo "Attempt number $attempt of ${{ parameters.maxAttempts }} - calling ${{ parameters.endpoint }} to check for successful response." | ||
if [ -n "$accessToken" ]; then | ||
httpStatusCode=`curl --write-out '%{http_code}' -H "Authorization: Bearer $accessToken" -s --output /dev/null ${{ parameters.endpoint }}` | ||
else | ||
httpStatusCode=`curl --write-out '%{http_code}' -s --output /dev/null ${{ parameters.endpoint }}` | ||
fi | ||
if (( $httpStatusCode >= 200 && $httpStatusCode <= 204 )); then | ||
echo "Received successful response with status code $httpStatusCode." | ||
exit 0 | ||
fi | ||
echo "Received response with status code $httpStatusCode. Retrying in ${{ parameters.pollingDelaySeconds }} seconds." | ||
sleep ${{ parameters.pollingDelaySeconds }} | ||
done | ||
echo "Timed out waiting for successful response." | ||
exit 1 |
Oops, something went wrong.