From 0306064ec6b692fcd311c7346905cd6936c6dffe Mon Sep 17 00:00:00 2001 From: Marco Donadoni Date: Tue, 24 Oct 2023 12:11:19 +0200 Subject: [PATCH] release-docker: add registry option --- reana/reana_dev/release.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/reana/reana_dev/release.py b/reana/reana_dev/release.py index ca95762a..9d89a4f3 100644 --- a/reana/reana_dev/release.py +++ b/reana/reana_dev/release.py @@ -84,9 +84,12 @@ def release_commands(): ) @click.option("--user", "-u", default="reanahub", help="DockerHub user name [reanahub]") @click.option("--image-name", help="Should the component have a custom image name?") +@click.option( + "--registry", "-r", default="docker.io", help="Registry to use in the image tag" +) @release_commands.command(name="release-docker") @click.pass_context -def release_docker(ctx, component, user, image_name): # noqa: D301 +def release_docker(ctx, component, user, image_name, registry): # noqa: D301 """Release a component on Docker Hub. \b @@ -108,18 +111,32 @@ def release_docker(ctx, component, user, image_name): # noqa: D301 :type component: str """ components = select_components(component) + + if image_name and len(components) > 1: + click.secho("Cannot use custom image name with multiple components.", fg="red") + sys.exit(1) + cannot_release_on_dockerhub = [] for component_ in components: if not is_component_dockerised(component_): cannot_release_on_dockerhub.append(component_) is_component_releasable(component_, exit_code=True, display=True) - full_image_name = f"{user}/{image_name or component_}" + # source_image_name is the name used by docker-build + source_image_name = f"docker.io/{user}/{component_}" + target_image_name = f"{registry}/{user}/{image_name or component_}" docker_tag = get_docker_tag(component_) run_command( - f"docker tag {full_image_name}:latest {full_image_name}:{docker_tag}", + f"docker tag {source_image_name}:latest {target_image_name}:{docker_tag}", component_, ) - ctx.invoke(docker_push, component=[component_], tag=docker_tag, user=user) + ctx.invoke( + docker_push, + component=[component_], + registry=registry, + user=user, + image_name=image_name, + tag=docker_tag, + ) if cannot_release_on_dockerhub: click.secho(