diff --git a/hubploy/__main__.py b/hubploy/__main__.py index 7155cc8..3c8d796 100644 --- a/hubploy/__main__.py +++ b/hubploy/__main__.py @@ -91,7 +91,6 @@ def main(): help=textwrap.dedent("""\ Override one or more images and tags to deploy. Format is:\n : : ...\n \n - IMPORTANT: The order of images passed in must match the order in which they appear in hubploy.yaml and separated by spaces without quotes. """) @@ -104,14 +103,13 @@ def main(): elif args.debug: logger.setLevel(logging.DEBUG) logger.info(args) - logger.info(args.image_overrides) - + # Attempt to load the config early, fail if it doesn't exist or is invalid try: config = hubploy.config.get_config( args.deployment, - args.debug, - args.verbose + debug=False, + verbose=False ) except hubploy.config.DeploymentNotFoundError as e: print(e, file=sys.stderr) diff --git a/hubploy/config.py b/hubploy/config.py index 31585d1..08261a8 100644 --- a/hubploy/config.py +++ b/hubploy/config.py @@ -50,7 +50,7 @@ def __init__(self, self.helm_substitution_path = helm_substitution_path self.image_spec = f"{self.name}:{self.tag}" -def get_config(deployment, debug, verbose): +def get_config(deployment, debug=False, verbose=False): """ Returns hubploy.yaml configuration as a Python dictionary if it exists for a given deployment, and also augments it with a set of RemoteImage objects @@ -72,9 +72,9 @@ def get_config(deployment, debug, verbose): config = yaml.load(f) if "images" in config: - # A single image is being deployed images_config = config["images"] + # A single image is being deployed if "image_name" in images_config: if ":" in images_config["image_name"]: image_name, tag = images_config["image_name"].split(":") @@ -106,6 +106,7 @@ def get_config(deployment, debug, verbose): "name": image_name, "tag": tag, }) + config["images"]["images"] = [RemoteImage(**i) for i in images] # Backwards compatibility checker for images block diff --git a/hubploy/helm.py b/hubploy/helm.py index 9a3fc59..c0059b7 100644 --- a/hubploy/helm.py +++ b/hubploy/helm.py @@ -204,12 +204,15 @@ def deploy( if config.get("images"): if image_overrides is not None: + print(f"Image overrides found: {image_overrides}") num_images = len(config["images"]["images"]) num_overrides = len(image_overrides) + if num_images != num_overrides: raise ValueError( f"Number of image overrides ({num_overrides}) must match " + - f"number of images in hubploy.yaml ({num_images})" + f"number of images found in " + + f"deployments/{deployment}/hubploy.yaml ({num_images})" ) for override in image_overrides: if ":" not in override: @@ -217,24 +220,25 @@ def deploy( f"Image override must be in the format " + f":. Got {override}" ) + count = 0 for image in config["images"]["images"]: - logger.info( - f"Using image {image.name}:{image.tag} for " + - f"{image.helm_substitution_path}" - ) # We can support other charts that wrap z2jh by allowing various # config paths where we set image tags and names. # We default to one sublevel, but we can do multiple levels. if image_overrides is not None: override = image_overrides[count] - image_name, tag = override.split(":") - image.name = image_name - image.tag = tag - logger.info( - f"Overriding image {image.helm_substitution_path} to " + - f"{image.name}:{image.tag}" + override_image, override_tag = override.split(":") + print( + f"Overriding image {image.name}:{image.tag} to " + + f"{override_image}:{override_tag}" ) + image.name = override_image + image.tag = override_tag + logger.info( + f"Using image {image.name}:{image.tag} for " + + f"{image.helm_substitution_path}" + ) helm_config_overrides_string.append( f"{image.helm_substitution_path}.tag={image.tag}" ) @@ -242,7 +246,6 @@ def deploy( f"{image.helm_substitution_path}.name={image.name}" ) count+=1 - print(helm_config_overrides_string) with ExitStack() as stack: decrypted_secret_files = [