浏览代码

Merge pull request #1291 from dotcloud/ensure_mount_commit

*Builder: Allow the commit of a non-started container
Victor Vieux 12 年之前
父节点
当前提交
16225c473f
共有 2 个文件被更改,包括 25 次插入0 次删除
  1. 4 0
      builder.go
  2. 21 0
      server_test.go

+ 4 - 0
builder.go

@@ -124,6 +124,10 @@ func (builder *Builder) Create(config *Config) (*Container, error) {
 func (builder *Builder) Commit(container *Container, repository, tag, comment, author string, config *Config) (*Image, error) {
 	// FIXME: freeze the container before copying it to avoid data corruption?
 	// FIXME: this shouldn't be in commands.
+	if err := container.EnsureMounted(); err != nil {
+		return nil, err
+	}
+
 	rwTar, err := container.ExportRw()
 	if err != nil {
 		return nil, err

+ 21 - 0
server_test.go

@@ -91,6 +91,27 @@ func TestCreateRm(t *testing.T) {
 
 }
 
+func TestCommit(t *testing.T) {
+	runtime := mkRuntime(t)
+	defer nuke(runtime)
+
+	srv := &Server{runtime: runtime}
+
+	config, _, _, err := ParseRun([]string{GetTestImage(runtime).ID, "/bin/cat"}, nil)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	id, err := srv.ContainerCreate(config)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if _, err := srv.ContainerCommit(id, "testrepo", "testtag", "", "", config); err != nil {
+		t.Fatal(err)
+	}
+}
+
 func TestCreateStartRestartStopStartKillRm(t *testing.T) {
 	runtime := mkRuntime(t)
 	defer nuke(runtime)