diff --git a/.gitignore b/.gitignore index 663b20c..934dda8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ dist/ build/ __pycache__/ +pyproject.toml +uv.lock diff --git a/src/github_actions/common/__init__.py b/src/github_actions/common/__init__.py index dd33709..87da7e4 100644 --- a/src/github_actions/common/__init__.py +++ b/src/github_actions/common/__init__.py @@ -1,6 +1,6 @@ # github_actions/common/__init__.py -from .actions.init_project import GETTenant, ProjectInitializer, RMKConfigInitCommand +from .actions.init_project import GETTenant, ProjectInitializer, RMKConfigInitCommand, GetRootDomain from .credentials.cluster_provider_credentials import ( AWSConfig, AzureConfig, ClusterProviders, Credentials, EnvironmentConfig, GCPConfig ) @@ -17,6 +17,7 @@ from .utils.cmd import BaseCommand, CMDInterface from .utils.github_environment_variables import GitHubContext from .utils.install_rmk import RMKInstaller +from .utils.install_kodjin_cli import KodjinCLIInstaller __all__ = [ @@ -45,4 +46,6 @@ "RMKInstaller", "S3BucketManager", "SlackNotifier", + "KodjinCLIInstaller", + "GetRootDomain", ] diff --git a/src/github_actions/common/actions/init_project.py b/src/github_actions/common/actions/init_project.py index 8dcda32..7e2f6ec 100644 --- a/src/github_actions/common/actions/init_project.py +++ b/src/github_actions/common/actions/init_project.py @@ -47,11 +47,24 @@ def execute(self) -> str: return self.run() def run(self) -> str: - output = self.run_command(f"rmk --log-format=json config view", True) + output = self.run_command("rmk --log-format=json config view", True) rmk_config = json.loads(output) return rmk_config["config"]["Tenant"] +class GetRootDomain(BaseCommand, CMDInterface): + def __init__(self, environment: str): + super().__init__(environment) + + def execute(self) -> str: + return self.run() + + def run(self) -> str: + output = self.run_command("rmk --log-format=json config view", True) + rmk_config = json.loads(output) + return rmk_config["config"]["RootDomain"] + + class ProjectInitializer: GIT_CONFIG = { "name": "github-actions", diff --git a/src/github_actions/common/utils/install_kodjin_cli.py b/src/github_actions/common/utils/install_kodjin_cli.py new file mode 100644 index 0000000..dba5ac0 --- /dev/null +++ b/src/github_actions/common/utils/install_kodjin_cli.py @@ -0,0 +1,40 @@ +import subprocess +import requests + +from argparse import Namespace +from packaging import version + + +class KodjinCLIInstaller: + def __init__(self, args: Namespace): + self.version = args.kodjin_cli_version + self.url = args.kodjin_cli_download_url + self.verify_kodjin_cli_version() + self.install_kodjin_cli() + + def verify_kodjin_cli_version(self): + print("Verifying Kodjin CLI installation version...") + if self.version != "latest": + if version.parse(self.version) <= version.parse("v0.1.11"): + raise Exception( + f"version {self.version} of Kodjin CLI is not correct, " + + "the version for Kodjin CLI must be at least v0.1.11 or greater" + ) + + def install_kodjin_cli(self): + print("Installing Kodjin CLI.") + try: + response = requests.get(self.url) + response.raise_for_status() + except requests.RequestException as err: + raise Exception(f"downloading Kodjin CLI installer file:\n{err}") + + try: + subprocess.run( + ["bash", "-s", "--", self.version], + check=True, + text=True, + input=response.text, + ) + except subprocess.CalledProcessError as err: + raise Exception(f"installing Kodjin CLI:\n{err}")