Skip to content

Commit 591debf

Browse files
Merge pull request #649 from chaudhariniraj/psl-add-acr
chore: Update acr script to handle WAF deployment
2 parents 5614b5f + 88918f8 commit 591debf

3 files changed

Lines changed: 126 additions & 3 deletions

File tree

infra/modules/container-registry.bicep

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ param location string
1010
@description('Optional. SKU for the Azure Container Registry.')
1111
param acrSku string = 'Basic'
1212

13-
@description('Optional. Public network access setting for the Azure Container Registry.')
14-
param publicNetworkAccess string = 'Enabled'
15-
1613
@description('Optional. Zone redundancy setting for the Azure Container Registry.')
1714
param zoneRedundancy string = 'Disabled'
1815

@@ -41,6 +38,9 @@ param backendSubnetResourceId string = ''
4138
@description('Optional. Private DNS zone resource ID for Container Registry.')
4239
param privateDnsZoneResourceId string = ''
4340

41+
@description('Optional. Public network access setting for the Azure Container Registry.')
42+
param publicNetworkAccess string = enablePrivateNetworking ? 'Disabled' : 'Enabled'
43+
4444
module avmContainerRegistry 'br/public:avm/res/container-registry/registry:0.12.1' = {
4545
name: acrName
4646
params: {

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+
$acrDefaultAction = 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)