@@ -189,6 +189,69 @@ def test_pip_install_cowsay_runs(self, image: str):
189
189
finally :
190
190
docker_utils .NotebookContainer (container ).stop (timeout = 0 )
191
191
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.). In this case, we need to check the size of the build image that contains these updates.
194
+ # 2. A change is done to the params.env file where we update manifest references to a new image. In this case we shall check that the updated reference matches our size constraints
195
+ size_treshold : int = 100 # in MBs
196
+ percent_treshold : int = 10
197
+ def test_image_size_change (self , image : str ):
198
+ """Checks the image size didn't change extensively - treshold is 10% or XXX MB."""
199
+
200
+ # Map of image label names with expected size in MBs.
201
+ expected_image_name_size_map = {
202
+ "odh-notebook-base-centos-stream9-python-3.11" : 1 ,
203
+ "odh-notebook-base-ubi9-python-3.11" : 1 ,
204
+ "odh-notebook-cuda-c9s-python-3.11" : 1 ,
205
+ "odh-notebook-cuda-ubi9-python-3.11" : 1 ,
206
+ "odh-notebook-jupyter-datascience-ubi9-python-3.11" : 1 ,
207
+ "odh-notebook-jupyter-datascience-ubi9-python-3.9" : 2681 , # TODO
208
+ "odh-notebook-jupyter-minimal-ubi9-python-3.11" : 1 ,
209
+ "odh-notebook-jupyter-pytorch-ubi9-python-3.11" : 1 ,
210
+ "odh-notebook-cuda-jupyter-tensorflow-ubi9-python-3.11" : 1 ,
211
+ "odh-notebook-jupyter-trustyai-ubi9-python-3.11" : 1 ,
212
+ "odh-notebook-jupyter-rocm-pytorch-ubi9-python-3.11" : 1 ,
213
+ "odh-notebook-jupyter-rocm-tensorflow-ubi9-python-3.11" : 1 ,
214
+ "odh-notebook-rstudio-server-c9s-python-3.11" : 1 ,
215
+ "odh-notebook-runtime-datascience-ubi9-python-3.11" : 1 ,
216
+ "odh-notebook-runtime-minimal-ubi9-python-3.11" : 1 ,
217
+ "odh-notebook-runtime-pytorch-ubi9-python-3.11" : 1 ,
218
+ "odh-notebook-cuda-runtime-tensorflow-ubi9-python-3.11" : 1 ,
219
+ "odh-notebook-runtime-rocm-pytorch-ubi9-python-3.11" : 1 ,
220
+ "odh-notebook-rocm-runtime-tensorflow-ubi9-python-3.11" : 1 ,
221
+ "odh-notebook-code-server-ubi9-python-3.11" : 1 ,
222
+ "odh-notebook-rocm-python-3.11" : 1 ,
223
+ }
224
+
225
+ client = testcontainers .core .container .DockerClient ()
226
+
227
+ image_metadata = client .client .images .get (image )
228
+ actual_img_size = image_metadata .attrs ["Size" ]
229
+ actual_img_size = round (actual_img_size / 1024 / 1024 )
230
+ logging .info (f"The size of the image is { actual_img_size } MBs." )
231
+
232
+ # print(image_metadata)
233
+
234
+ import docker
235
+ try :
236
+ image_metadata = client .client .images .get (image )
237
+ except docker .errors .ImageNotFound :
238
+ image_metadata = client .client .images .pull (image )
239
+ assert isinstance (image_metadata , docker .models .images .Image )
240
+
241
+ img_label_name = image_metadata .labels ["name" ]
242
+ if img_label_name in expected_image_name_size_map :
243
+ expected_img_size = expected_image_name_size_map [img_label_name ]
244
+ logging .debug (f"Expected size of the image is { expected_img_size } MBs." )
245
+ else :
246
+ pytest .fail (f"Image name label '{ img_label_name } ' is not in the expected image size map { expected_image_name_size_map } " )
247
+
248
+ # Check the size change constraints now
249
+ # 1. Percentual size change
250
+ percent_change = actual_img_size / expected_img_size * 100 - 100
251
+ assert percent_change < self .percent_treshold , f"Image size changed by { percent_change } % (expected: { expected_img_size } MB; actual: { actual_img_size } MB; treshold: { self .percent_treshold } %)."
252
+ # 2. Absolute size change
253
+ size_difference = actual_img_size - expected_img_size
254
+ assert size_difference < self .size_treshold , f"Image size changed by { size_difference } MB (expected: { expected_img_size } MB; actual: { actual_img_size } MB; treshold: { self .size_treshold } MB)."
192
255
193
256
def encode_python_function_execution_command_interpreter (python : str , function : Callable [..., Any ], * args : list [Any ]) -> list [str ]:
194
257
"""Returns a cli command that will run the given Python function encoded inline.
0 commit comments