@@ -189,6 +189,67 @@ def test_pip_install_cowsay_runs(self, image: str):
189189 finally :
190190 docker_utils .NotebookContainer (container ).stop (timeout = 0 )
191191
192+ # There are two ways how the image is being updated
193+ # 1. A change to the image is being done (e.g. package update, Dockerfile update etc.). This is what this test does.
194+ # In this case, we need to check the size of the build image that contains these updates. We're checking the compressed image size.
195+ # 2. A change is done to the params.env file or runtimes images definitions, where we update manifest references to a new image.
196+ # Check for this scenario is being done in 'ci/[check-params-env.sh|check-runtime-images.sh]'.
197+ size_treshold : int = 100 # in MBs
198+ percent_treshold : int = 10
199+ def test_image_size_change (self , image : str ):
200+ """Checks the image size didn't change extensively - treshold is 10% or XXX MB."""
201+
202+ # Map of image label names with expected size in MBs.
203+ expected_image_name_size_map = {
204+ "odh-notebook-base-centos-stream9-python-3.11" : 1 ,
205+ "odh-notebook-base-ubi9-python-3.11" : 1 ,
206+ "odh-notebook-cuda-c9s-python-3.11" : 1 ,
207+ "odh-notebook-cuda-ubi9-python-3.11" : 9070 , # TODO
208+ "odh-notebook-jupyter-datascience-ubi9-python-3.11" : 2845 ,
209+ "odh-notebook-jupyter-minimal-ubi9-python-3.11" : 1472 , # gpu 9070; rocm 26667 ???
210+ "odh-notebook-jupyter-pytorch-ubi9-python-3.11" : 15444 ,
211+ "odh-notebook-cuda-jupyter-tensorflow-ubi9-python-3.11" : 15218 ,
212+ "odh-notebook-jupyter-trustyai-ubi9-python-3.11" : 8613 ,
213+ "odh-notebook-jupyter-rocm-pytorch-ubi9-python-3.11" : 33001 ,
214+ "odh-notebook-jupyter-rocm-tensorflow-ubi9-python-3.11" : 30241 ,
215+ "odh-notebook-rstudio-server-c9s-python-3.11" : 13201 , # 3221 ??
216+ "odh-notebook-runtime-datascience-ubi9-python-3.11" : 2518 ,
217+ "odh-notebook-runtime-minimal-ubi9-python-3.11" : 1362 ,
218+ "odh-notebook-runtime-pytorch-ubi9-python-3.11" : 7487 ,
219+ "odh-notebook-cuda-runtime-tensorflow-ubi9-python-3.11" : 14572 ,
220+ "odh-notebook-runtime-rocm-pytorch-ubi9-python-3.11" : 32682 ,
221+ "odh-notebook-rocm-runtime-tensorflow-ubi9-python-3.11" : 29805 ,
222+ "odh-notebook-code-server-ubi9-python-3.11" : 2598 ,
223+ "odh-notebook-rocm-python-3.11" : 26667 , # TODO
224+ }
225+
226+ import docker
227+ client = testcontainers .core .container .DockerClient ()
228+ try :
229+ image_metadata = client .client .images .get (image )
230+ except docker .errors .ImageNotFound :
231+ image_metadata = client .client .images .pull (image )
232+ assert isinstance (image_metadata , docker .models .images .Image )
233+
234+ actual_img_size = image_metadata .attrs ["Size" ]
235+ actual_img_size = round (actual_img_size / 1024 / 1024 )
236+ logging .info (f"The size of the image is { actual_img_size } MBs." )
237+ logging .debug (f"The image metadata: { image_metadata } " )
238+
239+ img_label_name = image_metadata .labels ["name" ]
240+ if img_label_name in expected_image_name_size_map :
241+ expected_img_size = expected_image_name_size_map [img_label_name ]
242+ logging .debug (f"Expected size of the '{ img_label_name } ' image is { expected_img_size } MBs." )
243+ else :
244+ pytest .fail (f"Image name label '{ img_label_name } ' is not in the expected image size map { expected_image_name_size_map } " )
245+
246+ # Check the size change constraints now
247+ # 1. Percentual size change
248+ abs_percent_change = abs (actual_img_size / expected_img_size * 100 - 100 )
249+ assert abs_percent_change < self .percent_treshold , 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 } %)."
250+ # 2. Absolute size change
251+ abs_size_difference = abs (actual_img_size - expected_img_size )
252+ assert abs_size_difference < self .size_treshold , 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)."
192253
193254def encode_python_function_execution_command_interpreter (python : str , function : Callable [..., Any ], * args : list [Any ]) -> list [str ]:
194255 """Returns a cli command that will run the given Python function encoded inline.
0 commit comments