diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f90cc1..7885492 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ Note: Breaking changes between versions are indicated by "💥". ## Unreleased + +- 💥[Improvement] Fail on incorrect image name argument in `images build/pull/push/printtag` commands. - [Bugfix] Remove trailing slashes in docker-compose files for [compatibility with docker-compose v2 in WSL](https://github.com/docker/compose/issues/8558). - [Improvement] `settheme` now works with preview domain. - [Feature] Allow specifying extra pip packages through config.yml. diff --git a/tutor/commands/images.py b/tutor/commands/images.py index 4a0fdd3..af08e91 100644 --- a/tutor/commands/images.py +++ b/tutor/commands/images.py @@ -108,35 +108,64 @@ def push(context: Context, image_names: List[str]) -> None: def printtag(context: Context, image_names: List[str]) -> None: config = tutor_config.load(context.root) for image in image_names: + to_print = [] for _img, tag in iter_images(config, image, BASE_IMAGE_NAMES): - print(tag) + to_print.append(tag) for _plugin, _img, tag in iter_plugin_images(config, image, "build-image"): + to_print.append(tag) + + if not to_print: + raise ImageNotFoundError(image) + + for tag in to_print: print(tag) def build_image(root: str, config: Config, image: str, *args: str) -> None: + to_build = [] + # Build base images for img, tag in iter_images(config, image, BASE_IMAGE_NAMES): - images.build(tutor_env.pathjoin(root, "build", img), tag, *args) + to_build.append((tutor_env.pathjoin(root, "build", img), tag, args)) # Build plugin images for plugin, img, tag in iter_plugin_images(config, image, "build-image"): - images.build( - tutor_env.pathjoin(root, "plugins", plugin, "build", img), tag, *args + to_build.append( + (tutor_env.pathjoin(root, "plugins", plugin, "build", img), tag, args) ) + if not to_build: + raise ImageNotFoundError(image) + + for path, tag, build_args in to_build: + images.build(path, tag, *args) + def pull_image(config: Config, image: str) -> None: + to_pull = [] for _img, tag in iter_images(config, image, all_image_names(config)): - images.pull(tag) + to_pull.append(tag) for _plugin, _img, tag in iter_plugin_images(config, image, "remote-image"): + to_pull.append(tag) + + if not to_pull: + raise ImageNotFoundError(image) + + for tag in to_pull: images.pull(tag) def push_image(config: Config, image: str) -> None: + to_push = [] for _img, tag in iter_images(config, image, BASE_IMAGE_NAMES): - images.push(tag) + to_push.append(tag) for _plugin, _img, tag in iter_plugin_images(config, image, "remote-image"): + to_push.append(tag) + + if not to_push: + raise ImageNotFoundError(image) + + for tag in to_push: images.push(tag) @@ -177,6 +206,11 @@ def vendor_image_names(config: Config) -> List[str]: return vendor_images +class ImageNotFoundError(exceptions.TutorError): + def __init__(self, image_name: str): + super().__init__("Image '{}' could not be found".format(image_name)) + + images_command.add_command(build) images_command.add_command(pull) images_command.add_command(push)