Skip to content

Commit b86fbae

Browse files
Update acr script to handle WAF deployment
1 parent 201fc45 commit b86fbae

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

infra/scripts/acr_build_push.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,45 @@ else {
8383
}
8484

8585
$IMAGE_TAG = "latest"
86+
$DeploymentType = az group show `
87+
--name $RESOURCE_GROUP `
88+
--query "tags.Type" `
89+
-o tsv
90+
if ($DeploymentType -eq "WAF") {
91+
92+
Write-Host ""
93+
Write-Host "WAF deployment detected. Temporarily relaxing ACR restrictions..."
94+
95+
$acrAllowExport = az acr update `
96+
--name $ACR_NAME `
97+
--resource-group $RESOURCE_GROUP `
98+
--allow-exports true
99+
100+
if ($LASTEXITCODE -ne 0) {
101+
throw "Failed to enable ACR exports."
102+
}
103+
104+
$acrPublicNetwork = az acr update `
105+
--name $ACR_NAME `
106+
--resource-group $RESOURCE_GROUP `
107+
--public-network-enabled true
108+
109+
if ($LASTEXITCODE -ne 0) {
110+
throw "Failed to enable ACR public network access."
111+
}
112+
113+
$acrDefaultAction = az acr update `
114+
--name $ACR_NAME `
115+
--resource-group $RESOURCE_GROUP `
116+
--default-action Allow
117+
118+
if ($LASTEXITCODE -ne 0) {
119+
throw "Failed to set ACR default action to Allow."
120+
}
121+
122+
Write-Host "ACR restrictions temporarily relaxed."
123+
}
124+
86125

87126
# Get the script directory and navigate to repo root
88127
$ScriptDir = $PSScriptRoot
@@ -95,6 +134,7 @@ Write-Host " Resource Group: $RESOURCE_GROUP"
95134
Write-Host " Image Tag: $IMAGE_TAG"
96135
Write-Host ""
97136

137+
try {
98138
# =============================================================================
99139
# Step 1: Build and push images to ACR using az acr build
100140
# =============================================================================
@@ -214,3 +254,29 @@ Write-Host ""
214254
Write-Host "============================================================"
215255
Write-Host "ACR Build and Push - Completed Successfully!"
216256
Write-Host "============================================================"
257+
}
258+
finally {
259+
260+
if ($DeploymentType -eq "WAF") {
261+
262+
Write-Host ""
263+
Write-Host "Restoring WAF ACR configuration..."
264+
265+
$acrDefailtAction = az acr update `
266+
--name $ACR_NAME `
267+
--resource-group $RESOURCE_GROUP `
268+
--default-action Deny
269+
270+
$acrPublicNetwork = az acr update `
271+
--name $ACR_NAME `
272+
--resource-group $RESOURCE_GROUP `
273+
--public-network-enabled false
274+
275+
$acrAllowExport = az acr update `
276+
--name $ACR_NAME `
277+
--resource-group $RESOURCE_GROUP `
278+
--allow-exports false
279+
280+
Write-Host "ACR configuration restored."
281+
}
282+
}

infra/scripts/acr_build_push.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,34 @@ else
7676
fi
7777

7878
IMAGE_TAG="latest"
79+
DEPLOYMENT_TYPE=$(az group show \
80+
--name "$RESOURCE_GROUP" \
81+
--query "tags.Type" \
82+
-o tsv)
83+
84+
if [ "$DEPLOYMENT_TYPE" = "WAF" ]; then
85+
86+
echo ""
87+
echo "WAF deployment detected. Temporarily relaxing ACR restrictions..."
88+
89+
az acr update \
90+
--name "$ACR_NAME" \
91+
--resource-group "$RESOURCE_GROUP" \
92+
--allow-exports true
93+
94+
az acr update \
95+
--name "$ACR_NAME" \
96+
--resource-group "$RESOURCE_GROUP" \
97+
--public-network-enabled true
98+
99+
az acr update \
100+
--name "$ACR_NAME" \
101+
--resource-group "$RESOURCE_GROUP" \
102+
--default-action Allow
103+
104+
echo "ACR restrictions temporarily relaxed."
105+
106+
fi
79107

80108
# Get the directory where this script is located
81109
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -89,6 +117,35 @@ echo " Resource Group: $RESOURCE_GROUP"
89117
echo " Image Tag: $IMAGE_TAG"
90118
echo ""
91119

120+
cleanup() {
121+
122+
if [ "$DEPLOYMENT_TYPE" = "WAF" ]; then
123+
124+
echo ""
125+
echo "Restoring WAF ACR configuration..."
126+
127+
az acr update \
128+
--name "$ACR_NAME" \
129+
--resource-group "$RESOURCE_GROUP" \
130+
--default-action Deny
131+
132+
az acr update \
133+
--name "$ACR_NAME" \
134+
--resource-group "$RESOURCE_GROUP" \
135+
--public-network-enabled false
136+
137+
az acr update \
138+
--name "$ACR_NAME" \
139+
--resource-group "$RESOURCE_GROUP" \
140+
--allow-exports false
141+
142+
echo "ACR configuration restored."
143+
144+
fi
145+
}
146+
147+
trap cleanup EXIT
148+
92149
# =============================================================================
93150
# Step 1: Build and push images to ACR using az acr build
94151
# =============================================================================

0 commit comments

Comments
 (0)