Skip to content

Commit

Permalink
send file
Browse files Browse the repository at this point in the history
  • Loading branch information
zc authored and CMGS committed Mar 6, 2020
1 parent 0ce475f commit 669aef8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 1 addition & 3 deletions cluster/calcium/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package calcium
import (
"context"
"os"
"path/filepath"
"sync"

"github.com/projecteru2/core/engine"
Expand Down Expand Up @@ -42,13 +41,12 @@ 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)
if err != nil {
return err
}
defer f.Close()
return engine.VirtualizationCopyTo(ctx, ID, path, f, AllowOverwriteDirWithFile, CopyUIDGID)
return engine.VirtualizationCopyTo(ctx, ID, dst, f, AllowOverwriteDirWithFile, CopyUIDGID)
}
3 changes: 2 additions & 1 deletion engine/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"io/ioutil"
"path/filepath"

"github.com/docker/go-connections/nat"
"github.com/docker/go-units"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions engine/systemd/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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{}
Expand Down
11 changes: 10 additions & 1 deletion engine/systemd/virtualization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 669aef8

Please sign in to comment.