diff --git a/api/core/core_test.go b/api/core/core_test.go index 81e9e3a12..5ea2ce99d 100644 --- a/api/core/core_test.go +++ b/api/core/core_test.go @@ -13,7 +13,7 @@ func newServer(t *testing.T) *Server { container, err := container.New() require.Nil(t, err) - m, err := mesg.New(mesg.DockerClientOption(container)) + m, err := mesg.New(mesg.ContainerOption(container)) require.Nil(t, err) server, err := NewServer(MESGOption(m)) @@ -28,7 +28,7 @@ func newServerAndDockerTest(t *testing.T) (*Server, *dockertest.Testing) { container, err := container.New(container.ClientOption(dt.Client())) require.Nil(t, err) - m, err := mesg.New(mesg.DockerClientOption(container)) + m, err := mesg.New(mesg.ContainerOption(container)) require.Nil(t, err) server, err := NewServer(MESGOption(m)) diff --git a/api/core/type.go b/api/core/type.go index d6434f144..0e6e3901c 100644 --- a/api/core/type.go +++ b/api/core/type.go @@ -26,6 +26,7 @@ func NewServer(options ...Option) (*Server, error) { return s, nil } +// MESGOption configures underlying mesg access API. func MESGOption(mesg *mesg.MESG) Option { return func(s *Server) { s.mesg = mesg diff --git a/cmd/service/deploy.go b/cmd/service/deploy.go index dfa4aef39..b065f4464 100644 --- a/cmd/service/deploy.go +++ b/cmd/service/deploy.go @@ -54,30 +54,9 @@ func deployService(path string) (serviceID string, err error) { return "", err } } else { - archive, err := archive.TarWithOptions(path, &archive.TarOptions{ - Compression: archive.Gzip, - }) - if err != nil { + if err := deployServiceSendServiceContext(path, stream); err != nil { return "", err } - - buf := make([]byte, 1024) - for { - n, err := archive.Read(buf) - if err == io.EOF { - break - } - if err != nil { - return "", err - } - - if err := stream.Send(&core.DeployServiceRequest{ - Value: &core.DeployServiceRequest_Chunk{Chunk: buf[:n]}, - }); err != nil { - return "", err - } - - } } if err := stream.CloseSend(); err != nil { @@ -88,6 +67,34 @@ func deployService(path string) (serviceID string, err error) { return result.serviceID, result.err } +func deployServiceSendServiceContext(path string, stream core.Core_DeployServiceClient) error { + archive, err := archive.TarWithOptions(path, &archive.TarOptions{ + Compression: archive.Gzip, + }) + if err != nil { + return err + } + + buf := make([]byte, 1024) + for { + n, err := archive.Read(buf) + if err == io.EOF { + break + } + if err != nil { + return err + } + + if err := stream.Send(&core.DeployServiceRequest{ + Value: &core.DeployServiceRequest_Chunk{Chunk: buf[:n]}, + }); err != nil { + return err + } + } + + return nil +} + type deploymentResult struct { serviceID string err error diff --git a/mesg/mesg.go b/mesg/mesg.go index 22903f400..99116aa4c 100644 --- a/mesg/mesg.go +++ b/mesg/mesg.go @@ -26,7 +26,8 @@ func New(options ...Option) (*MESG, error) { return m, nil } -func DockerClientOption(container *container.Container) Option { +// ContainerOption configures underlying container access API. +func ContainerOption(container *container.Container) Option { return func(m *MESG) { m.container = container }