Skip to content

Commit

Permalink
release-docker: add platform option
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni committed Oct 31, 2023
1 parent 86e5950 commit b546898
Showing 1 changed file with 55 additions and 13 deletions.
68 changes: 55 additions & 13 deletions reana/reana_dev/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

"""`reana-dev`'s release commands."""

import json

Check warning on line 11 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L11

Added line #L11 was not covered by tests
import os
import sys
import tempfile
Expand Down Expand Up @@ -87,9 +88,14 @@ def release_commands():
@click.option(

Check warning on line 88 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L88

Added line #L88 was not covered by tests
"--registry", "-r", default="docker.io", help="Registry to use in the image tag"
)
@click.option(

Check warning on line 91 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L91

Added line #L91 was not covered by tests
"--platform",
multiple=True,
help="Platforms for multi-arch images",
)
@release_commands.command(name="release-docker")
@click.pass_context
def release_docker(ctx, component, user, image_name, registry): # noqa: D301
def release_docker(ctx, component, user, image_name, registry, platform): # noqa: D301

Check warning on line 98 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L98

Added line #L98 was not covered by tests
"""Release a component on Docker Hub.
\b
Expand All @@ -116,6 +122,13 @@ def release_docker(ctx, component, user, image_name, registry): # noqa: D301
click.secho("Cannot use custom image name with multiple components.", fg="red")
sys.exit(1)

Check warning on line 123 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L121-L123

Added lines #L121 - L123 were not covered by tests

is_multi_arch = len(platform) > 1
if is_multi_arch:

Check warning on line 126 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L125-L126

Added lines #L125 - L126 were not covered by tests
# check whether podman is installed
run_command("podman version", display=False, return_output=True)

Check warning on line 128 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L128

Added line #L128 was not covered by tests
# platforms are in the format OS/ARCH[/VARIANT], we are only interested in ARCH
expected_arch = sorted([p.split("/")[1] for p in platform])

Check warning on line 130 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L130

Added line #L130 was not covered by tests

cannot_release_on_dockerhub = []
for component_ in components:
if not is_component_dockerised(component_):
Expand All @@ -125,18 +138,47 @@ def release_docker(ctx, component, user, image_name, registry): # noqa: D301
source_image_name = f"docker.io/{user}/{component_}"
target_image_name = f"{registry}/{user}/{image_name or component_}"

Check warning on line 139 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L138-L139

Added lines #L138 - L139 were not covered by tests
docker_tag = get_docker_tag(component_)
run_command(
f"docker tag {source_image_name}:latest {target_image_name}:{docker_tag}",
component_,
)
ctx.invoke(
docker_push,
component=[component_],
registry=registry,
user=user,
image_name=image_name,
tag=docker_tag,
)

if is_multi_arch:
manifest = json.loads(

Check warning on line 143 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L142-L143

Added lines #L142 - L143 were not covered by tests
run_command(
f"podman manifest inspect {source_image_name}:latest",
component=component_,
return_output=True,
)
)
manifest_arch = sorted(

Check warning on line 150 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L150

Added line #L150 was not covered by tests
[m["platform"]["architecture"] for m in manifest["manifests"]]
)
if manifest_arch != expected_arch:
display_message(

Check warning on line 154 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L153-L154

Added lines #L153 - L154 were not covered by tests
f"Expected multi-arch image {source_image_name} with {expected_arch} variants, "
f"found {manifest_arch}.",
component=component_,
)
sys.exit(1)
run_command(

Check warning on line 160 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L159-L160

Added lines #L159 - L160 were not covered by tests
f"podman tag {source_image_name}:latest {target_image_name}:{docker_tag}",
component_,
)
run_command(

Check warning on line 164 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L164

Added line #L164 was not covered by tests
f"podman manifest push --all {target_image_name}:{docker_tag} "
f"docker://{target_image_name}:{docker_tag}",
component_,
)
else:
run_command(

Check warning on line 170 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L170

Added line #L170 was not covered by tests
f"docker tag {source_image_name}:latest {target_image_name}:{docker_tag}",
component_,
)
ctx.invoke(

Check warning on line 174 in reana/reana_dev/release.py

View check run for this annotation

Codecov / codecov/patch

reana/reana_dev/release.py#L174

Added line #L174 was not covered by tests
docker_push,
component=[component_],
registry=registry,
user=user,
image_name=image_name,
tag=docker_tag,
)

if cannot_release_on_dockerhub:
click.secho(
Expand Down

0 comments on commit b546898

Please sign in to comment.