-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make start and stop functions blocking #181
Changes from 16 commits
36bdb8b
e865379
a74d343
ead3fd9
030cd72
67afce5
d335451
70c33a4
001719a
59f01fc
e79c20e
173812b
03eebc8
38271a2
132b66f
116687d
704a0cc
60ea1b4
d22f278
9676ed9
e2adc19
61f2da0
5e404ae
50a6576
7f78f01
10be2d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package container | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
|
||
"github.com/docker/docker/api/types/mount" | ||
"github.com/docker/docker/api/types/swarm" | ||
) | ||
|
@@ -47,7 +50,7 @@ func (options *ServiceOptions) toSwarmServiceSpec() (service swarm.ServiceSpec) | |
}, | ||
Env: options.Env, | ||
Args: options.Args, | ||
Mounts: options.swarmMounts(), | ||
Mounts: options.swarmMounts(false), | ||
}, | ||
Networks: options.swarmNetworks(), | ||
}, | ||
|
@@ -71,7 +74,12 @@ func (options *ServiceOptions) swarmPorts() (ports []swarm.PortConfig) { | |
return | ||
} | ||
|
||
func (options *ServiceOptions) swarmMounts() (mounts []mount.Mount) { | ||
func (options *ServiceOptions) swarmMounts(force bool) (mounts []mount.Mount) { | ||
// hack for preventing mount when in CircleCI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit hacky, I would add a comment TOFIX just to make sure that we can find this again when the CI allow to mount directories There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment updated |
||
circleCI, errCircle := strconv.ParseBool(os.Getenv("CIRCLECI")) | ||
if force == false && errCircle == nil && circleCI { | ||
return | ||
} | ||
mounts = make([]mount.Mount, len(options.Mounts)) | ||
for i, m := range options.Mounts { | ||
mounts[i] = mount.Mount{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package container | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// StatusType of the service | ||
type StatusType uint | ||
|
||
|
@@ -8,3 +12,13 @@ const ( | |
STOPPED StatusType = 1 | ||
RUNNING StatusType = 2 | ||
) | ||
|
||
// TimeoutError represents an error of timeout | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is not a really good way to have errors I like the fact that we have the details in the error message but i'm sure we can do it better, I would just use something like that directly errors.New(Timeout reached after " + e.duration.String() + " for ressource " + e.name) or maybe have a function func timeoutError(duration, resource) error {
return errors.New(Timeout reached after " + e.duration.String() + " for ressource " + e.name)
} or just a constant with generic error message but like that we can compare this error in the tests for example. const TimeoutError = errors.New("Timeout error on container action") This is a bit too much and confusing because you don't even return an error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the classic way to create new errors in go and be able to compare. Eg with type casting: _, ok := err.(*TimeoutError) https://blog.golang.org/error-handling-and-go On the contrary, I think we should start creating custom error than using the default one with just a custom description. It will be way easier to debug. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it just feels like a lot of code just for a simple error that could be done in one constant but ok, let's follow the guidelines |
||
type TimeoutError struct { | ||
duration time.Duration | ||
name string | ||
} | ||
|
||
func (e *TimeoutError) Error() string { | ||
return "Timeout reached after " + e.duration.String() + " for ressource " + e.name | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use some
break
here in order to make sure that we always exit the for loop, it's a bit easier to testThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the new context of the
for
and the creation ofcurrentStatus
,err
is also created. So if I usebreak
, I'm pretty sure the err will not be assign to the returnerr
.If I write, the following code, go says
err is shadowed during return
on thereturn
.That's why I think if I use the break, the error will also be shadowed.
So there are 2 solutions.
The first one is to use
return err
as it's already the case.The second is to created
currentStatus
and then assign the value:@antho1404 What solution do you think it's the best?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally use the second solution all the time, we should definitely avoid shadowed variable it's the kind of things that can create bugs easily.