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