Skip to content

Commit f0a8b0f

Browse files
Address review comments
1. Use `docker run skopeo inspect` to get digest of manifest list of a container image instead of docker inspect 2. Write unit test
1 parent a59ec39 commit f0a8b0f

File tree

4 files changed

+486
-63
lines changed

4 files changed

+486
-63
lines changed

scripts/release/build/image_build_process.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ def build_image(self, tags: list[str],
2525
# check_if_image_exists could easily be used to get the digest of manfiest list but
2626
# the python package that we use somehow doesn't return the digest of manifest list
2727
# even though the respective docker CLI returns the digest. That's why we had to introduce
28-
# this function.
28+
# this function.
2929
def get_manfiest_list_digest(self, image: str) -> Optional[str]: pass
3030

31-
def pull_image(self, image: str): pass
32-
3331

3432
DEFAULT_BUILDER_NAME = "multiarch" # Default buildx builder name
3533

@@ -117,22 +115,27 @@ def check_if_image_exists(self, image_tag: str) -> bool:
117115
else:
118116
return True
119117

120-
def pull_image(self, image):
121-
docker_cmd = python_on_whales.docker
122-
try:
123-
docker_cmd.image.pull(image, quiet=True)
124-
except Exception as e:
125-
raise Exception("Failed pulling image.") from e
126-
127118
def get_manfiest_list_digest(self, image) -> Optional[str]:
128-
self.pull_image(image)
119+
SKOPEO_IMAGE = "quay.io/skopeo/stable"
129120

130-
docker_cmd = python_on_whales.docker
121+
skopeo_inspect_command = ["inspect", f"docker://{image}", "--format", "{{.Digest}}"]
122+
docker_run_skopeo = ["docker", "run", "--rm", SKOPEO_IMAGE]
123+
docker_run_skopeo.extend(skopeo_inspect_command)
124+
131125
try:
132-
manifest = docker_cmd.image.inspect(image)
133-
return manifest.id
126+
result = subprocess.run(
127+
docker_run_skopeo,
128+
capture_output=True,
129+
text=True,
130+
check=True
131+
)
132+
return result.stdout.strip()
133+
except subprocess.CalledProcessError as e:
134+
raise Exception(f"Failed to run skopeo inspect using 'docker run' for image {image}. Error: {e.stderr.strip()}") from e
135+
except FileNotFoundError:
136+
raise Exception("docker is not installed on the system.")
134137
except Exception as e:
135-
raise Exception("Failed inspecting the image to get manifest list digest") from e
138+
raise e
136139

137140
def build_image(self, tags: list[str],
138141
dockerfile: str,
@@ -196,9 +199,6 @@ def get_manfiest_list_digest(self, image) -> Optional[str]:
196199
logger.warning(f"PodmanImageBuilder does not support getting digest for manifest list, returning empty digest.")
197200
return ""
198201

199-
def pull_image(self, image: str):
200-
logger.warning("PodmanImageBuilder does not support pulling image right now.")
201-
202202
def build_image(self, tags: list[str],
203203
dockerfile: str,
204204
path: str,

scripts/release/release_info.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@
4444
def create_release_info_json(operator_version: str) -> str:
4545
build_info = load_build_info(scenario=BuildScenario.RELEASE)
4646

47-
release_info_json = convert_to_release_info_json(build_info, operator_version)
47+
release_json_path = os.path.join(os.getcwd(), "release.json")
48+
49+
release_info_json = convert_to_release_info_json(build_info, release_json_path, operator_version)
4850

4951
return json.dumps(release_info_json, indent=2)
5052

5153

52-
def convert_to_release_info_json(build_info: BuildInfo, operator_version: str) -> dict:
53-
release_json_data = os.path.join(os.getcwd(), "release.json")
54-
with open(release_json_data, "r") as fd:
54+
def convert_to_release_info_json(build_info: BuildInfo, release_json_path: str, operator_version: str) -> dict:
55+
with open(release_json_path, "r") as fd:
5556
release_data = json.load(fd)
5657

5758
release_info_output = {
Lines changed: 126 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,150 @@
11
import json
2+
import os
3+
from scripts.release.build.build_scenario import BuildScenario
4+
from scripts.release.release_info import convert_to_release_info_json
5+
from scripts.release.build.build_info import load_build_info
26

3-
from scripts.release.release_info import DUMMY_VERSION, create_release_info_json
4-
7+
OPERATOR_VERSION = "1.6.0"
58

69
def test_create_release_info_json():
710
expected_json = {
811
"images": {
912
"operator": {
10-
"repositories": ["quay.io/mongodb/mongodb-kubernetes"],
11-
"platforms": ["linux/arm64", "linux/amd64", "linux/s390x", "linux/ppc64le"],
12-
"version": DUMMY_VERSION,
13+
"repoURL": "quay.io/mongodb/mongodb-kubernetes",
14+
"platforms": [
15+
"linux/arm64",
16+
"linux/amd64",
17+
"linux/s390x",
18+
"linux/ppc64le"
19+
],
20+
"tag": "1.6.0",
21+
"digest": "sha256:317a7f2d40807629b1df78e7ef81790bcaeb09993d88b476ec3a33ee44cbb78d"
1322
},
1423
"init-database": {
15-
"repositories": ["quay.io/mongodb/mongodb-kubernetes-init-database"],
16-
"platforms": ["linux/arm64", "linux/amd64", "linux/s390x", "linux/ppc64le"],
17-
"version": DUMMY_VERSION,
24+
"repoURL": "quay.io/mongodb/mongodb-kubernetes-init-database",
25+
"platforms": [
26+
"linux/arm64",
27+
"linux/amd64",
28+
"linux/s390x",
29+
"linux/ppc64le"
30+
],
31+
"tag": "1.6.0",
32+
"digest": "sha256:ce10a711a6e6a31d20deecbe0ef15b5f82c2ca24d495fb832f5199ac327ee8ec"
1833
},
1934
"init-appdb": {
20-
"repositories": ["quay.io/mongodb/mongodb-kubernetes-init-appdb"],
21-
"platforms": ["linux/arm64", "linux/amd64", "linux/s390x", "linux/ppc64le"],
22-
"version": DUMMY_VERSION,
35+
"repoURL": "quay.io/mongodb/mongodb-kubernetes-init-appdb",
36+
"platforms": [
37+
"linux/arm64",
38+
"linux/amd64",
39+
"linux/s390x",
40+
"linux/ppc64le"
41+
],
42+
"tag": "1.6.0",
43+
"digest": "sha256:b0b66397056636052756157628c164d480f540d919a615d057192d553a7e892c"
2344
},
2445
"init-ops-manager": {
25-
"repositories": ["quay.io/mongodb/mongodb-kubernetes-init-ops-manager"],
26-
"platforms": ["linux/amd64"],
27-
"version": DUMMY_VERSION,
46+
"repoURL": "quay.io/mongodb/mongodb-kubernetes-init-ops-manager",
47+
"platforms": [
48+
"linux/amd64"
49+
],
50+
"tag": "1.6.0",
51+
"digest": "sha256:62825c8edcd45e26586cce5b4062d6930847db0c58a76c168312be8cdc934707"
2852
},
2953
"database": {
30-
"repositories": ["quay.io/mongodb/mongodb-kubernetes-database"],
31-
"platforms": ["linux/arm64", "linux/amd64", "linux/s390x", "linux/ppc64le"],
32-
"version": DUMMY_VERSION,
54+
"repoURL": "quay.io/mongodb/mongodb-kubernetes-database",
55+
"platforms": [
56+
"linux/arm64",
57+
"linux/amd64",
58+
"linux/s390x",
59+
"linux/ppc64le"
60+
],
61+
"tag": "1.6.0",
62+
"digest": "sha256:382248da5bdd90c8dbb0a1571b5f9ec90c10931c7e0974f4563a522963304b58"
3363
},
34-
"readiness-probe": {
35-
"repositories": ["quay.io/mongodb/mongodb-kubernetes-readinessprobe"],
36-
"platforms": ["linux/arm64", "linux/amd64"],
37-
"version": DUMMY_VERSION,
64+
"ops-manager": {
65+
"repoURL": "quay.io/mongodb/mongodb-enterprise-ops-manager-ubi",
66+
"platforms": [
67+
"linux/amd64"
68+
],
69+
"tag": "8.0.16",
70+
"digest": "sha256:ca4aad523f14d68fccb60256f9ce8909c66ebb5b321ee15e5abf9ac5738947f9"
71+
},
72+
"agent": {
73+
"repoURL": "quay.io/mongodb/mongodb-agent",
74+
"platforms": [
75+
"linux/arm64",
76+
"linux/amd64",
77+
"linux/s390x",
78+
"linux/ppc64le"
79+
],
80+
"tag": "108.0.16.8895-1",
81+
"digest": "sha256:6c5df0e0ec425731da1f82c7229304c1a01353d3aa81e02423f84904d96a7688"
3882
},
3983
"upgrade-hook": {
40-
"repositories": ["quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook"],
41-
"platforms": ["linux/arm64", "linux/amd64"],
42-
"version": DUMMY_VERSION,
84+
"repoURL": "quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook",
85+
"platforms": [
86+
"linux/arm64",
87+
"linux/amd64"
88+
],
89+
"tag": "1.0.10",
90+
"digest": "sha256:f321ec1d25d6e98805b8be9321f2a926d702835136dde88d5fffe917c2df1d0a"
4391
},
44-
},
45-
"binaries": {
46-
"kubectl-mongodb": {
92+
"readiness-probe": {
93+
"repoURL": "quay.io/mongodb/mongodb-kubernetes-readinessprobe",
4794
"platforms": [
48-
"darwin/amd64",
49-
"darwin/arm64",
50-
"linux/amd64",
5195
"linux/arm64",
52-
"linux/s390x",
53-
"linux/ppc64le",
96+
"linux/amd64"
5497
],
55-
"version": DUMMY_VERSION,
98+
"tag": "1.0.23",
99+
"digest": "sha256:436fc328f3887f022a4760afd03da1a7091d285baf3d627a17d80bbdaab0ee47"
100+
},
101+
"search": {
102+
"repoURL": "quay.io/mongodb/mongodb-search",
103+
"platforms": [
104+
"linux/arm64",
105+
"linux/amd64"
106+
],
107+
"tag": "0.55.0",
108+
"digest": "sha256:c1e636119aa206ff98cefed37ee4b488d75c6a5e6025dcb71f44275a8f3f546a"
109+
},
110+
"mongodb-enterprise-server": {
111+
"repoURL": "quay.io/mongodb/mongodb-enterprise-server",
112+
"platforms": [
113+
"linux/arm64",
114+
"linux/amd64"
115+
],
116+
"tag": "8.0.0-ubi9",
117+
"digest": "sha256:7a93a0276531ff9be4c90bb8fe8d104e0a9e930c29792aafe03cc6a76a9fa89c"
56118
}
57119
},
58-
"helm-charts": {
59-
"mongodb-kubernetes": {"registry": "quay.io", "repository": "mongodb/helm-charts", "version": DUMMY_VERSION}
60-
},
61-
}
62-
expected_release_info_json = json.dumps(expected_json, indent=2)
63-
release_info_json = create_release_info_json()
64-
65-
assert release_info_json == expected_release_info_json
120+
"latestOpsManagerAgentMapping": [
121+
{
122+
"6": {
123+
"opsManagerVersion": "6.0.27",
124+
"agentVersion": "12.0.35.7911-1"
125+
}
126+
},
127+
{
128+
"7": {
129+
"opsManagerVersion": "7.0.19",
130+
"agentVersion": "107.0.19.8805-1"
131+
}
132+
},
133+
{
134+
"8": {
135+
"opsManagerVersion": "8.0.16",
136+
"agentVersion": "108.0.16.8895-1"
137+
}
138+
}
139+
]
140+
}
141+
142+
build_info = load_build_info(scenario=BuildScenario.RELEASE)
143+
144+
# release_test.json is just a copy of our original release.json file and it's created so that we can easily
145+
# test release_info.py. If we directly used release.json, we will have to change the expected output `expected_json`
146+
# because content of release.json changes after every MCK/OM/Agent release.
147+
test_release_json_path = os.path.join(os.getcwd(), "scripts/release/tests/testdata/release_test.json")
148+
release_info_asset = convert_to_release_info_json(build_info, test_release_json_path, OPERATOR_VERSION)
149+
150+
assert release_info_asset == expected_json

0 commit comments

Comments
 (0)