1
1
import json
2
- import os
3
2
import sys
4
3
4
+
5
5
class Interactor :
6
6
7
7
def __init__ (self , interactor_config = None ):
8
8
self .config = interactor_config
9
-
9
+
10
10
def set_config (self , interactor_config ):
11
11
self .config = interactor_config
12
-
12
+
13
13
def interact (self , client , generate_save_tag ):
14
14
"""
15
15
Starts a container from a saved image that has already been initialized/indexed.
@@ -23,7 +23,7 @@ def interact(self, client, generate_save_tag):
23
23
exists = len (client .images .list (filters = {"reference" : "{}:{}" .format (self .config .repo , save_tag )})) != 0
24
24
if not exists :
25
25
sys .exit ("Must prepare image first..." )
26
-
26
+
27
27
interact_args = {
28
28
"opts" : {key : value for (key , value ) in map (lambda x : x .split ("=" ), self .config .opts )}
29
29
}
@@ -32,11 +32,11 @@ def interact(self, client, generate_save_tag):
32
32
# create with sh command to override any default command
33
33
container = client .containers .create ("{}:{}" .format (self .config .repo , save_tag ), command = "sh" , tty = True )
34
34
container .start ()
35
-
35
+
36
36
print ("Running interact script in container..." )
37
- log = container .exec_run ("sh -c '/interact --json {}'" .format (json .dumps (json .dumps (interact_args ))),
38
- stdout = True , stderr = True , stream = True )
39
-
37
+ log = container .exec_run ("sh -c '/interact --json {}'" .format (json .dumps (json .dumps (interact_args ))),
38
+ stdout = True , stderr = True , stream = True )
39
+
40
40
print ("Logs for interact in container with ID {}..." .format (container .id ))
41
41
for line in log [1 ]:
42
42
print (str (line .decode ('utf-8' )), end = "" )
@@ -47,7 +47,7 @@ def interact(self, client, generate_save_tag):
47
47
print ("Exiting..." )
48
48
print ("Don't forget to stop and remove the container after you are done!" )
49
49
return
50
-
50
+
51
51
wait = input ("Press ENTER to stop and remove container" )
52
52
print ("Stopping container {}..." .format (container .id ))
53
53
container .stop ()
0 commit comments