Przeglądaj źródła

dockerfile: get rid of Commit and CommitConfig

Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit 400e4922cbd004b93774fc55005f74bd8a995242)
Tibor Vass 9 lat temu
rodzic
commit
2a2d1f57b5
2 zmienionych plików z 18 dodań i 52 usunięć
  1. 18 10
      api/server/router/local/image.go
  2. 0 42
      builder/dockerfile/builder.go

+ 18 - 10
api/server/router/local/image.go

@@ -52,22 +52,30 @@ func (s *router) postCommit(ctx context.Context, w http.ResponseWriter, r *http.
 	if err != nil && err != io.EOF { //Do not fail if body is empty.
 		return err
 	}
-
-	commitCfg := &dockerfile.CommitConfig{
-		Pause:   pause,
-		Repo:    r.Form.Get("repo"),
-		Tag:     r.Form.Get("tag"),
-		Author:  r.Form.Get("author"),
-		Comment: r.Form.Get("comment"),
-		Changes: r.Form["changes"],
-		Config:  c,
+	if c == nil {
+		c = &runconfig.Config{}
 	}
 
 	if !s.daemon.Exists(cname) {
 		return derr.ErrorCodeNoSuchContainer.WithArgs(cname)
 	}
 
-	imgID, err := dockerfile.Commit(cname, s.daemon, commitCfg)
+	newConfig, err := dockerfile.BuildFromConfig(c, r.Form["changes"])
+	if err != nil {
+		return err
+	}
+
+	commitCfg := &types.ContainerCommitConfig{
+		Pause:        pause,
+		Repo:         r.Form.Get("repo"),
+		Tag:          r.Form.Get("tag"),
+		Author:       r.Form.Get("author"),
+		Comment:      r.Form.Get("comment"),
+		Config:       newConfig,
+		MergeConfigs: true,
+	}
+
+	imgID, err := s.daemon.Commit(cname, commitCfg)
 	if err != nil {
 		return err
 	}

+ 0 - 42
builder/dockerfile/builder.go

@@ -10,10 +10,8 @@ import (
 	"sync"
 
 	"github.com/Sirupsen/logrus"
-	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/builder"
 	"github.com/docker/docker/builder/dockerfile/parser"
-	"github.com/docker/docker/daemon"
 	"github.com/docker/docker/pkg/stringid"
 	"github.com/docker/docker/pkg/ulimit"
 	"github.com/docker/docker/runconfig"
@@ -209,17 +207,6 @@ func (b *Builder) Cancel() {
 	})
 }
 
-// CommitConfig contains build configs for commit operation
-type CommitConfig struct {
-	Pause   bool
-	Repo    string
-	Tag     string
-	Author  string
-	Comment string
-	Changes []string
-	Config  *runconfig.Config
-}
-
 // BuildFromConfig will do build directly from parameter 'changes', which comes
 // from Dockerfile entries, it will:
 // - call parse.Parse() to get AST root from Dockerfile entries
@@ -255,32 +242,3 @@ func BuildFromConfig(config *runconfig.Config, changes []string) (*runconfig.Con
 
 	return b.runConfig, nil
 }
-
-// Commit will create a new image from a container's changes
-// TODO: remove daemon, make Commit a method on *Builder ?
-func Commit(containerName string, d *daemon.Daemon, c *CommitConfig) (string, error) {
-	if c.Config == nil {
-		c.Config = &runconfig.Config{}
-	}
-
-	newConfig, err := BuildFromConfig(c.Config, c.Changes)
-	if err != nil {
-		return "", err
-	}
-
-	commitCfg := &types.ContainerCommitConfig{
-		Pause:        c.Pause,
-		Repo:         c.Repo,
-		Tag:          c.Tag,
-		Author:       c.Author,
-		Comment:      c.Comment,
-		Config:       newConfig,
-		MergeConfigs: true,
-	}
-
-	imgID, err := d.Commit(containerName, commitCfg)
-	if err != nil {
-		return "", err
-	}
-	return imgID, nil
-}