From dc334119d61dd6e8f4d269e28e2986abc96fac4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 19 Aug 2017 10:49:19 +0200 Subject: [PATCH] Close backend engine after execution It is required to close docker client when it uses socket. https://godoc.org/github.com/moby/moby/client#Client.Close --- pipec/exec.go | 1 + pipeline/backend/backend.go | 2 ++ pipeline/backend/docker/docker.go | 8 ++++++-- pipeline/backend/kubernetes/kubernetes.go | 4 ++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pipec/exec.go b/pipec/exec.go index 79c4efe..cd3f3a9 100644 --- a/pipec/exec.go +++ b/pipec/exec.go @@ -86,6 +86,7 @@ func executeAction(c *cli.Context) (err error) { return err } } + defer engine.Close() ctx, cancel := context.WithTimeout(context.Background(), c.Duration("timeout")) defer cancel() diff --git a/pipeline/backend/backend.go b/pipeline/backend/backend.go index ef83310..7a25027 100644 --- a/pipeline/backend/backend.go +++ b/pipeline/backend/backend.go @@ -18,4 +18,6 @@ type Engine interface { Tail(*Step) (io.ReadCloser, error) // Destroy the pipeline environment. Destroy(*Config) error + // Close the engine + Close() error } diff --git a/pipeline/backend/docker/docker.go b/pipeline/backend/docker/docker.go index e7c67d6..f602ffa 100644 --- a/pipeline/backend/docker/docker.go +++ b/pipeline/backend/docker/docker.go @@ -15,11 +15,11 @@ import ( ) type engine struct { - client client.APIClient + client *client.Client } // New returns a new Docker Engine using the given client. -func New(cli client.APIClient) backend.Engine { +func New(cli *client.Client) backend.Engine { return &engine{ client: cli, } @@ -183,6 +183,10 @@ func (e *engine) Destroy(conf *backend.Config) error { return nil } +func (e *engine) Close() error { + return e.client.Close() +} + var ( noContext = context.Background() diff --git a/pipeline/backend/kubernetes/kubernetes.go b/pipeline/backend/kubernetes/kubernetes.go index fad95e7..c4ff35f 100644 --- a/pipeline/backend/kubernetes/kubernetes.go +++ b/pipeline/backend/kubernetes/kubernetes.go @@ -58,3 +58,7 @@ func (e *engine) Destroy(*backend.Config) error { // DELETE /api/v1/namespaces/{name} return nil } + +func (e *engine) Close() error { + return nil +}