14
14
15
15
16
16
@pytest .fixture (scope = "session" )
17
- def docker_registry () -> str :
17
+ def docker_registry (keepdockerup : bool ) -> str :
18
18
# run the registry outside of the stack
19
19
docker_client = docker .from_env ()
20
- container = docker_client .containers .run (
21
- "registry:2" ,
22
- ports = {"5000" : "5000" },
23
- environment = ["REGISTRY_STORAGE_DELETE_ENABLED=true" ],
24
- restart_policy = {"Name" : "always" },
25
- detach = True ,
26
- )
20
+ # try to login to private registry
27
21
host = "127.0.0.1"
28
22
port = 5000
29
23
url = "{host}:{port}" .format (host = host , port = port )
30
- # Wait until we can connect
31
- assert _wait_till_registry_is_responsive (url )
24
+ container = None
25
+ try :
26
+ docker_client .login (registry = url , username = "simcore" )
27
+ container = docker_client .containers .list ({"name" :"pytest_registry" })[0 ]
28
+ except Exception :
29
+ print ("Warning: docker registry is already up!" )
30
+ container = docker_client .containers .run (
31
+ "registry:2" ,
32
+ ports = {"5000" : "5000" },
33
+ name = "pytest_registry" ,
34
+ environment = ["REGISTRY_STORAGE_DELETE_ENABLED=true" ],
35
+ restart_policy = {"Name" : "always" },
36
+ detach = True ,
37
+ )
38
+
39
+ # Wait until we can connect
40
+ assert _wait_till_registry_is_responsive (url )
32
41
33
- # test the registry
34
- docker_client = docker .from_env ()
35
42
# get the hello world example from docker hub
36
43
hello_world_image = docker_client .images .pull ("hello-world" , "latest" )
37
44
# login to private registry
@@ -49,11 +56,11 @@ def docker_registry() -> str:
49
56
docker_client .images .remove (image = private_image .id )
50
57
51
58
yield url
59
+ if not keepdockerup :
60
+ container .stop ()
52
61
53
- container .stop ()
54
-
55
- while docker_client .containers .list (filters = {"name" : container .name }):
56
- time .sleep (1 )
62
+ while docker_client .containers .list (filters = {"name" : container .name }):
63
+ time .sleep (1 )
57
64
58
65
59
66
@tenacity .retry (wait = tenacity .wait_fixed (1 ), stop = tenacity .stop_after_delay (60 ))
@@ -81,9 +88,9 @@ def sleeper_service(docker_registry: str) -> Dict[str, str]:
81
88
image_labels = image .labels
82
89
83
90
yield {
84
- json . loads ( key ): json .loads (value )
91
+ key [ len ( "io.simcore." ):]: json .loads (value )[ key [ len ( "io.simcore." ):]]
85
92
for key , value in image_labels .items ()
86
- if key .starts_with ("io.simcore." )
93
+ if key .startswith ("io.simcore." )
87
94
}
88
95
89
96
@@ -113,7 +120,7 @@ def jupyter_service(docker_registry: str) -> Dict[str, str]:
113
120
image_labels = image .labels
114
121
115
122
yield {
116
- json . loads ( key ): json .loads (value )
123
+ key [ len ( "io.simcore." ):]: json .loads (value )[ key [ len ( "io.simcore." ):]]
117
124
for key , value in image_labels .items ()
118
- if key .starts_with ("io.simcore." )
125
+ if key .startswith ("io.simcore." )
119
126
}
0 commit comments