Signed-off-by: David Calavera <david.calavera@gmail.com>
| ... | ... |
@@ -3,7 +3,7 @@ package build |
| 3 | 3 |
import ( |
| 4 | 4 |
"io" |
| 5 | 5 |
|
| 6 |
- "github.com/docker/docker/builder" |
|
| 6 |
+ "github.com/docker/docker/api/types/backend" |
|
| 7 | 7 |
"github.com/docker/engine-api/types" |
| 8 | 8 |
"golang.org/x/net/context" |
| 9 | 9 |
) |
| ... | ... |
@@ -16,5 +16,5 @@ type Backend interface {
|
| 16 | 16 |
// by the caller. |
| 17 | 17 |
// |
| 18 | 18 |
// TODO: make this return a reference instead of string |
| 19 |
- Build(clientCtx context.Context, config *types.ImageBuildOptions, context builder.Context, stdout io.Writer, stderr io.Writer, out io.Writer) (string, error) |
|
| 19 |
+ BuildFromContext(ctx context.Context, src io.ReadCloser, remote string, buildOptions *types.ImageBuildOptions, pg backend.ProgressWriter) (string, error) |
|
| 20 | 20 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
"github.com/Sirupsen/logrus" |
| 15 | 15 |
"github.com/docker/docker/api/server/httputils" |
| 16 |
- "github.com/docker/docker/builder" |
|
| 16 |
+ "github.com/docker/docker/api/types/backend" |
|
| 17 | 17 |
"github.com/docker/docker/pkg/ioutils" |
| 18 | 18 |
"github.com/docker/docker/pkg/progress" |
| 19 | 19 |
"github.com/docker/docker/pkg/streamformatter" |
| ... | ... |
@@ -148,6 +148,7 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r * |
| 148 | 148 |
if err != nil {
|
| 149 | 149 |
return errf(err) |
| 150 | 150 |
} |
| 151 |
+ buildOptions.AuthConfigs = authConfigs |
|
| 151 | 152 |
|
| 152 | 153 |
remoteURL := r.FormValue("remote")
|
| 153 | 154 |
|
| ... | ... |
@@ -161,21 +162,6 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r * |
| 161 | 161 |
return progress.NewProgressReader(in, progressOutput, r.ContentLength, "Downloading context", remoteURL) |
| 162 | 162 |
} |
| 163 | 163 |
|
| 164 |
- buildContext, dockerfileName, err := builder.DetectContextFromRemoteURL(r.Body, remoteURL, createProgressReader) |
|
| 165 |
- if err != nil {
|
|
| 166 |
- return errf(err) |
|
| 167 |
- } |
|
| 168 |
- defer func() {
|
|
| 169 |
- if err := buildContext.Close(); err != nil {
|
|
| 170 |
- logrus.Debugf("[BUILDER] failed to remove temporary context: %v", err)
|
|
| 171 |
- } |
|
| 172 |
- }() |
|
| 173 |
- if len(dockerfileName) > 0 {
|
|
| 174 |
- buildOptions.Dockerfile = dockerfileName |
|
| 175 |
- } |
|
| 176 |
- |
|
| 177 |
- buildOptions.AuthConfigs = authConfigs |
|
| 178 |
- |
|
| 179 | 164 |
var out io.Writer = output |
| 180 | 165 |
if buildOptions.SuppressOutput {
|
| 181 | 166 |
out = notVerboseBuffer |
| ... | ... |
@@ -184,9 +170,14 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r * |
| 184 | 184 |
stdout := &streamformatter.StdoutFormatter{Writer: out, StreamFormatter: sf}
|
| 185 | 185 |
stderr := &streamformatter.StderrFormatter{Writer: out, StreamFormatter: sf}
|
| 186 | 186 |
|
| 187 |
- imgID, err := br.backend.Build(ctx, buildOptions, |
|
| 188 |
- builder.DockerIgnoreContext{ModifiableContext: buildContext},
|
|
| 189 |
- stdout, stderr, out) |
|
| 187 |
+ pg := backend.ProgressWriter{
|
|
| 188 |
+ Output: out, |
|
| 189 |
+ StdoutFormatter: stdout, |
|
| 190 |
+ StderrFormatter: stderr, |
|
| 191 |
+ ProgressReaderFunc: createProgressReader, |
|
| 192 |
+ } |
|
| 193 |
+ |
|
| 194 |
+ imgID, err := br.backend.BuildFromContext(ctx, r.Body, remoteURL, buildOptions, pg) |
|
| 190 | 195 |
if err != nil {
|
| 191 | 196 |
return errf(err) |
| 192 | 197 |
} |
| ... | ... |
@@ -6,6 +6,7 @@ package backend |
| 6 | 6 |
import ( |
| 7 | 7 |
"io" |
| 8 | 8 |
|
| 9 |
+ "github.com/docker/docker/pkg/streamformatter" |
|
| 9 | 10 |
"github.com/docker/engine-api/types" |
| 10 | 11 |
) |
| 11 | 12 |
|
| ... | ... |
@@ -73,3 +74,12 @@ type ContainerCommitConfig struct {
|
| 73 | 73 |
types.ContainerCommitConfig |
| 74 | 74 |
Changes []string |
| 75 | 75 |
} |
| 76 |
+ |
|
| 77 |
+// ProgressWriter is an interface |
|
| 78 |
+// to transport progress streams. |
|
| 79 |
+type ProgressWriter struct {
|
|
| 80 |
+ Output io.Writer |
|
| 81 |
+ StdoutFormatter *streamformatter.StdoutFormatter |
|
| 82 |
+ StderrFormatter *streamformatter.StderrFormatter |
|
| 83 |
+ ProgressReaderFunc func(io.ReadCloser) io.ReadCloser |
|
| 84 |
+} |
| 76 | 85 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,33 @@ |
| 0 |
+package daemon |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "io" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/Sirupsen/logrus" |
|
| 6 |
+ "github.com/docker/docker/api/types/backend" |
|
| 7 |
+ "github.com/docker/docker/builder" |
|
| 8 |
+ "github.com/docker/docker/builder/dockerfile" |
|
| 9 |
+ "github.com/docker/engine-api/types" |
|
| 10 |
+ "golang.org/x/net/context" |
|
| 11 |
+) |
|
| 12 |
+ |
|
| 13 |
+// BuildFromContext builds a new image from a given context. |
|
| 14 |
+func (daemon *Daemon) BuildFromContext(ctx context.Context, src io.ReadCloser, remote string, buildOptions *types.ImageBuildOptions, pg backend.ProgressWriter) (string, error) {
|
|
| 15 |
+ buildContext, dockerfileName, err := builder.DetectContextFromRemoteURL(src, remote, pg.ProgressReaderFunc) |
|
| 16 |
+ if err != nil {
|
|
| 17 |
+ return "", err |
|
| 18 |
+ } |
|
| 19 |
+ defer func() {
|
|
| 20 |
+ if err := buildContext.Close(); err != nil {
|
|
| 21 |
+ logrus.Debugf("[BUILDER] failed to remove temporary context: %v", err)
|
|
| 22 |
+ } |
|
| 23 |
+ }() |
|
| 24 |
+ if len(dockerfileName) > 0 {
|
|
| 25 |
+ buildOptions.Dockerfile = dockerfileName |
|
| 26 |
+ } |
|
| 27 |
+ |
|
| 28 |
+ m := dockerfile.NewBuildManager(daemon) |
|
| 29 |
+ return m.Build(ctx, buildOptions, |
|
| 30 |
+ builder.DockerIgnoreContext{ModifiableContext: buildContext},
|
|
| 31 |
+ pg.StdoutFormatter, pg.StderrFormatter, pg.Output) |
|
| 32 |
+} |
| ... | ... |
@@ -22,7 +22,6 @@ import ( |
| 22 | 22 |
"github.com/docker/docker/api/server/router/network" |
| 23 | 23 |
systemrouter "github.com/docker/docker/api/server/router/system" |
| 24 | 24 |
"github.com/docker/docker/api/server/router/volume" |
| 25 |
- "github.com/docker/docker/builder/dockerfile" |
|
| 26 | 25 |
"github.com/docker/docker/cli" |
| 27 | 26 |
"github.com/docker/docker/cliconfig" |
| 28 | 27 |
"github.com/docker/docker/daemon" |
| ... | ... |
@@ -413,7 +412,7 @@ func initRouter(s *apiserver.Server, d *daemon.Daemon) {
|
| 413 | 413 |
image.NewRouter(d, decoder), |
| 414 | 414 |
systemrouter.NewRouter(d), |
| 415 | 415 |
volume.NewRouter(d), |
| 416 |
- build.NewRouter(dockerfile.NewBuildManager(d)), |
|
| 416 |
+ build.NewRouter(d), |
|
| 417 | 417 |
} |
| 418 | 418 |
if d.NetworkControllerEnabled() {
|
| 419 | 419 |
routers = append(routers, network.NewRouter(d)) |