Skip to content

Commit

Permalink
Merge branch 'master' into 0.6.5-dm-plugin
Browse files Browse the repository at this point in the history
Conflicts:
	server.go
  • Loading branch information
crosbymichael committed Nov 20, 2013
2 parents 579a5c8 + b4f7078 commit 2382a0f
Show file tree
Hide file tree
Showing 14 changed files with 501 additions and 30 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ run apt-get install -y -q ruby1.9.3 rubygems libffi-dev
run gem install --no-rdoc --no-ri fpm
run apt-get install -y -q reprepro dpkg-sig

# Install s3cmd 1.0.1 (earlier versions don't support env variables in the config)
run apt-get install -y -q python-pip
run pip install s3cmd
run pip install python-magic
run pip install s3cmd==1.1.0-beta3
run pip install python-magic==0.4.6
run /bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEY\n' > /.s3cfg

# Runtime dependencies
Expand Down
22 changes: 22 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,26 @@ func postImagesPush(srv *Server, version float64, w http.ResponseWriter, r *http
return nil
}

func getImagesGet(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
name := vars["name"]
if version > 1.0 {
w.Header().Set("Content-Type", "application/x-tar")
}
err := srv.ImageExport(name, w)
if err != nil {
return err
}
return nil
}

func postImagesLoad(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
err := srv.ImageLoad(r.Body)
if err != nil {
return err
}
return nil
}

func postContainersCreate(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := parseForm(r); err != nil {
return nil
Expand Down Expand Up @@ -1036,6 +1056,7 @@ func createRouter(srv *Server, logging bool) (*mux.Router, error) {
"/images/json": getImagesJSON,
"/images/viz": getImagesViz,
"/images/search": getImagesSearch,
"/images/{name:.*}/get": getImagesGet,
"/images/{name:.*}/history": getImagesHistory,
"/images/{name:.*}/json": getImagesByName,
"/containers/ps": getContainersJSON,
Expand All @@ -1052,6 +1073,7 @@ func createRouter(srv *Server, logging bool) (*mux.Router, error) {
"/build": postBuild,
"/images/create": postImagesCreate,
"/images/{name:.*}/insert": postImagesInsert,
"/images/load": postImagesLoad,
"/images/{name:.*}/push": postImagesPush,
"/images/{name:.*}/tag": postImagesTag,
"/containers/create": postContainersCreate,
Expand Down
File renamed without changes.
53 changes: 47 additions & 6 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error {
{"insert", "Insert a file in an image"},
{"inspect", "Return low-level information on a container"},
{"kill", "Kill a running container"},
{"load", "Load an image from a tar archive"},
{"login", "Register or Login to the docker registry server"},
{"logs", "Fetch the logs of a container"},
{"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"},
Expand All @@ -102,6 +103,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error {
{"rm", "Remove one or more containers"},
{"rmi", "Remove one or more images"},
{"run", "Run a command in a new container"},
{"save", "Save an image to a tar archive"},
{"search", "Search for an image in the docker index"},
{"start", "Start a stopped container"},
{"stop", "Stop a running container"},
Expand Down Expand Up @@ -577,6 +579,7 @@ func (cli *DockerCli) CmdStart(args ...string) error {
}

var cErr chan error
var tty bool
if *attach || *openStdin {
if cmd.NArg() > 1 {
return fmt.Errorf("Impossible to start and attach multiple containers at once.")
Expand All @@ -593,17 +596,13 @@ func (cli *DockerCli) CmdStart(args ...string) error {
return err
}

tty = container.Config.Tty

if !container.Config.Tty {
sigc := cli.forwardAllSignals(cmd.Arg(0))
defer utils.StopCatch(sigc)
}

if container.Config.Tty && cli.isTerminal {
if err := cli.monitorTtySize(cmd.Arg(0)); err != nil {
return err
}
}

var in io.ReadCloser

v := url.Values{}
Expand Down Expand Up @@ -641,7 +640,13 @@ func (cli *DockerCli) CmdStart(args ...string) error {
}
return encounteredError
}

if *openStdin || *attach {
if tty && cli.isTerminal {
if err := cli.monitorTtySize(cmd.Arg(0)); err != nil {
utils.Errorf("Error monitoring TTY size: %s\n", err)
}
}
return <-cErr
}
return nil
Expand Down Expand Up @@ -1967,6 +1972,42 @@ func (cli *DockerCli) CmdCp(args ...string) error {
return nil
}

func (cli *DockerCli) CmdSave(args ...string) error {
cmd := Subcmd("save", "IMAGE DESTINATION", "Save an image to a tar archive")
if err := cmd.Parse(args); err != nil {
cmd.Usage()
return nil
}

if cmd.NArg() != 1 {
cmd.Usage()
return nil
}

image := cmd.Arg(0)

if err := cli.stream("GET", "/images/"+image+"/get", nil, cli.out, nil); err != nil {
return err
}
return nil
}

func (cli *DockerCli) CmdLoad(args ...string) error {
cmd := Subcmd("load", "SOURCE", "Load an image from a tar archive")

if cmd.NArg() != 0 {
cmd.Usage()
return nil
}

err := cli.stream("POST", "/images/load", cli.in, cli.out, nil)
if err != nil {
fmt.Println("Send failed", err)
}

return nil
}

func (cli *DockerCli) call(method, path string, data interface{}) ([]byte, int, error) {
var params io.Reader
if data != nil {
Expand Down
47 changes: 47 additions & 0 deletions docs/sources/api/docker_remote_api_v1.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,53 @@ Monitor Docker's events
:statuscode 200: no error
:statuscode 500: server error

Get a tarball containing all images and tags in a repository
************************************************************

.. http:get:: /images/(name)/get
Get a tarball containing all images and metadata for the repository specified by ``name``.

**Example request**

.. sourcecode:: http

GET /images/ubuntu/get

**Example response**:

.. sourcecode:: http

HTTP/1.1 200 OK
Content-Type: application/x-tar

Binary data stream
:statuscode 200: no error
:statuscode 500: server error

Load a tarball with a set of images and tags into docker
********************************************************

.. http:post:: /images/load
Load a set of images and tags into the docker repository.

**Example request**

.. sourcecode:: http

POST /images/load

Tarball in body

**Example response**:

.. sourcecode:: http

HTTP/1.1 200 OK

:statuscode 200: no error
:statuscode 500: server error

3. Going further
================
Expand Down
23 changes: 23 additions & 0 deletions docs/sources/commandline/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,18 @@ Known Issues (kill)
* :issue:`197` indicates that ``docker kill`` may leave directories
behind and make it difficult to remove the container.

.. _cli_load:

``load``
--------

::

Usage: docker load < repository.tar

Loads a tarred repository from the standard input stream.
Restores both images and tags.

.. _cli_login:

``login``
Expand Down Expand Up @@ -852,6 +864,17 @@ Known Issues (run -volumes-from)
could indicate a permissions problem with AppArmor. Please see the
issue for a workaround.

.. _cli_save:

``save``

::

Usage: docker save image > repository.tar

Streams a tarred repository to the standard output stream.
Contains all parent layers, and all tags + versions.

.. _cli_search:

``search``
Expand Down
55 changes: 55 additions & 0 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package engine

import (
"testing"
)

func TestRegister(t *testing.T) {
if err := Register("dummy1", nil); err != nil {
t.Fatal(err)
}

if err := Register("dummy1", nil); err == nil {
t.Fatalf("Expecting error, got none")
}

eng := newTestEngine(t)

//Should fail because globan handlers are copied
//at the engine creation
if err := eng.Register("dummy1", nil); err == nil {
t.Fatalf("Expecting error, got none")
}

if err := eng.Register("dummy2", nil); err != nil {
t.Fatal(err)
}

if err := eng.Register("dummy2", nil); err == nil {
t.Fatalf("Expecting error, got none")
}
}

func TestJob(t *testing.T) {
eng := newTestEngine(t)
job1 := eng.Job("dummy1", "--level=awesome")

if job1.handler != nil {
t.Fatalf("job1.handler should be empty")
}

h := func(j *Job) string {
return j.Name
}

eng.Register("dummy2", h)
job2 := eng.Job("dummy2", "--level=awesome")

if job2.handler == nil {
t.Fatalf("job2.handler shouldn't be nil")
}

if job2.handler(job2) != job2.Name {
t.Fatalf("handler dummy2 was not found in job2")
}
}
Loading

0 comments on commit 2382a0f

Please sign in to comment.