1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Upload or download gzipped and bzipped images with put/pull -j/-b

This commit is contained in:
Solomon Hykes 2013-02-12 22:23:14 -08:00
parent f20deac47f
commit 059837c92a
3 changed files with 47 additions and 8 deletions

View file

@ -291,7 +291,20 @@ func (srv *Server) CmdKill(stdin io.ReadCloser, stdout io.Writer, args ...string
}
func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
if len(args) < 1 {
cmd := rcli.Subcmd(stdout, "pull", "[OPTIONS] NAME", "Download a new image from a remote location")
fl_bzip2 := cmd.Bool("j", false, "Bzip2 compression")
fl_gzip := cmd.Bool("z", false, "Gzip compression")
if err := cmd.Parse(args); err != nil {
return nil
}
var compression image.Compression
if *fl_bzip2 {
compression = image.Bzip2
} else if *fl_gzip {
compression = image.Gzip
}
name := cmd.Arg(0)
if name == "" {
return errors.New("Not enough arguments")
}
resp, err := http.Get(args[0])
@ -307,10 +320,23 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string
}
func (srv *Server) CmdPut(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
if len(args) < 1 {
cmd := rcli.Subcmd(stdout, "put", "[OPTIONS] NAME", "Import a new image from a local archive.")
fl_bzip2 := cmd.Bool("j", false, "Bzip2 compression")
fl_gzip := cmd.Bool("z", false, "Gzip compression")
if err := cmd.Parse(args); err != nil {
return nil
}
var compression image.Compression
if *fl_bzip2 {
compression = image.Bzip2
} else if *fl_gzip {
compression = image.Gzip
}
name := cmd.Arg(0)
if name == "" {
return errors.New("Not enough arguments")
}
img, err := srv.images.Import(args[0], stdin, stdout, nil)
img, err := srv.images.Import(name, stdin, stdout, nil, compression)
if err != nil {
return err
}
@ -470,7 +496,7 @@ func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout io.Writer, args ...stri
}
// Create a new image from the container's base layers + a new layer from container changes
parentImg := srv.images.Find(container.GetUserData("image"))
img, err := srv.images.Import(imgName, rwTar, stdout, parentImg)
img, err := srv.images.Import(imgName, rwTar, stdout, parentImg, image.Uncompressed)
if err != nil {
return err
}

View file

@ -41,9 +41,16 @@ func New(root string) (*Store, error) {
}, nil
}
type Compression uint32
func (store *Store) Import(name string, archive io.Reader, stderr io.Writer, parent *Image) (*Image, error) {
layer, err := store.Layers.AddLayer(archive, stderr)
const (
Uncompressed Compression = iota
Bzip2
Gzip
)
func (store *Store) Import(name string, archive io.Reader, stderr io.Writer, parent *Image, compression Compression) (*Image, error) {
layer, err := store.Layers.AddLayer(archive, stderr, compression)
if err != nil {
return nil, err
}

View file

@ -82,13 +82,19 @@ func (store *LayerStore) layerPath(id string) string {
}
func (store *LayerStore) AddLayer(archive io.Reader, stderr io.Writer) (string, error) {
func (store *LayerStore) AddLayer(archive io.Reader, stderr io.Writer, compression Compression) (string, error) {
tmp, err := store.Mktemp()
defer os.RemoveAll(tmp)
if err != nil {
return "", err
}
untarCmd := exec.Command("tar", "-C", tmp, "-x")
extractFlags := "-x"
if compression == Bzip2 {
extractFlags += "j"
} else if compression == Gzip {
extractFlags += "z"
}
untarCmd := exec.Command("tar", "-C", tmp, extractFlags)
untarW, err := untarCmd.StdinPipe()
if err != nil {
return "", err