8
8
"strings"
9
9
"syscall"
10
10
11
+ "golang.org/x/net/context"
12
+
11
13
"github.com/Sirupsen/logrus"
12
14
"github.com/codegangsta/cli"
13
15
"github.com/docker/libcompose/project"
@@ -47,7 +49,7 @@ func WithProject(factory ProjectFactory, action ProjectAction) func(context *cli
47
49
// ProjectPs lists the containers.
48
50
func ProjectPs (p project.APIProject , c * cli.Context ) error {
49
51
qFlag := c .Bool ("q" )
50
- allInfo , err := p .Ps (qFlag , c .Args ()... )
52
+ allInfo , err := p .Ps (context . Background (), qFlag , c .Args ()... )
51
53
if err != nil {
52
54
return cli .NewExitError (err .Error (), 1 )
53
55
}
@@ -66,7 +68,7 @@ func ProjectPort(p project.APIProject, c *cli.Context) error {
66
68
serviceName := c .Args ()[0 ]
67
69
privatePort := c .Args ()[1 ]
68
70
69
- port , err := p .Port (index , protocol , serviceName , privatePort )
71
+ port , err := p .Port (context . Background (), index , protocol , serviceName , privatePort )
70
72
if err != nil {
71
73
return cli .NewExitError (err .Error (), 1 )
72
74
}
@@ -76,7 +78,7 @@ func ProjectPort(p project.APIProject, c *cli.Context) error {
76
78
77
79
// ProjectStop stops all services.
78
80
func ProjectStop (p project.APIProject , c * cli.Context ) error {
79
- err := p .Stop (c .Int ("timeout" ), c .Args ()... )
81
+ err := p .Stop (context . Background (), c .Int ("timeout" ), c .Args ()... )
80
82
if err != nil {
81
83
return cli .NewExitError (err .Error (), 1 )
82
84
}
@@ -90,7 +92,7 @@ func ProjectDown(p project.APIProject, c *cli.Context) error {
90
92
RemoveImages : options .ImageType (c .String ("rmi" )),
91
93
RemoveOrphans : c .Bool ("remove-orphans" ),
92
94
}
93
- err := p .Down (options , c .Args ()... )
95
+ err := p .Down (context . Background (), options , c .Args ()... )
94
96
if err != nil {
95
97
return cli .NewExitError (err .Error (), 1 )
96
98
}
@@ -104,7 +106,7 @@ func ProjectBuild(p project.APIProject, c *cli.Context) error {
104
106
ForceRemove : c .Bool ("force-rm" ),
105
107
Pull : c .Bool ("pull" ),
106
108
}
107
- err := p .Build (config , c .Args ()... )
109
+ err := p .Build (context . Background (), config , c .Args ()... )
108
110
if err != nil {
109
111
return cli .NewExitError (err .Error (), 1 )
110
112
}
@@ -118,7 +120,7 @@ func ProjectCreate(p project.APIProject, c *cli.Context) error {
118
120
ForceRecreate : c .Bool ("force-recreate" ),
119
121
NoBuild : c .Bool ("no-build" ),
120
122
}
121
- err := p .Create (options , c .Args ()... )
123
+ err := p .Create (context . Background (), options , c .Args ()... )
122
124
if err != nil {
123
125
return cli .NewExitError (err .Error (), 1 )
124
126
}
@@ -134,7 +136,8 @@ func ProjectUp(p project.APIProject, c *cli.Context) error {
134
136
NoBuild : c .Bool ("no-build" ),
135
137
},
136
138
}
137
- err := p .Up (options , c .Args ()... )
139
+ ctx , cancelFun := context .WithCancel (context .Background ())
140
+ err := p .Up (ctx , options , c .Args ()... )
138
141
if err != nil {
139
142
return cli .NewExitError (err .Error (), 1 )
140
143
}
@@ -144,12 +147,13 @@ func ProjectUp(p project.APIProject, c *cli.Context) error {
144
147
signal .Notify (signalChan , syscall .SIGINT , syscall .SIGTERM )
145
148
errChan := make (chan error )
146
149
go func () {
147
- errChan <- p .Log (true , c .Args ()... )
150
+ errChan <- p .Log (ctx , true , c .Args ()... )
148
151
}()
149
152
go func () {
150
153
select {
151
154
case <- signalChan :
152
155
fmt .Printf ("\n Gracefully stopping...\n " )
156
+ cancelFun ()
153
157
ProjectStop (p , c )
154
158
cleanupDone <- true
155
159
case err := <- errChan :
@@ -174,7 +178,7 @@ func ProjectRun(p project.APIProject, c *cli.Context) error {
174
178
serviceName := c .Args ()[0 ]
175
179
commandParts := c .Args ()[1 :]
176
180
177
- exitCode , err := p .Run (serviceName , commandParts )
181
+ exitCode , err := p .Run (context . Background (), serviceName , commandParts )
178
182
if err != nil {
179
183
return cli .NewExitError (err .Error (), 1 )
180
184
}
@@ -183,7 +187,7 @@ func ProjectRun(p project.APIProject, c *cli.Context) error {
183
187
184
188
// ProjectStart starts services.
185
189
func ProjectStart (p project.APIProject , c * cli.Context ) error {
186
- err := p .Start (c .Args ()... )
190
+ err := p .Start (context . Background (), c .Args ()... )
187
191
if err != nil {
188
192
return cli .NewExitError (err .Error (), 1 )
189
193
}
@@ -192,7 +196,7 @@ func ProjectStart(p project.APIProject, c *cli.Context) error {
192
196
193
197
// ProjectRestart restarts services.
194
198
func ProjectRestart (p project.APIProject , c * cli.Context ) error {
195
- err := p .Restart (c .Int ("timeout" ), c .Args ()... )
199
+ err := p .Restart (context . Background (), c .Int ("timeout" ), c .Args ()... )
196
200
if err != nil {
197
201
return cli .NewExitError (err .Error (), 1 )
198
202
}
@@ -201,7 +205,7 @@ func ProjectRestart(p project.APIProject, c *cli.Context) error {
201
205
202
206
// ProjectLog gets services logs.
203
207
func ProjectLog (p project.APIProject , c * cli.Context ) error {
204
- err := p .Log (c .Bool ("follow" ), c .Args ()... )
208
+ err := p .Log (context . Background (), c .Bool ("follow" ), c .Args ()... )
205
209
if err != nil {
206
210
return cli .NewExitError (err .Error (), 1 )
207
211
}
@@ -210,7 +214,7 @@ func ProjectLog(p project.APIProject, c *cli.Context) error {
210
214
211
215
// ProjectPull pulls images for services.
212
216
func ProjectPull (p project.APIProject , c * cli.Context ) error {
213
- err := p .Pull (c .Args ()... )
217
+ err := p .Pull (context . Background (), c .Args ()... )
214
218
if err != nil && ! c .Bool ("ignore-pull-failures" ) {
215
219
return cli .NewExitError (err .Error (), 1 )
216
220
}
@@ -237,7 +241,7 @@ func ProjectDelete(p project.APIProject, c *cli.Context) error {
237
241
return true
238
242
}
239
243
}
240
- err := p .Delete (options , c .Args ()... )
244
+ err := p .Delete (context . Background (), options , c .Args ()... )
241
245
if err != nil {
242
246
return cli .NewExitError (err .Error (), 1 )
243
247
}
@@ -246,7 +250,7 @@ func ProjectDelete(p project.APIProject, c *cli.Context) error {
246
250
247
251
// ProjectKill forces stop service containers.
248
252
func ProjectKill (p project.APIProject , c * cli.Context ) error {
249
- err := p .Kill (c .String ("signal" ), c .Args ()... )
253
+ err := p .Kill (context . Background (), c .String ("signal" ), c .Args ()... )
250
254
if err != nil {
251
255
return cli .NewExitError (err .Error (), 1 )
252
256
}
@@ -255,7 +259,7 @@ func ProjectKill(p project.APIProject, c *cli.Context) error {
255
259
256
260
// ProjectPause pauses service containers.
257
261
func ProjectPause (p project.APIProject , c * cli.Context ) error {
258
- err := p .Pause (c .Args ()... )
262
+ err := p .Pause (context . Background (), c .Args ()... )
259
263
if err != nil {
260
264
return cli .NewExitError (err .Error (), 1 )
261
265
}
@@ -264,7 +268,7 @@ func ProjectPause(p project.APIProject, c *cli.Context) error {
264
268
265
269
// ProjectUnpause unpauses service containers.
266
270
func ProjectUnpause (p project.APIProject , c * cli.Context ) error {
267
- err := p .Unpause (c .Args ()... )
271
+ err := p .Unpause (context . Background (), c .Args ()... )
268
272
if err != nil {
269
273
return cli .NewExitError (err .Error (), 1 )
270
274
}
@@ -290,7 +294,7 @@ func ProjectScale(p project.APIProject, c *cli.Context) error {
290
294
servicesScale [name ] = count
291
295
}
292
296
293
- err := p .Scale (c .Int ("timeout" ), servicesScale )
297
+ err := p .Scale (context . Background (), c .Int ("timeout" ), servicesScale )
294
298
if err != nil {
295
299
return cli .NewExitError (err .Error (), 1 )
296
300
}
0 commit comments