Closed wheresalice closed 6 years ago
I think the problem here is that cali.NewDockerClient()
does not run docker.InitDocker()
Instead, Cali runs it as part of defaultTaskFunc
.
I can sorta see why; no point initialising docker if you don't need to.
And considering the fact that InitDocker
can return an error if it can't talk to the docker daemon, we don't want staticli update
to fail just because we can't talk to Docker.
I think the solution is something like:
// Init initialises the client
func (c *DockerClient) InitDocker() error {
+ // Do nothing if already initialised Docker
+ if c.Cli != nil {
+ return nil
+ }
var cli *client.Client
defaultHeaders := map[string]string{"User-Agent": "engine-api-cli-1.0"}
cli, err := client.NewClient(dockerHost, "v1.22", nil, defaultHeaders)
if err != nil {
return fmt.Errorf("Could not connect to Docker daemon on %s: %s", dockerHost, err)
}
c.Cli = cli
return nil
}
Then, in ImageExists
(and all otherDockerClient functions that need it), add something like:
if err := cli.InitDocker(); err != nil {
return err
}
This also has the added benefit of us being able to pull InitDocker
out of defaultTaskFunc
, where it doesn't really belong.
In a task I can create a new DockerClient to pull newer versions of the image I'm working with. This seems to work (although I'm about to raise a separate issue on this):
But if I skip the
docker.InitDocker()
step then I get a segfault. Which is not user-friendly.We should somehow catch this (by checking InitDocker has run(?)