Skip to content

Commit

Permalink
add more comments & minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgooz committed Aug 16, 2018
1 parent 51be4a9 commit cbd3b96
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
4 changes: 2 additions & 2 deletions api/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
1 change: 1 addition & 0 deletions api/core/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 29 additions & 22 deletions cmd/service/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion mesg/mesg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit cbd3b96

Please sign in to comment.