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

'docker commit' records parent container id and command, in addition to parent image

This commit is contained in:
Solomon Hykes 2013-03-21 21:13:27 -07:00
parent 8396798eba
commit 05ae69a6eb
6 changed files with 21 additions and 15 deletions

View file

@ -384,7 +384,7 @@ func (srv *Server) CmdImport(stdin io.ReadCloser, stdout io.Writer, args ...stri
}
archive = ProgressReader(resp.Body, int(resp.ContentLength), stdout)
}
img, err := srv.runtime.graph.Create(archive, "", "Imported from "+src)
img, err := srv.runtime.graph.Create(archive, nil, "Imported from "+src)
if err != nil {
return err
}

View file

@ -46,7 +46,7 @@ func TestCommitRun(t *testing.T) {
if err != nil {
t.Error(err)
}
img, err := runtime.graph.Create(rwTar, container1.Image, "unit test commited image")
img, err := runtime.graph.Create(rwTar, container1, "unit test commited image")
if err != nil {
t.Error(err)
}

View file

@ -47,13 +47,17 @@ func (graph *Graph) Get(id string) (*Image, error) {
return img, nil
}
func (graph *Graph) Create(layerData Archive, parent, comment string) (*Image, error) {
func (graph *Graph) Create(layerData Archive, container *Container, comment string) (*Image, error) {
img := &Image{
Id: GenerateId(),
Parent: parent,
Comment: comment,
Created: time.Now(),
}
if container != nil {
img.Parent = container.Image
img.ParentContainer = container.Id
img.ParentCommand = append([]string{container.Path}, container.Args...)
}
if err := graph.Register(layerData, img); err != nil {
return nil, err
}

View file

@ -35,7 +35,7 @@ func TestGraphCreate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
image, err := graph.Create(archive, "", "Testing")
image, err := graph.Create(archive, nil, "Testing")
if err != nil {
t.Fatal(err)
}
@ -92,7 +92,7 @@ func TestMount(t *testing.T) {
if err != nil {
t.Fatal(err)
}
image, err := graph.Create(archive, "", "Testing")
image, err := graph.Create(archive, nil, "Testing")
if err != nil {
t.Fatal(err)
}
@ -128,7 +128,7 @@ func TestDelete(t *testing.T) {
t.Fatal(err)
}
assertNImages(graph, t, 0)
img, err := graph.Create(archive, "", "Bla bla")
img, err := graph.Create(archive, nil, "Bla bla")
if err != nil {
t.Fatal(err)
}
@ -139,11 +139,11 @@ func TestDelete(t *testing.T) {
assertNImages(graph, t, 0)
// Test 2 create (same name) / 1 delete
img1, err := graph.Create(archive, "foo", "Testing")
img1, err := graph.Create(archive, nil, "Testing")
if err != nil {
t.Fatal(err)
}
if _, err = graph.Create(archive, "foo", "Testing"); err != nil {
if _, err = graph.Create(archive, nil, "Testing"); err != nil {
t.Fatal(err)
}
assertNImages(graph, t, 2)

View file

@ -19,6 +19,8 @@ type Image struct {
Parent string
Comment string
Created time.Time
ParentContainer string
ParentCommand []string
graph *Graph
}

View file

@ -214,7 +214,7 @@ func (runtime *Runtime) Commit(id, repository, tag string) (*Image, error) {
return nil, err
}
// Create a new image from the container's base layers + a new layer from container changes
img, err := runtime.graph.Create(rwTar, container.Image, "")
img, err := runtime.graph.Create(rwTar, container, "")
if err != nil {
return nil, err
}