Browse code

Merge pull request #21268 from calavera/remove_dockerfile_from_api

Remove dockerfile dependency from the API.

Sebastiaan van Stijn authored on 2016/03/24 11:34:21
Showing 7 changed files
... ...
@@ -3,9 +3,9 @@ package image
3 3
 import (
4 4
 	"io"
5 5
 
6
+	"github.com/docker/docker/api/types/backend"
6 7
 	"github.com/docker/docker/reference"
7 8
 	"github.com/docker/engine-api/types"
8
-	"github.com/docker/engine-api/types/container"
9 9
 	"github.com/docker/engine-api/types/registry"
10 10
 	"golang.org/x/net/context"
11 11
 )
... ...
@@ -20,7 +20,7 @@ type Backend interface {
20 20
 }
21 21
 
22 22
 type containerBackend interface {
23
-	Commit(name string, config *types.ContainerCommitConfig) (imageID string, err error)
23
+	Commit(name string, config *backend.ContainerCommitConfig) (imageID string, err error)
24 24
 }
25 25
 
26 26
 type imageBackend interface {
... ...
@@ -33,7 +33,7 @@ type imageBackend interface {
33 33
 
34 34
 type importExportBackend interface {
35 35
 	LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error
36
-	ImportImage(src string, newRef reference.Named, msg string, inConfig io.ReadCloser, outStream io.Writer, config *container.Config) error
36
+	ImportImage(src string, newRef reference.Named, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error
37 37
 	ExportImage(names []string, outStream io.Writer) error
38 38
 }
39 39
 
... ...
@@ -13,7 +13,7 @@ import (
13 13
 	"github.com/docker/distribution/digest"
14 14
 	"github.com/docker/distribution/registry/api/errcode"
15 15
 	"github.com/docker/docker/api/server/httputils"
16
-	"github.com/docker/docker/builder/dockerfile"
16
+	"github.com/docker/docker/api/types/backend"
17 17
 	"github.com/docker/docker/pkg/ioutils"
18 18
 	"github.com/docker/docker/pkg/streamformatter"
19 19
 	"github.com/docker/docker/reference"
... ...
@@ -48,19 +48,17 @@ func (s *imageRouter) postCommit(ctx context.Context, w http.ResponseWriter, r *
48 48
 		c = &container.Config{}
49 49
 	}
50 50
 
51
-	newConfig, err := dockerfile.BuildFromConfig(c, r.Form["changes"])
52
-	if err != nil {
53
-		return err
54
-	}
55
-
56
-	commitCfg := &types.ContainerCommitConfig{
57
-		Pause:        pause,
58
-		Repo:         r.Form.Get("repo"),
59
-		Tag:          r.Form.Get("tag"),
60
-		Author:       r.Form.Get("author"),
61
-		Comment:      r.Form.Get("comment"),
62
-		Config:       newConfig,
63
-		MergeConfigs: true,
51
+	commitCfg := &backend.ContainerCommitConfig{
52
+		ContainerCommitConfig: types.ContainerCommitConfig{
53
+			Pause:        pause,
54
+			Repo:         r.Form.Get("repo"),
55
+			Tag:          r.Form.Get("tag"),
56
+			Author:       r.Form.Get("author"),
57
+			Comment:      r.Form.Get("comment"),
58
+			Config:       c,
59
+			MergeConfigs: true,
60
+		},
61
+		Changes: r.Form["changes"],
64 62
 	}
65 63
 
66 64
 	imgID, err := s.backend.Commit(cname, commitCfg)
... ...
@@ -160,17 +158,10 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite
160 160
 		}
161 161
 
162 162
 		src := r.Form.Get("fromSrc")
163
-
164 163
 		// 'err' MUST NOT be defined within this block, we need any error
165 164
 		// generated from the download to be available to the output
166 165
 		// stream processing below
167
-		var newConfig *container.Config
168
-		newConfig, err = dockerfile.BuildFromConfig(&container.Config{}, r.Form["changes"])
169
-		if err != nil {
170
-			return err
171
-		}
172
-
173
-		err = s.backend.ImportImage(src, newRef, message, r.Body, output, newConfig)
166
+		err = s.backend.ImportImage(src, newRef, message, r.Body, output, r.Form["changes"])
174 167
 	}
175 168
 	if err != nil {
176 169
 		if !output.Flushed() {
... ...
@@ -67,3 +67,11 @@ type ExecProcessConfig struct {
67 67
 	Privileged *bool    `json:"privileged,omitempty"`
68 68
 	User       string   `json:"user,omitempty"`
69 69
 }
70
+
71
+// ContainerCommitConfig is a wrapper around
72
+// types.ContainerCommitConfig that also
73
+// transports configuration changes for a container.
74
+type ContainerCommitConfig struct {
75
+	types.ContainerCommitConfig
76
+	Changes []string
77
+}
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"os"
10 10
 	"time"
11 11
 
12
+	"github.com/docker/docker/api/types/backend"
12 13
 	"github.com/docker/docker/reference"
13 14
 	"github.com/docker/engine-api/types"
14 15
 	"github.com/docker/engine-api/types/container"
... ...
@@ -118,7 +119,7 @@ type Backend interface {
118 118
 	// ContainerRm removes a container specified by `id`.
119 119
 	ContainerRm(name string, config *types.ContainerRmConfig) error
120 120
 	// Commit creates a new Docker image from an existing Docker container.
121
-	Commit(string, *types.ContainerCommitConfig) (string, error)
121
+	Commit(string, *backend.ContainerCommitConfig) (string, error)
122 122
 	// Kill stops the container execution abruptly.
123 123
 	ContainerKill(containerID string, sig uint64) error
124 124
 	// Start starts a new container
... ...
@@ -19,6 +19,7 @@ import (
19 19
 	"time"
20 20
 
21 21
 	"github.com/Sirupsen/logrus"
22
+	"github.com/docker/docker/api/types/backend"
22 23
 	"github.com/docker/docker/builder"
23 24
 	"github.com/docker/docker/builder/dockerfile/parser"
24 25
 	"github.com/docker/docker/pkg/archive"
... ...
@@ -84,10 +85,12 @@ func (b *Builder) commit(id string, autoCmd strslice.StrSlice, comment string) e
84 84
 	autoConfig := *b.runConfig
85 85
 	autoConfig.Cmd = autoCmd
86 86
 
87
-	commitCfg := &types.ContainerCommitConfig{
88
-		Author: b.maintainer,
89
-		Pause:  true,
90
-		Config: &autoConfig,
87
+	commitCfg := &backend.ContainerCommitConfig{
88
+		ContainerCommitConfig: types.ContainerCommitConfig{
89
+			Author: b.maintainer,
90
+			Pause:  true,
91
+			Config: &autoConfig,
92
+		},
91 93
 	}
92 94
 
93 95
 	// Commit the container
... ...
@@ -7,6 +7,8 @@ import (
7 7
 	"strings"
8 8
 	"time"
9 9
 
10
+	"github.com/docker/docker/api/types/backend"
11
+	"github.com/docker/docker/builder/dockerfile"
10 12
 	"github.com/docker/docker/container"
11 13
 	"github.com/docker/docker/dockerversion"
12 14
 	"github.com/docker/docker/image"
... ...
@@ -14,7 +16,6 @@ import (
14 14
 	"github.com/docker/docker/pkg/archive"
15 15
 	"github.com/docker/docker/pkg/ioutils"
16 16
 	"github.com/docker/docker/reference"
17
-	"github.com/docker/engine-api/types"
18 17
 	containertypes "github.com/docker/engine-api/types/container"
19 18
 	"github.com/docker/go-connections/nat"
20 19
 )
... ...
@@ -98,7 +99,7 @@ func merge(userConf, imageConf *containertypes.Config) error {
98 98
 
99 99
 // Commit creates a new filesystem image from the current state of a container.
100 100
 // The image can optionally be tagged into a repository.
101
-func (daemon *Daemon) Commit(name string, c *types.ContainerCommitConfig) (string, error) {
101
+func (daemon *Daemon) Commit(name string, c *backend.ContainerCommitConfig) (string, error) {
102 102
 	container, err := daemon.GetContainer(name)
103 103
 	if err != nil {
104 104
 		return "", err
... ...
@@ -114,8 +115,13 @@ func (daemon *Daemon) Commit(name string, c *types.ContainerCommitConfig) (strin
114 114
 		defer daemon.containerUnpause(container)
115 115
 	}
116 116
 
117
+	newConfig, err := dockerfile.BuildFromConfig(c.Config, c.Changes)
118
+	if err != nil {
119
+		return "", err
120
+	}
121
+
117 122
 	if c.MergeConfigs {
118
-		if err := merge(c.Config, container.Config); err != nil {
123
+		if err := merge(newConfig, container.Config); err != nil {
119 124
 			return "", err
120 125
 		}
121 126
 	}
... ...
@@ -166,7 +172,7 @@ func (daemon *Daemon) Commit(name string, c *types.ContainerCommitConfig) (strin
166 166
 	config, err := json.Marshal(&image.Image{
167 167
 		V1Image: image.V1Image{
168 168
 			DockerVersion:   dockerversion.Version,
169
-			Config:          c.Config,
169
+			Config:          newConfig,
170 170
 			Architecture:    runtime.GOARCH,
171 171
 			OS:              runtime.GOOS,
172 172
 			Container:       container.ID,
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"runtime"
9 9
 	"time"
10 10
 
11
+	"github.com/docker/docker/builder/dockerfile"
11 12
 	"github.com/docker/docker/dockerversion"
12 13
 	"github.com/docker/docker/image"
13 14
 	"github.com/docker/docker/layer"
... ...
@@ -23,13 +24,17 @@ import (
23 23
 // inConfig (if src is "-"), or from a URI specified in src. Progress output is
24 24
 // written to outStream. Repository and tag names can optionally be given in
25 25
 // the repo and tag arguments, respectively.
26
-func (daemon *Daemon) ImportImage(src string, newRef reference.Named, msg string, inConfig io.ReadCloser, outStream io.Writer, config *container.Config) error {
26
+func (daemon *Daemon) ImportImage(src string, newRef reference.Named, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error {
27 27
 	var (
28 28
 		sf   = streamformatter.NewJSONStreamFormatter()
29 29
 		rc   io.ReadCloser
30 30
 		resp *http.Response
31 31
 	)
32 32
 
33
+	config, err := dockerfile.BuildFromConfig(&container.Config{}, changes)
34
+	if err != nil {
35
+		return err
36
+	}
33 37
 	if src == "-" {
34 38
 		rc = inConfig
35 39
 	} else {