Merge branch 'master' into storage_refactor

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-06-22 09:16:49 -03:00
4 changed files with 45 additions and 10 deletions

View File

@@ -41,7 +41,11 @@ ENV DOCKER_STORAGE_DRIVER=$docker_storage_driver
# Move to our home # Move to our home
WORKDIR /root WORKDIR /root
RUN mkdir -p /var/run/pwd/certs && mkdir -p /var/run/pwd/uploads # Setup certs and ssh keys
RUN mkdir -p /var/run/pwd/certs && mkdir -p /var/run/pwd/uploads \
&& ssh-keygen -N "" -t rsa -f /etc/ssh/ssh_host_rsa_key >/dev/null \
&& mkdir ~/.ssh && ssh-keygen -N "" -t rsa -f ~/.ssh/id_rsa \
&& cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys
# Remove IPv6 alias for localhost and start docker in the background ... # Remove IPv6 alias for localhost and start docker in the background ...
CMD cat /etc/hosts >/etc/hosts.bak && \ CMD cat /etc/hosts >/etc/hosts.bak && \
@@ -53,7 +57,7 @@ CMD cat /etc/hosts >/etc/hosts.bak && \
sed -i "s/\DOCKER_TLSCERT/$DOCKER_TLSCERT/" /etc/docker/daemon.json && \ sed -i "s/\DOCKER_TLSCERT/$DOCKER_TLSCERT/" /etc/docker/daemon.json && \
sed -i "s/\DOCKER_TLSKEY/$DOCKER_TLSKEY/" /etc/docker/daemon.json && \ sed -i "s/\DOCKER_TLSKEY/$DOCKER_TLSKEY/" /etc/docker/daemon.json && \
umount /var/lib/docker && mount -t securityfs none /sys/kernel/security && \ umount /var/lib/docker && mount -t securityfs none /sys/kernel/security && \
echo "root:root" | chpasswd &> /dev/null && ssh-keygen -N "" -t rsa -f /etc/ssh/ssh_host_rsa_key >/dev/null && \ echo "root:root" | chpasswd &> /dev/null && \
/usr/sbin/sshd -o PermitRootLogin=yes -o PrintMotd=no 2>/dev/null && \ /usr/sbin/sshd -o PermitRootLogin=yes -o PrintMotd=no 2>/dev/null && \
dockerd &>/docker.log & \ dockerd &>/docker.log & \
while true ; do script -q -c "/bin/bash -l" /dev/null ; done while true ; do script -q -c "/bin/bash -l" /dev/null ; done

View File

@@ -1,6 +1,7 @@
package handlers package handlers
import ( import (
"io"
"log" "log"
"net/http" "net/http"
@@ -28,18 +29,34 @@ func FileUpload(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK) rw.WriteHeader(http.StatusOK)
return return
} else { } else {
// This is for multipart upload red, err := req.MultipartReader()
log.Println("Not implemented yet") if err != nil {
log.Println(err)
/* rw.WriteHeader(http.StatusBadRequest)
err := req.ParseMultipartForm(32 << 20) return
}
for {
p, err := red.NextPart()
if err == io.EOF {
break
}
if err != nil { if err != nil {
log.Println(err) log.Println(err)
rw.WriteHeader(http.StatusBadRequest) continue
}
if p.FileName() == "" {
continue
}
err = core.InstanceUploadFromReader(i, p.FileName(), p)
if err != nil {
log.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
return return
} }
*/ log.Printf("Uploaded [%s] to [%s]\n", p.FileName(), i.Name)
rw.WriteHeader(http.StatusInternalServerError) }
rw.WriteHeader(http.StatusOK)
return return
} }

View File

@@ -82,6 +82,18 @@ func (p *pwd) InstanceUploadFromUrl(instance *types.Instance, url string) error
return nil return nil
} }
func (p *pwd) InstanceUploadFromReader(instance *types.Instance, fileName string, reader io.Reader) error {
defer observeAction("InstanceUploadFromReader", time.Now())
copyErr := p.docker.CopyToContainer(instance.Name, "/var/run/pwd/uploads", fileName, reader)
if copyErr != nil {
return fmt.Errorf("Error while uploading file [%s]. Error: %s\n", fileName, copyErr)
}
return nil
}
func (p *pwd) InstanceGet(session *types.Session, name string) *types.Instance { func (p *pwd) InstanceGet(session *types.Session, name string) *types.Instance {
defer observeAction("InstanceGet", time.Now()) defer observeAction("InstanceGet", time.Now())
return session.Instances[name] return session.Instances[name]

View File

@@ -1,6 +1,7 @@
package pwd package pwd
import ( import (
"io"
"time" "time"
"github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/docker"
@@ -60,6 +61,7 @@ type PWDApi interface {
InstanceResizeTerminal(instance *types.Instance, cols, rows uint) error InstanceResizeTerminal(instance *types.Instance, cols, rows uint) error
InstanceAttachTerminal(instance *types.Instance) error InstanceAttachTerminal(instance *types.Instance) error
InstanceUploadFromUrl(instance *types.Instance, url string) error InstanceUploadFromUrl(instance *types.Instance, url string) error
InstanceUploadFromReader(instance *types.Instance, filename string, reader io.Reader) error
InstanceGet(session *types.Session, name string) *types.Instance InstanceGet(session *types.Session, name string) *types.Instance
InstanceFindByIP(ip string) *types.Instance InstanceFindByIP(ip string) *types.Instance
InstanceFindByAlias(sessionPrefix, alias string) *types.Instance InstanceFindByAlias(sessionPrefix, alias string) *types.Instance