Skip to content

Commit

Permalink
feat(RHTAPBUGS-946): support multiple tags in create_pyxis_image
Browse files Browse the repository at this point in the history
The tag cli argument was renamed to tags and now it supports
multiple tags using a single string with tags separated
by space.

Signed-off-by: Martin Malina <[email protected]>
  • Loading branch information
mmalina committed Nov 3, 2023
1 parent dc1e824 commit 9f2b671
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
32 changes: 16 additions & 16 deletions pyxis/create_container_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def setup_argparser() -> Any: # pragma: no cover
)
parser.add_argument("--certified", help="Is the ContainerImage certified?", required=True)
parser.add_argument(
"--tag",
help="The ContainerImage tag name to upload",
"--tags",
help="Tags to include in the ContainerImage object. It can be a single tag "
"or multiple tags separated by space",
required=True,
)
parser.add_argument(
Expand Down Expand Up @@ -176,19 +177,26 @@ def create_container_image(args, parsed_data: Dict[str, Any]):
del parsed_data["name"]

upload_url = urljoin(args.pyxis_url, "v1/images")

tags = args.tags.split()
if args.is_latest == "true":
tags.append("latest")
pyxis_tags = [
{
"added_date": date_now,
"name": tag,
}
for tag in tags
]

container_image_payload = {
"repositories": [
{
"published": False,
"registry": image_registry,
"repository": image_repo,
"push_date": date_now,
"tags": [
{
"added_date": date_now,
"name": args.tag,
},
],
"tags": pyxis_tags,
}
],
"certified": json.loads(args.certified.lower()),
Expand All @@ -197,14 +205,6 @@ def create_container_image(args, parsed_data: Dict[str, Any]):
"parsed_data": parsed_data,
}

if args.is_latest == "true":
container_image_payload["repositories"][0]["tags"].append(
{
"added_date": date_now,
"name": "latest",
}
)

digest_field = get_digest_field(args.media_type)
container_image_payload["repositories"][0][digest_field] = docker_image_digest

Expand Down
24 changes: 16 additions & 8 deletions pyxis/test_create_container_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_create_container_image(mock_datetime, mock_post, mock_get_digest_field:

args = MagicMock()
args.pyxis_url = mock_pyxis_url
args.tag = "some_version"
args.tags = "some_version"
args.certified = "false"
args.rh_push = "false"
mock_get_digest_field.return_value = "digest_field"
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_create_container_image_latest(

args = MagicMock()
args.pyxis_url = mock_pyxis_url
args.tag = "some_version"
args.tags = "some_version"
args.certified = "false"
args.is_latest = "true"
args.rh_push = "false"
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_create_container_image_latest(
@patch("create_container_image.get_digest_field")
@patch("create_container_image.pyxis.post")
@patch("create_container_image.datetime")
def test_create_container_image_rh_push(
def test_create_container_image_rh_push_multiple_tags(
mock_datetime, mock_post, mock_get_digest_field: MagicMock
):
# Mock an _id in the response for logger check
Expand All @@ -189,7 +189,7 @@ def test_create_container_image_rh_push(

args = MagicMock()
args.pyxis_url = mock_pyxis_url
args.tag = "some_version"
args.tags = "tagprefix tagprefix-timestamp"
args.certified = "false"
args.rh_push = "true"
mock_get_digest_field.return_value = "digest_field"
Expand Down Expand Up @@ -217,8 +217,12 @@ def test_create_container_image_rh_push(
"tags": [
{
"added_date": "1970-10-10T10:10:10.000000+00:00",
"name": "some_version",
}
"name": "tagprefix",
},
{
"added_date": "1970-10-10T10:10:10.000000+00:00",
"name": "tagprefix-timestamp",
},
],
"digest_field": "some_digest",
},
Expand All @@ -230,8 +234,12 @@ def test_create_container_image_rh_push(
"tags": [
{
"added_date": "1970-10-10T10:10:10.000000+00:00",
"name": "some_version",
}
"name": "tagprefix",
},
{
"added_date": "1970-10-10T10:10:10.000000+00:00",
"name": "tagprefix-timestamp",
},
],
"digest_field": "some_digest",
},
Expand Down

0 comments on commit 9f2b671

Please sign in to comment.