-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines.yml
83 lines (70 loc) · 3.1 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
trigger: none
pool:
vmImage: 'ubuntu-latest'
variables:
AZURE_CONTAINER_APP_NAME: 'building33-mock-api-iac'
RESOURCE_GROUP: 'Gateway-Resources-IAC'
DOCKER_IMAGE: 'attonbomb/building33mockapi' # Replace with your Docker Hub image path
AZURE_SUBSCRIPTION: 'Gateway-Resources-IAC-MI-Conn-2'
steps:
- task: Docker@2
inputs:
command: 'login'
containerRegistry: 'attonbomb-DockerHub-SC'
# Set the Azure subscription based on the branch
- script: |
echo "Determining Azure subscription...$(Build.SourceBranchName)"
if [ "$(Build.SourceBranchName)" == "development" ]; then
echo "##vso[task.setvariable variable=AZURE_SUBSCRIPTION]Dev-Gateway-Resources-MS"
else
echo "##vso[task.setvariable variable=AZURE_SUBSCRIPTION]Gateway-Resources-IAC-MI-Conn-2"
fi
displayName: 'Set Azure Subscription to $(AZURE_SUBSCRIPTION)'
# Force a restart of the Azure Container App
- task: AzureCLI@2
inputs:
azureSubscription: $(AZURE_SUBSCRIPTION)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
set -e
set -x
echo "Restarting Azure Container App with new configuration"
echo "Updating Azure Container App. The latest image version is ======= $(DOCKER_IMAGE_VERSION)"
az containerapp list --query "[?name=='building33-mock-api-iac']" --output table
az group list --query "[?name=='Gateway-IAC-Resources']" --output table
# Validate resource group
echo "Validating resource group..."
if ! az group show --name "$(RESOURCE_GROUP)" > /dev/null 2>&1; then
echo "Error: Resource group '$(RESOURCE_GROUP)' does not exist."
exit 1
fi
# Validate container app
echo "Validating container app..."
if ! az containerapp show --name "$(AZURE_CONTAINER_APP_NAME)" --resource-group "$(RESOURCE_GROUP)" > /dev/null 2>&1; then
echo "Error: Container app '$(AZURE_CONTAINER_APP_NAME)' does not exist in resource group '$(RESOURCE_GROUP)'."
exit 1
fi
# Update the container image if applicable
az containerapp update \
--name $(AZURE_CONTAINER_APP_NAME) \
--resource-group $(RESOURCE_GROUP) \
--image $(DOCKER_IMAGE):latest \
--query "[].properties.provisioningState"
# Get the active revision
REVISION_NAME=$(az containerapp revision list \
--name $(AZURE_CONTAINER_APP_NAME) \
--resource-group $(RESOURCE_GROUP) \
--query "[?properties.active].name" -o tsv)
echo "Active Revision: $REVISION_NAME"
# Restart to update live deployment if we have an active revision
if [ -n "$REVISION_NAME" ]; then
az containerapp revision restart \
--name $(AZURE_CONTAINER_APP_NAME) \
--resource-group $(RESOURCE_GROUP) \
--revision $REVISION_NAME
else
echo "No active revision found"
exit 1
fi
echo "Building 33 Mock API Container App updated successfully for Azure Subscription $(AZURE_SUBSCRIPTION)"