Skip to content

Commit

Permalink
[ARM] az bicep\deployment\stack: Conditionally enable invariant glo…
Browse files Browse the repository at this point in the history
…balization for Bicep running inside the Azure CLI docker image (#29897)
  • Loading branch information
anthony-c-martin authored Oct 29, 2024
1 parent 27d8f8a commit 2a770c0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions azure-linux.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ FROM $IMAGE
# jq: It's widely used for parsing JSON output in Azure CLI and has a small size. See https://github.com/Azure/azure-cli/issues/29830
RUN --mount=type=bind,target=/azure-cli.rpm,source=./docker-temp/azure-cli.rpm tdnf install ca-certificates jq /azure-cli.rpm -y && tdnf clean all && rm -rf /var/cache/tdnf

# See https://github.com/Azure/azure-cli/issues/29828 for background on this
ENV AZ_BICEP_GLOBALIZATION_INVARIANT=1

ENV AZ_INSTALLER=DOCKER
CMD bash
1 change: 1 addition & 0 deletions src/azure-cli-core/azure/cli/core/_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


_ENV_AZ_INSTALLER = 'AZ_INSTALLER'
_ENV_AZ_BICEP_GLOBALIZATION_INVARIANT = 'AZ_BICEP_GLOBALIZATION_INVARIANT'


def get_config_dir():
Expand Down
15 changes: 14 additions & 1 deletion src/azure-cli/azure/cli/command_modules/resource/_bicep.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,25 @@ def _extract_version(text):
return semver.VersionInfo.parse(semver_match.group(0)) if semver_match else None


def _get_bicep_env_vars(custom_env=None):
env_vars = (custom_env or os.environ).copy()

# See https://github.com/Azure/azure-cli/issues/29828 for background on this
from azure.cli.core._environment import _ENV_AZ_BICEP_GLOBALIZATION_INVARIANT
env_bicep_globalization_invariant = os.getenv(_ENV_AZ_BICEP_GLOBALIZATION_INVARIANT, 'False')

if env_bicep_globalization_invariant.lower() in ('true', '1'):
env_vars['DOTNET_SYSTEM_GLOBALIZATION_INVARIANT'] = '1'

return env_vars


def _run_command(bicep_installation_path, args, custom_env=None):
process = subprocess.run(
[rf"{bicep_installation_path}"] + args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=custom_env)
env=_get_bicep_env_vars(custom_env))

try:
process.check_returncode()
Expand Down

0 comments on commit 2a770c0

Please sign in to comment.