|
| 1 | +import os |
| 2 | +import re |
| 3 | +import subprocess |
| 4 | + |
| 5 | +subscription_id = "0b894477-1614-4c8d-8a9b-a697a24596b8" |
| 6 | +resource_group = "AzureFunctionsPythonWorkerCILinuxDevOps" |
| 7 | + |
| 8 | + |
| 9 | +def deploy_bicep_files(): |
| 10 | + """ |
| 11 | + Deploy selected Bicep files compatible with the specified Python version to the given Azure resource group, |
| 12 | + with user-provided parameters for each template. |
| 13 | +
|
| 14 | + :param resource_group: The Azure resource group to deploy to. |
| 15 | + :param python_version: The Python version to filter Bicep files. |
| 16 | + """ |
| 17 | + # Get the current working directory |
| 18 | + directory = os.getcwd() |
| 19 | + |
| 20 | + python_version = input("Enter the Python version (e.g., 3.8): ") |
| 21 | + |
| 22 | + # Regex pattern to match files compatible with the specified Python version |
| 23 | + pattern = ".*\\.bicep$" |
| 24 | + |
| 25 | + # List all Bicep files in the directory compatible with the specified Python version |
| 26 | + all_bicep_files = [f for f in os.listdir(directory) if re.search(pattern, f)] |
| 27 | + |
| 28 | + if not all_bicep_files: |
| 29 | + print(f"No Bicep files found") |
| 30 | + return |
| 31 | + |
| 32 | + # Display the list of files to the user |
| 33 | + print("Available Bicep Templates:") |
| 34 | + for idx, file in enumerate(all_bicep_files, 1): |
| 35 | + print(f"{idx}. {file}") |
| 36 | + |
| 37 | + # Ask user to select files to deploy |
| 38 | + selected = input("Enter the numbers of the templates to deploy (comma separated), or type 'all' to deploy all: ") |
| 39 | + if selected.lower() == 'all': |
| 40 | + bicep_files_to_deploy = all_bicep_files |
| 41 | + else: |
| 42 | + selected_indices = [int(i) - 1 for i in selected.split(',') if i.isdigit()] |
| 43 | + bicep_files_to_deploy = [all_bicep_files[i] for i in selected_indices if 0 <= i < len(all_bicep_files)] |
| 44 | + |
| 45 | + # Deploy the selected Bicep files |
| 46 | + for bicep_file in bicep_files_to_deploy: |
| 47 | + file_path = os.path.join(directory, bicep_file) |
| 48 | + |
| 49 | + params_string = f"--parameters python_version={python_version.replace('.', '')}" |
| 50 | + |
| 51 | + # Deploy the Bicep file |
| 52 | + print(f"Deploying {bicep_file}...") |
| 53 | + deploy_command = (f"az deployment group create --subscription {subscription_id} " |
| 54 | + f"--resource-group {resource_group} --template-file {file_path} {params_string}") |
| 55 | + subprocess.run(deploy_command, shell=True) |
| 56 | + |
| 57 | + |
| 58 | +deploy_bicep_files() |
0 commit comments