Merge branch 'next' into mongo_storage
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package pwd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -66,10 +67,11 @@ func (p *pwd) InstanceAttachTerminal(instance *types.Instance) error {
|
||||
terms[instance.SessionId][instance.Name] = conn
|
||||
}
|
||||
io.Copy(encoder.Writer(sw), conn)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *pwd) InstanceUploadFromUrl(instance *types.Instance, url string) error {
|
||||
func (p *pwd) InstanceUploadFromUrl(instance *types.Instance, fileName, dest string, url string) error {
|
||||
defer observeAction("InstanceUploadFromUrl", time.Now())
|
||||
log.Printf("Downloading file [%s]\n", url)
|
||||
resp, err := http.Get(url)
|
||||
@@ -81,9 +83,7 @@ func (p *pwd) InstanceUploadFromUrl(instance *types.Instance, url string) error
|
||||
return fmt.Errorf("Could not download file [%s]. Status code: %d\n", url, resp.StatusCode)
|
||||
}
|
||||
|
||||
_, fileName := filepath.Split(url)
|
||||
|
||||
copyErr := p.docker.CopyToContainer(instance.Name, "/var/run/pwd/uploads", fileName, resp.Body)
|
||||
copyErr := p.docker.CopyToContainer(instance.Name, dest, fileName, resp.Body)
|
||||
|
||||
if copyErr != nil {
|
||||
return fmt.Errorf("Error while downloading file [%s]. Error: %s\n", url, copyErr)
|
||||
@@ -92,10 +92,36 @@ func (p *pwd) InstanceUploadFromUrl(instance *types.Instance, url string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *pwd) InstanceUploadFromReader(instance *types.Instance, fileName string, reader io.Reader) error {
|
||||
func (p *pwd) getInstanceCWD(instance *types.Instance) (string, error) {
|
||||
b := bytes.NewBufferString("")
|
||||
|
||||
if c, err := p.docker.ExecAttach(instance.Name, []string{"bash", "-c", `pwdx $(</var/run/cwd)`}, b); c > 0 {
|
||||
log.Println(b.String())
|
||||
return "", fmt.Errorf("Error %d trying to get CWD", c)
|
||||
} else if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
cwd := strings.TrimSpace(strings.Split(b.String(), ":")[1])
|
||||
|
||||
return cwd, nil
|
||||
}
|
||||
|
||||
func (p *pwd) InstanceUploadFromReader(instance *types.Instance, fileName, dest string, reader io.Reader) error {
|
||||
defer observeAction("InstanceUploadFromReader", time.Now())
|
||||
|
||||
copyErr := p.docker.CopyToContainer(instance.Name, "/var/run/pwd/uploads", fileName, reader)
|
||||
var finalDest string
|
||||
if filepath.IsAbs(dest) {
|
||||
finalDest = dest
|
||||
} else {
|
||||
if cwd, err := p.getInstanceCWD(instance); err != nil {
|
||||
return err
|
||||
} else {
|
||||
finalDest = fmt.Sprintf("%s/%s", cwd, dest)
|
||||
}
|
||||
}
|
||||
|
||||
copyErr := p.docker.CopyToContainer(instance.Name, finalDest, fileName, reader)
|
||||
|
||||
if copyErr != nil {
|
||||
return fmt.Errorf("Error while uploading file [%s]. Error: %s\n", fileName, copyErr)
|
||||
|
||||
@@ -61,8 +61,8 @@ type PWDApi interface {
|
||||
InstanceNew(session *types.Session, conf InstanceConfig) (*types.Instance, error)
|
||||
InstanceResizeTerminal(instance *types.Instance, cols, rows uint) error
|
||||
InstanceAttachTerminal(instance *types.Instance) error
|
||||
InstanceUploadFromUrl(instance *types.Instance, url string) error
|
||||
InstanceUploadFromReader(instance *types.Instance, filename string, reader io.Reader) error
|
||||
InstanceUploadFromUrl(instance *types.Instance, fileName, dest, url string) error
|
||||
InstanceUploadFromReader(instance *types.Instance, fileName, dest string, reader io.Reader) error
|
||||
InstanceGet(session *types.Session, name string) *types.Instance
|
||||
// TODO remove this function when we add the session prefix to the PWD url
|
||||
InstanceFindByIP(ip string) *types.Instance
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"math"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -154,13 +155,15 @@ func (p *pwd) SessionDeployStack(s *types.Session) error {
|
||||
log.Printf("Error creating instance for stack [%s]: %s\n", s.Stack, err)
|
||||
return err
|
||||
}
|
||||
err = p.InstanceUploadFromUrl(i, s.Stack)
|
||||
|
||||
_, fileName := filepath.Split(s.Stack)
|
||||
err = p.InstanceUploadFromUrl(i, fileName, "/var/run/pwd/uploads", s.Stack)
|
||||
if err != nil {
|
||||
log.Printf("Error uploading stack file [%s]: %s\n", s.Stack, err)
|
||||
return err
|
||||
}
|
||||
|
||||
fileName := path.Base(s.Stack)
|
||||
fileName = path.Base(s.Stack)
|
||||
file := fmt.Sprintf("/var/run/pwd/uploads/%s", fileName)
|
||||
cmd := fmt.Sprintf("docker swarm init --advertise-addr eth0 && docker-compose -f %s pull && docker stack deploy -c %s %s", file, file, s.StackName)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user