Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: convert docker-build tag auto to semver2 #417

Merged
merged 1 commit into from Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions reana/reana_dev/docker.py
Expand Up @@ -13,7 +13,7 @@
from reana.config import DOCKER_PREFETCH_IMAGES
from reana.reana_dev.utils import (
display_message,
get_current_tag,
get_docker_tag,
is_component_dockerised,
run_command,
select_components,
Expand All @@ -32,7 +32,7 @@ def docker_commands():
default="latest",
help="Image tag to generate. Default 'latest'. "
"Use 'auto' to generate git-tag-based value such as "
"'0.5.1-3-g75ae5ce'",
"'0.7.0-alpha.3'",
)
@click.option(
"--component",
Expand Down Expand Up @@ -100,7 +100,7 @@ def docker_build(
:param exclude_components: List of components to exclude from the build.
:param user: DockerHub organisation or user name. [default=reanahub]
:param tag: Docker image tag to generate. Default 'latest'. Use 'auto' to
generate git-tag-based value such as '0.5.1-3-g75ae5ce'.
generate git-tag-based value such as '0.7.0-alpha.3'.
:param build_arg: Optional docker build argument. (e.g. DEBUG=1)
:param no_cache: Flag instructing to avoid using cache. [default=False]
:param output_component_versions: File where to write the built images
Expand All @@ -124,7 +124,7 @@ def docker_build(
if is_component_dockerised(component):
cmd = "docker build"
if tag == "auto":
component_tag = get_current_tag(component)
component_tag = get_docker_tag(component)
for arg in build_arg:
cmd += " --build-arg {0}".format(arg)
if no_cache:
Expand Down Expand Up @@ -209,7 +209,7 @@ def docker_rmi(user, tag, component): # noqa: D301
default="latest",
help="Image tag to push. Default 'latest'. "
"Use 'auto' to push git-tag-based value such as "
"'0.5.1-3-g75ae5ce'",
"'0.7.0-alpha.3'",
)
@click.option(
"--component",
Expand Down Expand Up @@ -240,7 +240,7 @@ def docker_push(user, tag, component): # noqa: D301
all REANA repositories.
:param user: DockerHub organisation or user name. [default=reanahub]
:param tag: Docker image tag to push. Default 'latest'. Use 'auto' to
push git-tag-based value such as '0.5.1-3-g75ae5ce'.
push git-tag-based value such as '0.7.0-alpha.3'.
:param tag: Docker tag to use. [default=latest]
:type component: str
:type user: str
Expand All @@ -251,7 +251,7 @@ def docker_push(user, tag, component): # noqa: D301
component_tag = tag
if is_component_dockerised(component):
if tag == "auto":
component_tag = get_current_tag(component)
component_tag = get_docker_tag(component)
cmd = "docker push {0}/{1}:{2}".format(user, component, component_tag)
run_command(cmd, component)
else:
Expand Down
21 changes: 2 additions & 19 deletions reana/reana_dev/release.py
Expand Up @@ -24,12 +24,10 @@
display_message,
fetch_latest_pypi_version,
get_current_component_version_from_source_files,
get_current_tag,
get_docker_tag,
is_component_dockerised,
parse_pep440_version,
run_command,
select_components,
translate_pep440_to_semver2,
)


Expand Down Expand Up @@ -111,23 +109,8 @@ def release_docker(ctx, component, user, image_name): # noqa: D301
if not is_component_dockerised(component_):
cannot_release_on_dockerhub.append(component_)
is_component_releasable(component_, exit_code=True, display=True)

current_tag = get_current_tag(component_)
full_image_name = f"{user}/{image_name or component_}"
docker_tag = ""

if parse_pep440_version(current_tag):
docker_tag = translate_pep440_to_semver2(current_tag)
elif semver.VersionInfo.isvalid(current_tag):
docker_tag = current_tag
else:
display_message(
f"The component's latest tag ({current_tag}) is not a "
"valid version (nor PEP440 nor semver2 compliant).",
component_,
)
sys.exit(1)

docker_tag = get_docker_tag(component_)
run_command(
f"docker tag {full_image_name}:latest {full_image_name}:{docker_tag}",
component_,
Expand Down
23 changes: 22 additions & 1 deletion reana/reana_dev/utils.py
Expand Up @@ -707,7 +707,7 @@ def bump_component_version(component, current_version, next_version=None):
)


def get_current_tag(component):
def get_git_tag(component):
"""Return the current version of a component.

:param component: standard component name
Expand All @@ -724,3 +724,24 @@ def validate_mode_option(ctx, param, value):
"Supported values are '{}'.".format("', '".join(CLUSTER_DEPLOYMENT_MODES))
)
return value


def get_docker_tag(component):
"""Return the current semver version of a component.

:param component: standard component name
:type component: str
"""
tag = get_git_tag(component)

if parse_pep440_version(tag):
return translate_pep440_to_semver2(tag)
elif semver.VersionInfo.isvalid(tag):
return tag
else:
display_message(
f"The component's latest tag ({tag}) is not a "
"valid version (nor PEP440 nor semver2 compliant).",
component,
)
sys.exit(1)