1111from pathlib import Path
1212from typing import Any
1313
14+ import aiodocker
1415import docker
1516import jsonschema
1617import pytest
@@ -144,40 +145,45 @@ def _pull_push_service(
144145) -> dict [str , Any ]:
145146 client = docker .from_env ()
146147 # pull image from original location
147- print ( f"Pulling { pull_key } :{ tag } ..." )
148- image = client .images .pull (pull_key , tag = tag )
149- assert image , f"image { pull_key } :{ tag } could NOT be pulled!"
148+ with log_context ( logging . INFO , msg = f"Pulling { pull_key } :{ tag } ..." ):
149+ image = client .images .pull (pull_key , tag = tag )
150+ assert image , f"image { pull_key } :{ tag } could NOT be pulled!"
150151
151152 # get io.simcore.* labels
152153 image_labels : dict = dict (image .labels )
153154
154155 if owner_email :
155- print (f"Overriding labels to take ownership as { owner_email } ..." )
156- # By overriding these labels, user owner_email gets ownership of the service
157- # and the catalog service automatically gives full access rights for testing it
158- # otherwise it does not even get read rights
159-
160- image_labels .update ({"io.simcore.contact" : f'{{"contact": "{ owner_email } "}}' })
161- image_labels .update (
162- {
163- "io.simcore.authors" : f'{{"authors": [{{"name": "Tester", "email": "{ owner_email } ", "affiliation": "IT\' IS Foundation"}}] }}'
164- }
165- )
166- image_labels .update ({"maintainer" : f"{ owner_email } " })
167-
168- df_path = Path ("Dockerfile" ).resolve ()
169- df_path .write_text (f"FROM { pull_key } :{ tag } " )
156+ with log_context (
157+ logging .INFO ,
158+ msg = (f"Overriding labels to take ownership as { owner_email } ..." ,),
159+ ):
160+ # By overriding these labels, user owner_email gets ownership of the service
161+ # and the catalog service automatically gives full access rights for testing it
162+ # otherwise it does not even get read rights
170163
171- try :
172- # Rebuild to override image labels AND re-tag
173- image2 , _ = client .images .build (
174- path = str (df_path .parent ), labels = image_labels , tag = f"{ tag } -owned"
164+ image_labels .update (
165+ {"io.simcore.contact" : f'{{"contact": "{ owner_email } "}}' }
166+ )
167+ image_labels .update (
168+ {
169+ "io.simcore.authors" : f'{{"authors": [{{"name": "Tester", "email": "{ owner_email } ", "affiliation": "IT\' IS Foundation"}}] }}'
170+ }
175171 )
176- print (json .dumps (image2 .labels , indent = 2 ))
177- image = image2
172+ image_labels .update ({"maintainer" : f"{ owner_email } " })
178173
179- finally :
180- df_path .unlink ()
174+ df_path = Path ("Dockerfile" ).resolve ()
175+ df_path .write_text (f"FROM { pull_key } :{ tag } " )
176+
177+ try :
178+ # Rebuild to override image labels AND re-tag
179+ image2 , _ = client .images .build (
180+ path = str (df_path .parent ), labels = image_labels , tag = f"{ tag } -owned"
181+ )
182+ print (json .dumps (image2 .labels , indent = 2 ))
183+ image = image2
184+
185+ finally :
186+ df_path .unlink ()
181187
182188 assert image_labels
183189 io_simcore_labels = {
@@ -197,8 +203,11 @@ def _pull_push_service(
197203 assert image .tag (new_image_tag )
198204
199205 # push the image to the new location
200- print (f"Pushing { pull_key } :{ tag } -> { new_image_tag } ..." )
201- client .images .push (new_image_tag )
206+ with log_context (
207+ logging .INFO ,
208+ msg = f"Pushing { pull_key } :{ tag } -> { new_image_tag } ..." ,
209+ ):
210+ client .images .push (new_image_tag )
202211
203212 # return image io.simcore.* labels
204213 image_labels = dict (image .labels )
0 commit comments