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

Merge remote-tracking branch 'dotcloud/master' into dhrp/docs

Conflicts:
	docs/sources/examples/python_web_app.rst
This commit is contained in:
Thatcher Peskens 2013-03-28 12:48:32 -07:00
commit 09910785c8
3 changed files with 44 additions and 4 deletions

View file

@ -24,9 +24,9 @@ We set a URL variable that points to a tarball of a simple helloflask web app
.. code-block:: bash .. code-block:: bash
BUILD_JOB=$(docker run -t shykes/pybuilder:1d9aab3737242c65 /usr/local/bin/buildapp $URL) BUILD_JOB=$(docker run -d -t shykes/pybuilder:latest /usr/local/bin/buildapp $URL)
Inside of the "shykes/pybuilder" image there is a command called buildapp, we are running that command and passing the $URL variable from step 2 to it, and running the whole thing inside of a new container. BUILD_JOB will be set with the new container_id. "1d9aab3737242c65" came from the output of step 1 when importing image. also available from 'docker images'. Inside of the "shykes/pybuilder" image there is a command called buildapp, we are running that command and passing the $URL variable from step 2 to it, and running the whole thing inside of a new container. BUILD_JOB will be set with the new container_id.
.. code-block:: bash .. code-block:: bash
@ -43,7 +43,7 @@ Save the changed we just made in the container to a new image called "_/builds/g
.. code-block:: bash .. code-block:: bash
WEB_WORKER=$(docker run -p 5000 $BUILD_IMG /usr/local/bin/runapp) WEB_WORKER=$(docker run -d -p 5000 $BUILD_IMG /usr/local/bin/runapp)
Use the new image we just created and create a new container with network port 5000, and return the container id and store in the WEB_WORKER variable. Use the new image we just created and create a new container with network port 5000, and return the container id and store in the WEB_WORKER variable.

View file

@ -110,12 +110,44 @@ func (graph *Graph) Garbage() (*Graph, error) {
return NewGraph(path.Join(graph.Root, ":garbage:")) return NewGraph(path.Join(graph.Root, ":garbage:"))
} }
// Check if given error is "not empty"
// Note: this is the way golang do it internally with os.IsNotExists
func isNotEmpty(err error) bool {
switch pe := err.(type) {
case nil:
return false
case *os.PathError:
err = pe.Err
case *os.LinkError:
err = pe.Err
}
return strings.Contains(err.Error(), " not empty")
}
func (graph *Graph) Delete(id string) error { func (graph *Graph) Delete(id string) error {
garbage, err := graph.Garbage() garbage, err := graph.Garbage()
if err != nil { if err != nil {
return err return err
} }
return os.Rename(graph.imageRoot(id), garbage.imageRoot(id)) err = os.Rename(graph.imageRoot(id), garbage.imageRoot(id))
if err != nil {
if isNotEmpty(err) {
Debugf("The image %s is already present in garbage. Removing it.", id)
if err = os.RemoveAll(garbage.imageRoot(id)); err != nil {
Debugf("Error while removing the image %s from garbage: %s\n", id, err)
return err
}
Debugf("Image %s removed from garbage", id)
if err = os.Rename(graph.imageRoot(id), garbage.imageRoot(id)); err != nil {
return err
}
Debugf("Image %s put in the garbage", id)
} else {
Debugf("Error putting the image %s to garbage: %s\n", id, err)
}
return err
}
return nil
} }
func (graph *Graph) Undelete(id string) error { func (graph *Graph) Undelete(id string) error {

View file

@ -158,6 +158,14 @@ func TestDelete(t *testing.T) {
} }
assertNImages(graph, t, 1) assertNImages(graph, t, 1)
// Test delete twice (pull -> rm -> pull -> rm)
if err := graph.Register(archive, img1); err != nil {
t.Fatal(err)
}
if err := graph.Delete(img1.Id); err != nil {
t.Fatal(err)
}
assertNImages(graph, t, 1)
} }
func assertNImages(graph *Graph, t *testing.T, n int) { func assertNImages(graph *Graph, t *testing.T, n int) {