@@ -22,14 +22,19 @@ class DockerCompose(object):
22
22
-------
23
23
::
24
24
25
- with DockerCompose("/home/project", pull=True) as compose:
25
+ with DockerCompose("/home/project",
26
+ compose_file_name=["docker-compose-1.yml", "docker-compose-2.yml"],
27
+ pull=True) as compose:
26
28
host = compose.get_service_host("hub", 4444)
27
29
port = compose.get_service_port("hub", 4444)
28
30
driver = webdriver.Remote(
29
31
command_executor=("http://{}:{}/wd/hub".format(host,port)),
30
32
desired_capabilities=CHROME,
31
33
)
32
34
driver.get("http://automation-remarks.com")
35
+ stdout, stderr = compose.get_logs()
36
+ if stderr:
37
+ print("Errors\\ n:{}".format(stderr))
33
38
34
39
35
40
.. code-block:: yaml
@@ -57,7 +62,9 @@ def __init__(
57
62
compose_file_name = "docker-compose.yml" ,
58
63
pull = False ):
59
64
self .filepath = filepath
60
- self .compose_file_name = compose_file_name
65
+ self .compose_file_names = compose_file_name if isinstance (
66
+ compose_file_name , (list , tuple )
67
+ ) else [compose_file_name ]
61
68
self .pull = pull
62
69
63
70
def __enter__ (self ):
@@ -67,18 +74,35 @@ def __enter__(self):
67
74
def __exit__ (self , exc_type , exc_val , exc_tb ):
68
75
self .stop ()
69
76
77
+ def docker_compose_command (self ):
78
+ docker_compose_cmd = ['docker-compose' ]
79
+ for file in self .compose_file_names :
80
+ docker_compose_cmd += ['-f' , file ]
81
+ return docker_compose_cmd
82
+
70
83
def start (self ):
71
84
with blindspin .spinner ():
72
85
if self .pull :
73
- subprocess . call ([ "docker-compose" , "-f" , self .compose_file_name , " pull" ],
74
- cwd = self .filepath )
75
- subprocess . call ([ "docker-compose" , "-f" , self .compose_file_name , "up" , "-d" ],
76
- cwd = self .filepath )
86
+ pull_cmd = self .docker_compose_command () + [ ' pull' ]
87
+ subprocess . call ( pull_cmd , cwd = self .filepath )
88
+ up_cmd = self .docker_compose_command () + [ 'up' , '-d' ]
89
+ subprocess . call ( up_cmd , cwd = self .filepath )
77
90
78
91
def stop (self ):
79
92
with blindspin .spinner ():
80
- subprocess .call (["docker-compose" , "-f" , self .compose_file_name , "down" , "-v" ],
81
- cwd = self .filepath )
93
+ down_cmd = self .docker_compose_command () + ['down' , '-v' ]
94
+ subprocess .call (down_cmd , cwd = self .filepath )
95
+
96
+ def get_logs (self ):
97
+ logs_cmd = self .docker_compose_command () + ["logs" ]
98
+ with blindspin .spinner ():
99
+ result = subprocess .run (
100
+ logs_cmd ,
101
+ cwd = self .filepath ,
102
+ stdout = subprocess .PIPE ,
103
+ stderr = subprocess .PIPE ,
104
+ )
105
+ return result .stdout , result .stderr
82
106
83
107
def get_service_port (self , service_name , port ):
84
108
return self ._get_service_info (service_name , port )[1 ]
@@ -87,9 +111,8 @@ def get_service_host(self, service_name, port):
87
111
return self ._get_service_info (service_name , port )[0 ]
88
112
89
113
def _get_service_info (self , service , port ):
90
- cmd_as_list = ["docker-compose" , "-f" , self .compose_file_name , "port" , service , str (port )]
91
- output = subprocess .check_output (cmd_as_list ,
92
- cwd = self .filepath ).decode ("utf-8" )
114
+ port_cmd = self .docker_compose_command () + ["port" , service , str (port )]
115
+ output = subprocess .check_output (port_cmd , cwd = self .filepath ).decode ("utf-8" )
93
116
result = str (output ).rstrip ().split (":" )
94
117
if len (result ) == 1 :
95
118
raise NoSuchPortExposed ("Port {} was not exposed for service {}"
0 commit comments