From 669aef857b5463e287740452bfcf95fac7ea386c Mon Sep 17 00:00:00 2001 From: zc Date: Mon, 2 Mar 2020 18:01:39 +0800 Subject: [PATCH] send file --- cluster/calcium/send.go | 4 +--- engine/docker/container.go | 3 ++- engine/systemd/systemd.go | 3 +++ engine/systemd/virtualization.go | 11 ++++++++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cluster/calcium/send.go b/cluster/calcium/send.go index a61bcfff9..57aa00a47 100644 --- a/cluster/calcium/send.go +++ b/cluster/calcium/send.go @@ -3,7 +3,6 @@ package calcium import ( "context" "os" - "path/filepath" "sync" "github.com/projecteru2/core/engine" @@ -42,7 +41,6 @@ func (c *Calcium) Send(ctx context.Context, opts *types.SendOptions) (chan *type } func (c *Calcium) doSendFileToContainer(ctx context.Context, engine engine.API, ID, dst, src string, AllowOverwriteDirWithFile bool, CopyUIDGID bool) error { - path := filepath.Dir(dst) log.Infof("[doSendFileToContainer] Send file to %s:%s", ID, dst) log.Debugf("[doSendFileToContainer] Local file %s, remote path %s", src, dst) f, err := os.Open(src) @@ -50,5 +48,5 @@ func (c *Calcium) doSendFileToContainer(ctx context.Context, engine engine.API, return err } defer f.Close() - return engine.VirtualizationCopyTo(ctx, ID, path, f, AllowOverwriteDirWithFile, CopyUIDGID) + return engine.VirtualizationCopyTo(ctx, ID, dst, f, AllowOverwriteDirWithFile, CopyUIDGID) } diff --git a/engine/docker/container.go b/engine/docker/container.go index 17a12c7fb..95c6be99b 100644 --- a/engine/docker/container.go +++ b/engine/docker/container.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "io/ioutil" + "path/filepath" "github.com/docker/go-connections/nat" "github.com/docker/go-units" @@ -192,7 +193,7 @@ func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.Vir // VirtualizationCopyTo copy things to virtualization func (e *Engine) VirtualizationCopyTo(ctx context.Context, ID, path string, content io.Reader, AllowOverwriteDirWithFile, CopyUIDGID bool) error { - return e.client.CopyToContainer(ctx, ID, path, content, dockertypes.CopyToContainerOptions{AllowOverwriteDirWithFile: AllowOverwriteDirWithFile, CopyUIDGID: CopyUIDGID}) + return e.client.CopyToContainer(ctx, ID, filepath.Dir(path), content, dockertypes.CopyToContainerOptions{AllowOverwriteDirWithFile: AllowOverwriteDirWithFile, CopyUIDGID: CopyUIDGID}) } // VirtualizationStart start virtualization diff --git a/engine/systemd/systemd.go b/engine/systemd/systemd.go index d55f91bda..4268f225b 100644 --- a/engine/systemd/systemd.go +++ b/engine/systemd/systemd.go @@ -13,6 +13,8 @@ import ( enginetypes "github.com/projecteru2/core/engine/types" coretypes "github.com/projecteru2/core/types" "golang.org/x/crypto/ssh" + + log "github.com/sirupsen/logrus" ) const ( @@ -102,6 +104,7 @@ func (s *SystemdSSH) ResourceValidate(ctx context.Context, cpu float64, cpumap m func (s *SystemdSSH) runSingleCommand(ctx context.Context, cmd string, stdin io.Reader) (stdout, stderr *bytes.Buffer, err error) { // what a pathetic library that leaves context completely useless + log.Debugf("[runSingleCommand] %s", cmd) stdout = &bytes.Buffer{} stderr = &bytes.Buffer{} diff --git a/engine/systemd/virtualization.go b/engine/systemd/virtualization.go index 1f6264e4c..f0c35eb13 100644 --- a/engine/systemd/virtualization.go +++ b/engine/systemd/virtualization.go @@ -25,7 +25,16 @@ const ( func (s *SystemdSSH) VirtualizationCreate(ctx context.Context, opts *enginetypes.VirtualizationCreateOptions) (created *enginetypes.VirtualizationCreated, err error) { ID := "SYSTEMD-" + utils.RandomString(46) - buffer, err := s.newUnitBuilder(ID, opts).buildUnit().buildPreExec().buildExec().buildPostExec().buffer() + + cpuAmount, err := s.CPUInfo(ctx) + if err != nil { + return + } + buffer, err := s.newUnitBuilder(ID, opts).buildUnit().buildPreExec(cpuAmount).buildExec().buildPostExec().buffer() + if err != nil { + return + } + // cp - /usr/local/lib/systemd/system/ if err = s.VirtualizationCopyTo(ctx, "", getUnitFilename(ID), buffer, true, true); err != nil { return