@@ -241,6 +241,74 @@ def test_fn(container: testcontainers.core.container.DockerContainer):
241241
242242 self ._run_test (image = image , test_fn = test_fn )
243243
244+ # There are two ways how the image is being updated
245+ # 1. A change to the image is being done (e.g. package update, Dockerfile update etc.). This is what this test does.
246+ # In this case, we need to check the size of the build image that contains these updates. We're checking the compressed image size.
247+ # 2. A change is done to the params.env file or runtimes images definitions, where we update manifest references to a new image.
248+ # Check for this scenario is being done in 'ci/[check-params-env.sh|check-runtime-images.sh]'.
249+ size_treshold : int = 100 # in MBs
250+ percent_treshold : int = 10
251+
252+ def test_image_size_change (self , image : str ):
253+ """Checks the image size didn't change extensively based on the size and percent defined tresholds."""
254+
255+ # Map of image label names with expected size in MBs.
256+ expected_image_name_size_map = {
257+ "odh-notebook-code-server-ubi9-python-3.11" : 2820 ,
258+ "odh-notebook-cuda-jupyter-tensorflow-ubi9-python-3.11" : 14813 ,
259+ "odh-notebook-jupyter-cuda-minimal-ubi9-python-3.11" : 8920 ,
260+ "odh-notebook-jupyter-cuda-pytorch-ubi9-python-3.11" : 15540 ,
261+ "odh-notebook-jupyter-datascience-ubi9-python-3.11" : 3068 ,
262+ "odh-notebook-jupyter-minimal-ubi9-python-3.11" : 1676 ,
263+ "odh-notebook-jupyter-rocm-minimal-ubi9-python-3.11" : 28675 ,
264+ "odh-notebook-jupyter-rocm-pytorch-ubi9-python-3.11" : 34321 ,
265+ "odh-notebook-jupyter-rocm-tensorflow-ubi9-python-3.11" : 32166 ,
266+ "odh-notebook-jupyter-trustyai-ubi9-python-3.11" : 8785 ,
267+ "odh-notebook-rstudio-server-c9s-python-3.11" : 3480 ,
268+ "odh-notebook-rstudio-server-cuda-c9s-python-3.11" : 12250 ,
269+ "odh-notebook-runtime-datascience-ubi9-python-3.11" : 2750 ,
270+ "odh-notebook-runtime-minimal-ubi9-python-3.11" : 1561 ,
271+ "odh-notebook-runtime-pytorch-ubi9-python-3.11" : 15234 ,
272+ "odh-notebook-cuda-runtime-tensorflow-ubi9-python-3.11" : 14488 ,
273+ "odh-notebook-runtime-rocm-pytorch-ubi9-python-3.11" : 34009 ,
274+ "odh-notebook-rocm-runtime-tensorflow-ubi9-python-3.11" : 31834 ,
275+ }
276+
277+ import docker
278+
279+ client = testcontainers .core .container .DockerClient ()
280+ try :
281+ image_metadata = client .client .images .get (image )
282+ except docker .errors .ImageNotFound :
283+ image_metadata = client .client .images .pull (image )
284+ assert isinstance (image_metadata , docker .models .images .Image )
285+
286+ actual_img_size = image_metadata .attrs ["Size" ]
287+ actual_img_size = round (actual_img_size / 1024 / 1024 )
288+ logging .info (f"The size of the image is { actual_img_size } MBs." )
289+ logging .debug (f"The image metadata: { image_metadata } " )
290+
291+ img_label_name = image_metadata .labels ["name" ]
292+ if img_label_name in expected_image_name_size_map :
293+ expected_img_size = expected_image_name_size_map [img_label_name ]
294+ logging .debug (f"Expected size of the '{ img_label_name } ' image is { expected_img_size } MBs." )
295+ else :
296+ pytest .fail (
297+ f"Image name label '{ img_label_name } ' is not in the expected image size map { expected_image_name_size_map } "
298+ )
299+
300+ # Check the size change constraints now
301+ # 1. Percentual size change
302+ abs_percent_change = abs (actual_img_size / expected_img_size * 100 - 100 )
303+ assert abs_percent_change < self .percent_treshold , (
304+ f"Image size of '{ img_label_name } ' changed by { abs_percent_change } % (expected: { expected_img_size } MB; actual: { actual_img_size } MB; treshold: { self .percent_treshold } %)."
305+ )
306+ # 2. Absolute size change
307+ abs_size_difference = abs (actual_img_size - expected_img_size )
308+ assert abs_size_difference < self .size_treshold , (
309+ f"Image size of '{ img_label_name } ' changed by { abs_size_difference } MB (expected: { expected_img_size } MB; actual: { actual_img_size } MB; treshold: { self .size_treshold } MB)."
310+ )
311+
244312
245313def encode_python_function_execution_command_interpreter (
246314 python : str , function : Callable [..., Any ], * args : list [Any ]
0 commit comments