Skip to content

Commit adc13dc

Browse files
committed
Use environment specific registry when creating image
The create image script now uses a environment specific registry based on pipeline argument. Each environment uses a different registry while creating container image metadata. JIRA: ISV-1674
1 parent 0bafae7 commit adc13dc

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

ansible/roles/operator-pipeline/templates/openshift/pipelines/operator-release-pipeline.yml

+2
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ spec:
365365
params:
366366
- name: pipeline_image
367367
value: "$(params.pipeline_image)"
368+
- name: environment
369+
value: "$(params.env)"
368370
- name: isv_pid
369371
value: "$(tasks.get-cert-project-related-data.results.isv_pid)"
370372
- name: repository

ansible/roles/operator-pipeline/templates/openshift/tasks/create-container-image.yml

+30-5
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,47 @@ metadata:
66
spec:
77
params:
88
- name: pipeline_image
9+
description: A docker image of operator-pipeline-images for the steps to run in.
10+
911
- name: pyxis_ssl_secret_name
10-
description: Kubernetes secret name that contains the Pyxis SSL files. Valid only when internal Pyxis is used.
12+
description: |
13+
Kubernetes secret name that contains the Pyxis SSL files.
14+
Valid only when internal Pyxis is used.
15+
1116
- name: pyxis_ssl_cert_secret_key
12-
description: The key within the Kubernetes secret that contains the Pyxis SSL cert. Valid only when internal Pyxis is used.
17+
description: |
18+
The key within the Kubernetes secret that contains the Pyxis SSL cert.
19+
Valid only when internal Pyxis is used.
20+
1321
- name: pyxis_ssl_key_secret_key
14-
description: The key within the Kubernetes secret that contains the Pyxis SSL key. Valid only when internal Pyxis is used.
22+
description: |
23+
The key within the Kubernetes secret that contains the Pyxis SSL key.
24+
Valid only when internal Pyxis is used.
25+
1526
- name: pyxis_url
1627
default: https://pyxis.engineering.redhat.com
28+
1729
- name: isv_pid
1830
description: isv_pid of the certification project from Red Hat Connect
31+
1932
- name: repository
20-
description: Repository path, including namespace, assigned to certification project from Red Hat Connect
33+
description: |
34+
Repository path, including namespace, assigned to certification
35+
project from Red Hat Connect
36+
2137
- name: container_digest
2238
description: imagestream container_digest
39+
2340
- name: bundle_version
2441
description: Operator bundle version
42+
2543
- name: is_latest
2644
description: If explicitly set to "true", resulting image will be tagged as "latest"
45+
46+
- name: environment
47+
default: prod
48+
description: Environment where the pipeline runs
49+
2750
workspaces:
2851
- name: image-data
2952
description: JSON files with data about image retrieved with Skopeo and Podman
@@ -43,6 +66,8 @@ spec:
4366
value: $(params.pyxis_url)
4467
- name: ISV_PID
4568
value: $(params.isv_pid)
69+
- name: ENVIRONMENT
70+
value: $(params.environment)
4671
- name: REPOSITORY
4772
value: $(params.repository)
4873
- name: CONTAINER_DIGEST
@@ -62,9 +87,9 @@ spec:
6287
6388
create-container-image \
6489
--pyxis-url $PYXIS_URL \
90+
--environment $ENVIRONMENT \
6591
--isv-pid $ISV_PID \
6692
--repo-published "true" \
67-
--registry "registry.connect.redhat.com" \
6893
--repository $REPOSITORY \
6994
--certified "true" \
7095
--docker-image-digest $CONTAINER_DIGEST \

operator-pipeline-images/operatorcert/entrypoints/create_container_image.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Any, Dict, List
77
from urllib.parse import urljoin
88

9-
from operatorcert import pyxis
9+
from operatorcert import pyxis, utils
1010
from operatorcert.logger import setup_logger
1111

1212
LOGGER = logging.getLogger("operator-cert")
@@ -37,9 +37,10 @@ def setup_argparser() -> Any: # pragma: no cover
3737
required=True,
3838
)
3939
parser.add_argument(
40-
"--registry",
41-
help="Certification Project Registry",
42-
default="registry.connect.redhat.com",
40+
"--environment",
41+
help="Environment where a tool runs",
42+
choices=["prod", "stage", "dev", "qa"],
43+
default="dev",
4344
)
4445
parser.add_argument(
4546
"--repository",
@@ -125,12 +126,13 @@ def create_container_image(
125126
parsed_data = prepare_parsed_data(skopeo_result)
126127

127128
upload_url = urljoin(args.pyxis_url, f"v1/images")
129+
registry = utils.get_registry_for_env(args.environment)
128130
container_image_payload = {
129131
"isv_pid": args.isv_pid,
130132
"repositories": [
131133
{
132134
"published": True,
133-
"registry": args.registry,
135+
"registry": registry,
134136
"repository": args.repository,
135137
"push_date": date_now,
136138
"tags": [

operator-pipeline-images/tests/entrypoints/test_create_container_image.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_create_container_image(
5959
args = MagicMock()
6060
args.pyxis_url = "https://catalog.redhat.com/api/containers/"
6161
args.isv_pid = "some_isv_pid"
62-
args.registry = "some_registry"
62+
args.environment = "prod"
6363
args.repository = "some_repo"
6464
args.docker_image_digest = "some_digest"
6565
args.bundle_version = "some_version"
@@ -76,7 +76,7 @@ def test_create_container_image(
7676
"repositories": [
7777
{
7878
"published": True,
79-
"registry": "some_registry",
79+
"registry": "registry.connect.redhat.com",
8080
"repository": "some_repo",
8181
"push_date": "1970-10-10T10:10:10.000000+00:00",
8282
"tags": [
@@ -100,7 +100,7 @@ def test_create_container_image(
100100
@patch("operatorcert.entrypoints.create_container_image.pyxis.post")
101101
@patch("operatorcert.entrypoints.create_container_image.prepare_parsed_data")
102102
@patch("operatorcert.entrypoints.create_container_image.datetime")
103-
def test_create_container_image(
103+
def test_create_container_image_latest(
104104
mock_datetime: MagicMock, mock_prepare_parsed: MagicMock, mock_post: MagicMock
105105
):
106106
# Arrange
@@ -113,7 +113,7 @@ def test_create_container_image(
113113
args = MagicMock()
114114
args.pyxis_url = "https://catalog.redhat.com/api/containers/"
115115
args.isv_pid = "some_isv_pid"
116-
args.registry = "some_registry"
116+
args.environment = "prod"
117117
args.repository = "some_repo"
118118
args.docker_image_digest = "some_digest"
119119
args.bundle_version = "some_version"
@@ -131,7 +131,7 @@ def test_create_container_image(
131131
"repositories": [
132132
{
133133
"published": True,
134-
"registry": "some_registry",
134+
"registry": "registry.connect.redhat.com",
135135
"repository": "some_repo",
136136
"push_date": "1970-10-10T10:10:10.000000+00:00",
137137
"tags": [

0 commit comments

Comments
 (0)