Skip to content

Commit aff7a5b

Browse files
committed
feat(RELEASE-2056): support flatpak registries
The create_container_image.py was modified to support flatpak registries. If rh_push=true and the image pull spec is quay.io/rh-flatpaks-stage or quay.io/rh-flatpaks-prod, the resulting repository entry in Pyxis will use flatpaks.registry.redhat.io as the registry string. Signed-off-by: Martin Malina <mmalina@redhat.com> Assisted-by: Cursor
1 parent 5462606 commit aff7a5b

File tree

2 files changed

+98
-16
lines changed

2 files changed

+98
-16
lines changed

pyxis/create_container_image.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
Container Repository object to exist in Pyxis. This will typically be created as part
1919
of product onboarding to RHTAP.
2020
21+
Flatpak images use different Quay namespaces and a different Pyxis registry: they are
22+
pushed to quay.io/rh-flatpaks-prod/* or quay.io/rh-flatpaks-stage/*. For these, the
23+
registry value in Pyxis is set to flatpaks.registry.redhat.io (for both prod and stage).
24+
2125
For stage, if you want to be able to pull an image from registry.stage.redhat.io,
2226
the image is pushed to quay.io/redhat-pending, the Container Image is created
2327
in stage Pyxis, but the registry value in Pyxis is still set to registry.access.redhat.com.
@@ -125,12 +129,14 @@ def setup_argparser() -> Any: # pragma: no cover
125129
)
126130
parser.add_argument(
127131
"--rh-push",
128-
help="If set to true, a second item will be created in ContainerImage.repositories "
129-
"with the registry and repository entries converted to use Red Hat's official "
130-
"registry. E.g. a mapped repository of "
131-
"quay.io/redhat-pending/product---my-image will be converted to use "
132-
"registry registry.access.redhat.com and repository product/my-image. Also, "
133-
"the image will be marked as published.",
132+
help="If set to true, the item created in ContainerImage.repositories "
133+
"will have the registry and repository entries converted to use Red Hat's official "
134+
"registry. For standard images (quay.io/redhat-prod/*, quay.io/redhat-pending/*) "
135+
"registry is registry.access.redhat.com; for flatpaks (quay.io/rh-flatpaks-prod/*, "
136+
"quay.io/rh-flatpaks-stage/*) registry is flatpaks.registry.redhat.io. "
137+
"E.g. quay.io/redhat-pending/product----my-image becomes registry "
138+
"registry.access.redhat.com and repository product/my-image. The image will be "
139+
"marked as published.",
134140
default="false",
135141
)
136142
parser.add_argument(
@@ -340,28 +346,46 @@ def update_container_image_repositories(
340346
raise Exception("Image metadata was not successfully added to Pyxis.")
341347

342348

349+
def _rh_push_registry(image_name: str) -> str:
350+
"""Return the Pyxis registry string for rh_push when --rh-push is true.
351+
352+
For flatpak images (quay.io/rh-flatpaks-prod/* or quay.io/rh-flatpaks-stage/*)
353+
returns flatpaks.registry.redhat.io. For other Red Hat images
354+
(e.g. quay.io/redhat-prod/*, quay.io/redhat-pending/*) returns
355+
registry.access.redhat.com.
356+
"""
357+
parts = image_name.split("/")
358+
if len(parts) >= 2 and parts[1] in ("rh-flatpaks-prod", "rh-flatpaks-stage"):
359+
return "flatpaks.registry.redhat.io"
360+
return "registry.access.redhat.com"
361+
362+
343363
def construct_repository(args, tags):
364+
"""Build the repository dict for the Container Image.
365+
366+
When rh_push is true, the repository entry it adds will be for Red Hat
367+
registries: registry is either registry.access.redhat.com (for standard
368+
images like quay.io/redhat-prod/*, quay.io/redhat-pending/*) or
369+
flatpaks.registry.redhat.io (for flatpak images quay.io/rh-flatpaks-prod/*,
370+
quay.io/rh-flatpaks-stage/*). The repository path is derived via proxymap
371+
(e.g. product----image -> product/image).
372+
"""
344373
image_name = args.name
345-
image_registry = image_name.split("/")[0]
346-
image_repo = image_name.split("/", 1)[1]
347-
348374
date_now = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f+00:00")
349375

350-
# For images released to registry.redhat.io we need a special repository item
351-
# with published=true and registry and repository converted.
352-
# E.g. if the name in the oras manifest result is
353-
# "quay.io/redhat-prod/rhtas-tech-preview----cosign-rhel9",
354-
# repository will be "rhtas-tech-preview/cosign-rhel9"
355376
if args.rh_push == "true":
356-
LOGGER.info("--rh-push is true. Associating registry.access.redhat.com repository.")
377+
registry = _rh_push_registry(image_name)
378+
LOGGER.info("--rh-push is true. Associating %s repository.", registry)
357379
repo = {
358380
"published": True,
359-
"registry": "registry.access.redhat.com",
381+
"registry": registry,
360382
"repository": proxymap(image_name),
361383
"push_date": date_now,
362384
"tags": pyxis_tags(tags, date_now),
363385
}
364386
else:
387+
image_registry = image_name.split("/")[0]
388+
image_repo = image_name.split("/", 1)[1]
365389
repo = {
366390
"published": False,
367391
"registry": image_registry,

pyxis/test_create_container_image.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
create_container_image,
1414
update_container_image_repositories,
1515
construct_repository,
16+
_rh_push_registry,
1617
)
1718

1819

@@ -610,6 +611,27 @@ def test_repository_digest_values__multi_arch():
610611
}
611612

612613

614+
def test_rh_push_registry():
615+
"""Flatpak namespaces use flatpaks.registry.redhat.io;
616+
others use registry.access.redhat.com.
617+
"""
618+
assert (
619+
_rh_push_registry("quay.io/rh-flatpaks-prod/foo/bar") == "flatpaks.registry.redhat.io"
620+
)
621+
assert (
622+
_rh_push_registry("quay.io/rh-flatpaks-stage/foo/bar") == "flatpaks.registry.redhat.io"
623+
)
624+
assert (
625+
_rh_push_registry("quay.io/redhat-prod/product----image")
626+
== "registry.access.redhat.com"
627+
)
628+
assert (
629+
_rh_push_registry("quay.io/redhat-pending/product----image")
630+
== "registry.access.redhat.com"
631+
)
632+
assert _rh_push_registry("quay.io/some-org/repo") == "registry.access.redhat.com"
633+
634+
613635
@patch("create_container_image.datetime")
614636
def test_construct_repository__rh_push_true(mock_datetime):
615637
mock_datetime.now = MagicMock(return_value=datetime(1970, 10, 10, 10, 10, 10))
@@ -643,6 +665,42 @@ def test_construct_repository__rh_push_true(mock_datetime):
643665
}
644666

645667

668+
@patch("create_container_image.datetime")
669+
def test_construct_repository__rh_push_true_flatpak_prod(mock_datetime):
670+
mock_datetime.now = MagicMock(return_value=datetime(1970, 10, 10, 10, 10, 10))
671+
args = MagicMock()
672+
args.media_type = "application/vnd.oci.image.manifest.v1+json"
673+
args.architecture_digest = "sha256:abc"
674+
args.digest = "sha256:top"
675+
args.rh_push = "true"
676+
args.name = "quay.io/rh-flatpaks-prod/myapp----myflatpak"
677+
tags = ["latest"]
678+
679+
repo = construct_repository(args, tags)
680+
681+
assert repo["registry"] == "flatpaks.registry.redhat.io"
682+
assert repo["repository"] == "myapp/myflatpak"
683+
assert repo["published"] is True
684+
685+
686+
@patch("create_container_image.datetime")
687+
def test_construct_repository__rh_push_true_flatpak_stage(mock_datetime):
688+
mock_datetime.now = MagicMock(return_value=datetime(1970, 10, 10, 10, 10, 10))
689+
args = MagicMock()
690+
args.media_type = "application/vnd.oci.image.manifest.v1+json"
691+
args.architecture_digest = "sha256:def"
692+
args.digest = "sha256:top2"
693+
args.rh_push = "true"
694+
args.name = "quay.io/rh-flatpaks-stage/namespace----another-flatpak"
695+
tags = ["1.0"]
696+
697+
repo = construct_repository(args, tags)
698+
699+
assert repo["registry"] == "flatpaks.registry.redhat.io"
700+
assert repo["repository"] == "namespace/another-flatpak" # proxymap: ---- -> /
701+
assert repo["published"] is True
702+
703+
646704
@patch("create_container_image.datetime")
647705
def test_construct_repository__rh_push_false(mock_datetime):
648706
mock_datetime.now = MagicMock(return_value=datetime(1970, 10, 10, 10, 10, 10))

0 commit comments

Comments
 (0)