mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Replaced 'pull' and 'put' with 'import'
This commit is contained in:
parent
2548722dae
commit
132ecb2482
1 changed files with 33 additions and 45 deletions
|
@ -1,15 +1,15 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker"
|
|
||||||
"github.com/dotcloud/docker/fs"
|
|
||||||
"github.com/dotcloud/docker/future"
|
|
||||||
"github.com/dotcloud/docker/rcli"
|
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/dotcloud/docker"
|
||||||
|
"github.com/dotcloud/docker/fs"
|
||||||
|
"github.com/dotcloud/docker/future"
|
||||||
|
"github.com/dotcloud/docker/rcli"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -42,8 +42,7 @@ func (srv *Server) Help() string {
|
||||||
for _, cmd := range [][]interface{}{
|
for _, cmd := range [][]interface{}{
|
||||||
{"run", "Run a command in a container"},
|
{"run", "Run a command in a container"},
|
||||||
{"ps", "Display a list of containers"},
|
{"ps", "Display a list of containers"},
|
||||||
{"pull", "Download a tarball and create a container from it"},
|
{"import", "Create a new filesystem image from the contents of a tarball"},
|
||||||
{"put", "Upload a tarball and create a container from it"},
|
|
||||||
{"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"},
|
{"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"},
|
||||||
{"rm", "Remove containers"},
|
{"rm", "Remove containers"},
|
||||||
{"kill", "Kill a running container"},
|
{"kill", "Kill a running container"},
|
||||||
|
@ -401,36 +400,42 @@ func (srv *Server) CmdKill(stdin io.ReadCloser, stdout io.Writer, args ...string
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
func (srv *Server) CmdImport(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
||||||
cmd := rcli.Subcmd(stdout, "pull", "[OPTIONS] NAME", "Download a new image from a remote location")
|
cmd := rcli.Subcmd(stdout, "import", "[OPTIONS] NAME", "Create a new filesystem image from the contents of a tarball")
|
||||||
|
fl_stdin := cmd.Bool("stdin", false, "Read tarball from stdin")
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
var archive io.Reader
|
||||||
name := cmd.Arg(0)
|
name := cmd.Arg(0)
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return errors.New("Not enough arguments")
|
return errors.New("Not enough arguments")
|
||||||
}
|
}
|
||||||
u, err := url.Parse(name)
|
if *fl_stdin {
|
||||||
if err != nil {
|
archive = stdin
|
||||||
return err
|
} else {
|
||||||
}
|
u, err := url.Parse(name)
|
||||||
if u.Scheme == "" {
|
if err != nil {
|
||||||
u.Scheme = "http"
|
|
||||||
}
|
|
||||||
// FIXME: hardcode a mirror URL that does not depend on a single provider.
|
|
||||||
if u.Host == "" {
|
|
||||||
u.Host = "s3.amazonaws.com"
|
|
||||||
u.Path = path.Join("/docker.io/images", u.Path)
|
|
||||||
}
|
|
||||||
fmt.Fprintf(stdout, "Downloading from %s\n", u.String())
|
|
||||||
// Download with curl (pretty progress bar)
|
|
||||||
// If curl is not available, fallback to http.Get()
|
|
||||||
archive, err := future.Curl(u.String(), stdout)
|
|
||||||
if err != nil {
|
|
||||||
if resp, err := http.Get(u.String()); err != nil {
|
|
||||||
return err
|
return err
|
||||||
} else {
|
}
|
||||||
archive = resp.Body
|
if u.Scheme == "" {
|
||||||
|
u.Scheme = "http"
|
||||||
|
}
|
||||||
|
// FIXME: hardcode a mirror URL that does not depend on a single provider.
|
||||||
|
if u.Host == "" {
|
||||||
|
u.Host = "s3.amazonaws.com"
|
||||||
|
u.Path = path.Join("/docker.io/images", u.Path)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(stdout, "Downloading from %s\n", u.String())
|
||||||
|
// Download with curl (pretty progress bar)
|
||||||
|
// If curl is not available, fallback to http.Get()
|
||||||
|
archive, err = future.Curl(u.String(), stdout)
|
||||||
|
if err != nil {
|
||||||
|
if resp, err := http.Get(u.String()); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
archive = resp.Body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprintf(stdout, "Unpacking to %s\n", name)
|
fmt.Fprintf(stdout, "Unpacking to %s\n", name)
|
||||||
|
@ -442,23 +447,6 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) CmdPut(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
|
||||||
cmd := rcli.Subcmd(stdout, "put", "[OPTIONS] NAME", "Import a new image from a local archive.")
|
|
||||||
if err := cmd.Parse(args); err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
name := cmd.Arg(0)
|
|
||||||
if name == "" {
|
|
||||||
return errors.New("Not enough arguments")
|
|
||||||
}
|
|
||||||
img, err := srv.images.Create(stdin, nil, name, "")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Fprintln(stdout, img.Id)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
||||||
cmd := rcli.Subcmd(stdout, "images", "[OPTIONS] [NAME]", "List images")
|
cmd := rcli.Subcmd(stdout, "images", "[OPTIONS] [NAME]", "List images")
|
||||||
limit := cmd.Int("l", 0, "Only show the N most recent versions of each image")
|
limit := cmd.Int("l", 0, "Only show the N most recent versions of each image")
|
||||||
|
|
Loading…
Add table
Reference in a new issue