mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
added push hijack (wip)
This commit is contained in:
parent
1aa7f1392d
commit
6ce475dbdf
4 changed files with 50 additions and 11 deletions
34
api.go
34
api.go
|
@ -1,6 +1,7 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
_"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -251,6 +252,39 @@ func ListenAndServe(addr string, rtime *Runtime) error {
|
|||
}
|
||||
})
|
||||
|
||||
r.Path("/pull").Methods("GET", "POST").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in PullIn
|
||||
//json.NewDecoder(r.Body).Decode(&in)
|
||||
in.Name = "base"
|
||||
|
||||
hj, ok := w.(http.Hijacker)
|
||||
if !ok {
|
||||
http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
conn, bufrw, err := hj.Hijack()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// Don't forget to close the connection:
|
||||
defer conn.Close()
|
||||
|
||||
|
||||
|
||||
if rtime.graph.LookupRemoteImage(in.Name, rtime.authConfig) {
|
||||
if err := rtime.graph.PullImage(bufrw, in.Name, rtime.authConfig); err != nil {
|
||||
//http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err := rtime.graph.PullRepository(bufrw, in.Name, "", rtime.repositories, rtime.authConfig); err != nil {
|
||||
//http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
})
|
||||
|
||||
|
||||
r.Path("/containers/{name:.*}/restart").Methods("POST").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println(r.RequestURI)
|
||||
vars := mux.Vars(r)
|
||||
|
|
|
@ -51,6 +51,10 @@ type PsOut struct {
|
|||
Status string `json:",omitempty"`
|
||||
}
|
||||
|
||||
type PullIn struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type LogsIn struct {
|
||||
Name string
|
||||
}
|
||||
|
|
12
commands.go
12
commands.go
|
@ -613,15 +613,15 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string
|
|||
|
||||
// FIXME: CmdPull should be a wrapper around Runtime.Pull()
|
||||
if srv.runtime.graph.LookupRemoteImage(remote, srv.runtime.authConfig) {
|
||||
if err := srv.runtime.graph.PullImage(stdout, remote, srv.runtime.authConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
// if err := srv.runtime.graph.PullImage(stdout, remote, srv.runtime.authConfig); err != nil {
|
||||
// return err
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
// FIXME: Allow pull repo:tag
|
||||
if err := srv.runtime.graph.PullRepository(stdout, remote, "", srv.runtime.repositories, srv.runtime.authConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
//if err := srv.runtime.graph.PullRepository(stdout, remote, "", srv.runtime.repositories, srv.runtime.authConfig); err != nil {
|
||||
// return err
|
||||
//}
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
|
11
registry.go
11
registry.go
|
@ -1,6 +1,7 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/auth"
|
||||
|
@ -94,10 +95,10 @@ func (graph *Graph) LookupRemoteImage(imgId string, authConfig *auth.AuthConfig)
|
|||
|
||||
// Retrieve an image from the Registry.
|
||||
// Returns the Image object as well as the layer as an Archive (io.Reader)
|
||||
func (graph *Graph) getRemoteImage(stdout io.Writer, imgId string, authConfig *auth.AuthConfig) (*Image, Archive, error) {
|
||||
func (graph *Graph) getRemoteImage(stdout *bufio.ReadWriter, imgId string, authConfig *auth.AuthConfig) (*Image, Archive, error) {
|
||||
client := &http.Client{}
|
||||
|
||||
fmt.Fprintf(stdout, "Pulling %s metadata\r\n", imgId)
|
||||
fmt.Fprintf(stdout, "Pulling %s metadata\r\n", imgId);stdout.Flush()
|
||||
// Get the Json
|
||||
req, err := http.NewRequest("GET", REGISTRY_ENDPOINT+"/images/"+imgId+"/json", nil)
|
||||
if err != nil {
|
||||
|
@ -125,7 +126,7 @@ func (graph *Graph) getRemoteImage(stdout io.Writer, imgId string, authConfig *a
|
|||
img.Id = imgId
|
||||
|
||||
// Get the layer
|
||||
fmt.Fprintf(stdout, "Pulling %s fs layer\r\n", imgId)
|
||||
fmt.Fprintf(stdout, "Pulling %s fs layer\r\n", imgId);stdout.Flush()
|
||||
req, err = http.NewRequest("GET", REGISTRY_ENDPOINT+"/images/"+imgId+"/layer", nil)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Error while getting from the server: %s\n", err)
|
||||
|
@ -138,7 +139,7 @@ func (graph *Graph) getRemoteImage(stdout io.Writer, imgId string, authConfig *a
|
|||
return img, ProgressReader(res.Body, int(res.ContentLength), stdout), nil
|
||||
}
|
||||
|
||||
func (graph *Graph) PullImage(stdout io.Writer, imgId string, authConfig *auth.AuthConfig) error {
|
||||
func (graph *Graph) PullImage(stdout *bufio.ReadWriter, imgId string, authConfig *auth.AuthConfig) error {
|
||||
history, err := graph.getRemoteHistory(imgId, authConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -161,7 +162,7 @@ func (graph *Graph) PullImage(stdout io.Writer, imgId string, authConfig *auth.A
|
|||
}
|
||||
|
||||
// FIXME: Handle the askedTag parameter
|
||||
func (graph *Graph) PullRepository(stdout io.Writer, remote, askedTag string, repositories *TagStore, authConfig *auth.AuthConfig) error {
|
||||
func (graph *Graph) PullRepository(stdout *bufio.ReadWriter, remote, askedTag string, repositories *TagStore, authConfig *auth.AuthConfig) error {
|
||||
client := &http.Client{}
|
||||
|
||||
fmt.Fprintf(stdout, "Pulling repository %s\r\n", remote)
|
||||
|
|
Loading…
Reference in a new issue