Skip to content

Commit

Permalink
cli: convert docker-build tag auto to semver2
Browse files Browse the repository at this point in the history
closes #414
  • Loading branch information
audrium committed Oct 1, 2020
1 parent 2b2cb5a commit 2da1a63
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
8 changes: 4 additions & 4 deletions reana/reana_dev/docker.py
Expand Up @@ -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 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 Down
19 changes: 1 addition & 18 deletions reana/reana_dev/release.py
Expand Up @@ -26,10 +26,8 @@
get_current_component_version_from_source_files,
get_current_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_current_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_current_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)

0 comments on commit 2da1a63

Please sign in to comment.