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

Remove builder dependency from the api.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2016-03-29 15:51:14 -07:00
parent d78f8f2796
commit d12b7c7e3e
5 changed files with 56 additions and 23 deletions

View file

@ -3,7 +3,7 @@ package build
import ( import (
"io" "io"
"github.com/docker/docker/builder" "github.com/docker/docker/api/types/backend"
"github.com/docker/engine-api/types" "github.com/docker/engine-api/types"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -16,5 +16,5 @@ type Backend interface {
// by the caller. // by the caller.
// //
// TODO: make this return a reference instead of string // TODO: make this return a reference instead of string
Build(clientCtx context.Context, config *types.ImageBuildOptions, context builder.Context, stdout io.Writer, stderr io.Writer, out io.Writer) (string, error) BuildFromContext(ctx context.Context, src io.ReadCloser, remote string, buildOptions *types.ImageBuildOptions, pg backend.ProgressWriter) (string, error)
} }

View file

@ -13,7 +13,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/builder" "github.com/docker/docker/api/types/backend"
"github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/progress" "github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter" "github.com/docker/docker/pkg/streamformatter"
@ -148,6 +148,7 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *
if err != nil { if err != nil {
return errf(err) return errf(err)
} }
buildOptions.AuthConfigs = authConfigs
remoteURL := r.FormValue("remote") remoteURL := r.FormValue("remote")
@ -161,21 +162,6 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *
return progress.NewProgressReader(in, progressOutput, r.ContentLength, "Downloading context", remoteURL) return progress.NewProgressReader(in, progressOutput, r.ContentLength, "Downloading context", remoteURL)
} }
buildContext, dockerfileName, err := builder.DetectContextFromRemoteURL(r.Body, remoteURL, createProgressReader)
if err != nil {
return errf(err)
}
defer func() {
if err := buildContext.Close(); err != nil {
logrus.Debugf("[BUILDER] failed to remove temporary context: %v", err)
}
}()
if len(dockerfileName) > 0 {
buildOptions.Dockerfile = dockerfileName
}
buildOptions.AuthConfigs = authConfigs
var out io.Writer = output var out io.Writer = output
if buildOptions.SuppressOutput { if buildOptions.SuppressOutput {
out = notVerboseBuffer out = notVerboseBuffer
@ -184,9 +170,14 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *
stdout := &streamformatter.StdoutFormatter{Writer: out, StreamFormatter: sf} stdout := &streamformatter.StdoutFormatter{Writer: out, StreamFormatter: sf}
stderr := &streamformatter.StderrFormatter{Writer: out, StreamFormatter: sf} stderr := &streamformatter.StderrFormatter{Writer: out, StreamFormatter: sf}
imgID, err := br.backend.Build(ctx, buildOptions, pg := backend.ProgressWriter{
builder.DockerIgnoreContext{ModifiableContext: buildContext}, Output: out,
stdout, stderr, out) StdoutFormatter: stdout,
StderrFormatter: stderr,
ProgressReaderFunc: createProgressReader,
}
imgID, err := br.backend.BuildFromContext(ctx, r.Body, remoteURL, buildOptions, pg)
if err != nil { if err != nil {
return errf(err) return errf(err)
} }

View file

@ -6,6 +6,7 @@ package backend
import ( import (
"io" "io"
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/engine-api/types" "github.com/docker/engine-api/types"
) )
@ -73,3 +74,12 @@ type ContainerCommitConfig struct {
types.ContainerCommitConfig types.ContainerCommitConfig
Changes []string Changes []string
} }
// ProgressWriter is an interface
// to transport progress streams.
type ProgressWriter struct {
Output io.Writer
StdoutFormatter *streamformatter.StdoutFormatter
StderrFormatter *streamformatter.StderrFormatter
ProgressReaderFunc func(io.ReadCloser) io.ReadCloser
}

33
daemon/builder.go Normal file
View file

@ -0,0 +1,33 @@
package daemon
import (
"io"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/builder"
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/engine-api/types"
"golang.org/x/net/context"
)
// BuildFromContext builds a new image from a given context.
func (daemon *Daemon) BuildFromContext(ctx context.Context, src io.ReadCloser, remote string, buildOptions *types.ImageBuildOptions, pg backend.ProgressWriter) (string, error) {
buildContext, dockerfileName, err := builder.DetectContextFromRemoteURL(src, remote, pg.ProgressReaderFunc)
if err != nil {
return "", err
}
defer func() {
if err := buildContext.Close(); err != nil {
logrus.Debugf("[BUILDER] failed to remove temporary context: %v", err)
}
}()
if len(dockerfileName) > 0 {
buildOptions.Dockerfile = dockerfileName
}
m := dockerfile.NewBuildManager(daemon)
return m.Build(ctx, buildOptions,
builder.DockerIgnoreContext{ModifiableContext: buildContext},
pg.StdoutFormatter, pg.StderrFormatter, pg.Output)
}

View file

@ -22,7 +22,6 @@ import (
"github.com/docker/docker/api/server/router/network" "github.com/docker/docker/api/server/router/network"
systemrouter "github.com/docker/docker/api/server/router/system" systemrouter "github.com/docker/docker/api/server/router/system"
"github.com/docker/docker/api/server/router/volume" "github.com/docker/docker/api/server/router/volume"
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cliconfig" "github.com/docker/docker/cliconfig"
"github.com/docker/docker/daemon" "github.com/docker/docker/daemon"
@ -413,7 +412,7 @@ func initRouter(s *apiserver.Server, d *daemon.Daemon) {
image.NewRouter(d, decoder), image.NewRouter(d, decoder),
systemrouter.NewRouter(d), systemrouter.NewRouter(d),
volume.NewRouter(d), volume.NewRouter(d),
build.NewRouter(dockerfile.NewBuildManager(d)), build.NewRouter(d),
} }
if d.NetworkControllerEnabled() { if d.NetworkControllerEnabled() {
routers = append(routers, network.NewRouter(d)) routers = append(routers, network.NewRouter(d))