Skip to content

Commit 92d2fe6

Browse files
Run precommit
1 parent 33e6c58 commit 92d2fe6

File tree

2 files changed

+26
-42
lines changed

2 files changed

+26
-42
lines changed

scripts/publish_helm_chart.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def run_command(command: list[str]):
2020
except subprocess.CalledProcessError as e:
2121
raise RuntimeError(f"Command {' '.join(command)} failed. Stderr: {e.stderr.strip()}") from e
2222
except FileNotFoundError:
23-
raise FileNotFoundError(f"Error: {command[0]} command not found. Ensure {command[0]} is installed and in your PATH.")
23+
raise FileNotFoundError(
24+
f"Error: {command[0]} command not found. Ensure {command[0]} is installed and in your PATH."
25+
)
2426

2527

2628
# update_chart_and_get_metadata updates the helm chart's Chart.yaml and sets the version
@@ -71,7 +73,6 @@ def get_oci_registry(chart_info: HelmChartInfo) -> str:
7173
if not repo:
7274
raise ValueError("Error: reposiotry doesn't seem to be set in HelmChartInfo.")
7375

74-
7576
oci_registry = f"oci://{registry}/{repo}"
7677
logger.info(f"Determined OCI Registry: {oci_registry}")
7778
return oci_registry
Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,72 @@
11
import os
2-
import sys
32
import subprocess
3+
import sys
4+
45
from lib.base_logger import logger
56
from scripts.release.build.build_info import load_build_info
67

8+
79
def helm_registry_login(helm_registry: str, region: str):
810
logger.info(f"Attempting to log into ECR registry: {helm_registry}, using helm registry login.")
9-
10-
aws_command = [
11-
"aws",
12-
"ecr",
13-
"get-login-password",
14-
"--region",
15-
region
16-
]
17-
11+
12+
aws_command = ["aws", "ecr", "get-login-password", "--region", region]
13+
1814
# as we can see the password is being provided by stdin, that would mean we will have to
1915
# pipe the aws_command (it figures out the password) into helm_command.
20-
helm_command = [
21-
"helm",
22-
"registry",
23-
"login",
24-
"--username",
25-
"AWS",
26-
"--password-stdin",
27-
helm_registry
28-
]
16+
helm_command = ["helm", "registry", "login", "--username", "AWS", "--password-stdin", helm_registry]
2917

3018
try:
3119
logger.info("Starting AWS ECR credential retrieval.")
3220
aws_proc = subprocess.Popen(
33-
aws_command,
34-
stdout=subprocess.PIPE,
35-
stderr=subprocess.PIPE,
36-
text=True # Treat input/output as text strings
21+
aws_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True # Treat input/output as text strings
3722
)
38-
23+
3924
logger.info("Starting Helm registry login.")
4025
helm_proc = subprocess.Popen(
41-
helm_command,
42-
stdin=aws_proc.stdout,
43-
stdout=subprocess.PIPE,
44-
stderr=subprocess.PIPE,
45-
text=True
26+
helm_command, stdin=aws_proc.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
4627
)
47-
48-
# Close the stdout stream of aws_proc in the parent process
28+
29+
# Close the stdout stream of aws_proc in the parent process
4930
# to prevent resource leakage (only needed if you plan to do more processing)
50-
aws_proc.stdout.close()
31+
aws_proc.stdout.close()
5132

5233
# Wait for the Helm command (helm_proc) to finish and capture its output
5334
helm_stdout, helm_stderr = helm_proc.communicate()
54-
35+
5536
# Wait for the AWS process to finish as well
56-
aws_proc.wait()
37+
aws_proc.wait()
5738

5839
if aws_proc.returncode != 0:
59-
_, aws_stderr = aws_proc.communicate()
40+
_, aws_stderr = aws_proc.communicate()
6041
raise Exception(f"aws command to get password failed. Error: {aws_stderr}")
61-
42+
6243
if helm_proc.returncode == 0:
6344
logger.info("Login to helm registry was successful.")
6445
logger.info(helm_stdout.strip())
6546
else:
66-
raise Exception(f"Login to helm registry failed, Exit code: {helm_proc.returncode}, Error: {helm_stderr.strip()}")
47+
raise Exception(
48+
f"Login to helm registry failed, Exit code: {helm_proc.returncode}, Error: {helm_stderr.strip()}"
49+
)
6750

6851
except FileNotFoundError as e:
6952
# This catches errors if 'aws' or 'helm' are not in the PATH
7053
raise Exception(f"Command not found. Please ensure '{e.filename}' is installed and in your system's PATH.")
7154
except Exception as e:
7255
raise Exception(f"An unexpected error occurred: {e}.")
73-
56+
7457

7558
def main():
7659
build_scenario = os.environ.get("BUILD_SCENARIO")
7760
build_info = load_build_info(build_scenario)
7861

79-
8062
registry = build_info.helm_charts["mongodb-kubernetes"].registry
8163
region = build_info.helm_charts["mongodb-kubernetes"].region
8264
return helm_registry_login(registry, region)
8365

66+
8467
if __name__ == "__main__":
8568
try:
8669
main()
8770
except Exception as e:
8871
logger.error(f"Failed while logging in to the helm registry. Error: {e}")
89-
sys.exit(1)
72+
sys.exit(1)

0 commit comments

Comments
 (0)