Skip to content

fix: Add ACR public access management functions to build scripts#283

Open
Shubhangi-Microsoft wants to merge 6 commits into
mainfrom
psl-hb-acr-build
Open

fix: Add ACR public access management functions to build scripts#283
Shubhangi-Microsoft wants to merge 6 commits into
mainfrom
psl-hb-acr-build

Conversation

@Shubhangi-Microsoft

Copy link
Copy Markdown
Contributor

This pull request adds robust handling for Azure Container Registry (ACR) public network access in both the PowerShell (build_push_images.ps1) and Bash (build_push_images.sh) image build/deploy scripts. The scripts now ensure that ACR public access is enabled before building and pushing images, and then restore the original ACR network settings afterward, even if an error occurs. This helps prevent accidental exposure or misconfiguration of ACR network rules during CI/CD operations.

Key changes:

ACR Public Access Management:

  • Added Enable-AcrPublicAccess and Restore-AcrAccess functions to build_push_images.ps1 to manage ACR public network access and network rule settings before and after the script runs. The script records the original state and restores it at the end.
  • Added enable_acr_public_access, restore_acr_access, and cleanup_on_exit functions to build_push_images.sh to provide equivalent functionality in Bash, including trapping script exit to ensure restoration. [1] [2]

Script Execution Flow:

  • Updated both scripts to call the ACR public access enabling function before image build/push, and to restore the original settings afterward (using try/finally in PowerShell, and a trap in Bash). This ensures cleanup even if the script fails or is interrupted. [1] [2] [3]## Purpose
  • ...

Does this introduce a breaking change?

  • Yes
  • No

How to Test

  • Get the code
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install
  • Test the code

What to Check

Verify that the following are valid

  • ...

Other Information

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds “open ACR temporarily, then restore” behavior to the image build/push scripts so az acr build and subsequent deployments can succeed even when ACR public access/network rules are restrictive, while ensuring the original ACR configuration is restored on completion or failure.

Changes:

  • Added ACR public network access enable/restore helpers to the Bash and PowerShell build/push scripts.
  • Wrapped build/deploy flow with guaranteed cleanup (try/finally in PowerShell, trap in Bash).
  • Recorded original ACR publicNetworkAccess and networkRuleSet.defaultAction to restore after the run.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
infra/scripts/build_push_images.sh Adds Bash functions + trap-based cleanup to temporarily enable ACR public access and restore prior settings.
infra/scripts/build_push_images.ps1 Adds PowerShell functions + try/finally cleanup to temporarily enable ACR public access and restore prior settings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread infra/scripts/build_push_images.ps1 Outdated
Comment on lines +202 to +204
$script:OriginalAcrPublicAccess = (az acr show --name $Name --query "publicNetworkAccess" -o tsv 2>$null).Trim()
$script:OriginalAcrDefaultAction = (az acr show --name $Name --query "networkRuleSet.defaultAction" -o tsv 2>$null).Trim()
Write-Host " Current: publicNetworkAccess=$($script:OriginalAcrPublicAccess) defaultAction=$($script:OriginalAcrDefaultAction)" -ForegroundColor DarkGray

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread infra/scripts/build_push_images.sh Outdated
Comment on lines +204 to +206
ORIGINAL_ACR_PUBLIC_ACCESS="$(az acr show --name "$name" --query "publicNetworkAccess" -o tsv 2>/dev/null || true)"
ORIGINAL_ACR_DEFAULT_ACTION="$(az acr show --name "$name" --query "networkRuleSet.defaultAction" -o tsv 2>/dev/null || true)"
echo " Current: publicNetworkAccess=${ORIGINAL_ACR_PUBLIC_ACCESS} defaultAction=${ORIGINAL_ACR_DEFAULT_ACTION}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread infra/scripts/build_push_images.sh Outdated
Comment on lines +302 to +305
trap cleanup_on_exit EXIT INT TERM

enable_acr_public_access "$ACR_NAME"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants