8
8
9
9
10
10
class ExecuteFailure (Exception ):
11
+ """Failure to execute command."""
11
12
pass
12
13
13
14
14
15
class Docker :
15
-
16
+ """The Docker class."""
16
17
def __init__ (self , local_portage , overlay_dirs ):
17
18
"""Create a new container."""
18
19
@@ -44,7 +45,7 @@ def execute(self, cmd):
44
45
"""
45
46
46
47
options .log .info ("%s %s" % (self .cid [:6 ], cmd ))
47
- docker_cmd = [ options .options .docker_command , "exec" , "--interactive" ]
48
+ docker_cmd = options .options .docker_command + [ "exec" , "--interactive" ]
48
49
docker_cmd += [self .cid , "/bin/bash" ]
49
50
docker = subprocess .Popen (docker_cmd ,
50
51
stdout = subprocess .PIPE ,
@@ -94,9 +95,9 @@ def shell(self):
94
95
"""Run an interactive shell in container."""
95
96
96
97
options .log .info ("running interactive shell in container" )
97
- docker = subprocess .Popen ([ options .options .docker_command ,
98
- "exec" , "--tty" , "--interactive" ,
99
- self .cid , "/bin/bash" ])
98
+ docker = subprocess .Popen (options .options .docker_command
99
+ + [ "exec" , "--tty" , "--interactive" ,
100
+ self .cid , "/bin/bash" ])
100
101
try :
101
102
docker .wait ()
102
103
except KeyboardInterrupt :
@@ -112,12 +113,12 @@ def remove(self):
112
113
"""Remove the docker container."""
113
114
114
115
options .log .info ("stopping container" )
115
- docker = subprocess .Popen ([ options .options .docker_command ,
116
- "kill" , self .cid ])
116
+ docker = subprocess .Popen (options .options .docker_command
117
+ + [ "kill" , self .cid ])
117
118
docker .wait ()
118
119
options .log .info ("deleting container" )
119
- docker = subprocess .Popen ([ options .options .docker_command ,
120
- "rm" , self .cid ])
120
+ docker = subprocess .Popen (options .options .docker_command
121
+ + [ "rm" , self .cid ])
121
122
docker .wait ()
122
123
123
124
def _reader (self , proc , stream , name ):
@@ -135,27 +136,27 @@ def _setup_container(self, docker_image):
135
136
"""Setup the container."""
136
137
137
138
if options .options .pull :
138
- docker_args = [ options .options .docker_command ,
139
- "pull" , docker_image ]
139
+ docker_args = options .options .docker_command \
140
+ + [ "pull" , docker_image ]
140
141
docker = subprocess .Popen (docker_args )
141
142
docker .wait ()
142
143
143
144
def _create_container (self , docker_image , local_portage , overlays ):
144
145
"""Create new container."""
145
146
146
- docker_args = [
147
- options . options . docker_command , "create" ,
148
- "--tty" ,
149
- "--cap-add" , "CAP_SYS_ADMIN" ,
150
- "--cap-add" , "CAP_MKNOD" ,
151
- "--cap-add" , "CAP_NET_ADMIN" ,
152
- # https://github.com/moby/moby/issues/16429
153
- "--security-opt" , "apparmor:unconfined" ,
154
- "--device" , "/dev/fuse" ,
155
- "--workdir" , "/root" ,
156
- "--volume" , "%s:/var/db/repos/gentoo" % local_portage ,
157
- "--volume" , "%s/distfiles:/var/cache/distfiles" % local_portage ,
158
- "--volume" , "%s/packages:/var/cache/binpkgs" % local_portage ]
147
+ docker_args = options . options . docker_command \
148
+ + [ "create" ,
149
+ "--tty" ,
150
+ "--cap-add" , "CAP_SYS_ADMIN" ,
151
+ "--cap-add" , "CAP_MKNOD" ,
152
+ "--cap-add" , "CAP_NET_ADMIN" ,
153
+ # https://github.com/moby/moby/issues/16429
154
+ "--security-opt" , "apparmor:unconfined" ,
155
+ "--device" , "/dev/fuse" ,
156
+ "--workdir" , "/root" ,
157
+ "--volume" , "%s:/var/db/repos/gentoo" % local_portage ,
158
+ "--volume" , "%s/distfiles:/var/cache/distfiles" % local_portage ,
159
+ "--volume" , "%s/packages:/var/cache/binpkgs" % local_portage ]
159
160
160
161
if options .options .storage_opt :
161
162
for s in options .options .storage_opt :
@@ -182,8 +183,8 @@ def _create_container(self, docker_image, local_portage, overlays):
182
183
def _start_container (self ):
183
184
"""Start the container."""
184
185
185
- docker_args = [ options .options .docker_command ,
186
- "start" , "%s" % self .cid ]
186
+ docker_args = options .options .docker_command \
187
+ + [ "start" , "%s" % self .cid ]
187
188
docker = subprocess .Popen (docker_args , stdout = subprocess .PIPE )
188
189
docker .wait ()
189
190
if docker .returncode != 0 :
0 commit comments