mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move build endpoint handler from daemon (#21972)
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
6f8878872f
commit
73ac6d199c
3 changed files with 26 additions and 49 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/docker/api/types/backend"
|
||||||
"github.com/docker/docker/builder"
|
"github.com/docker/docker/builder"
|
||||||
"github.com/docker/docker/builder/dockerfile/parser"
|
"github.com/docker/docker/builder/dockerfile/parser"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
|
@ -84,6 +85,27 @@ func NewBuildManager(b builder.Backend) (bm *BuildManager) {
|
||||||
return &BuildManager{backend: b}
|
return &BuildManager{backend: b}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildFromContext builds a new image from a given context.
|
||||||
|
func (bm *BuildManager) 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
|
||||||
|
}
|
||||||
|
b, err := NewBuilder(ctx, buildOptions, bm.backend, builder.DockerIgnoreContext{ModifiableContext: buildContext}, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return b.build(pg.StdoutFormatter, pg.StderrFormatter, pg.Output)
|
||||||
|
}
|
||||||
|
|
||||||
// NewBuilder creates a new Dockerfile builder from an optional dockerfile and a Config.
|
// NewBuilder creates a new Dockerfile builder from an optional dockerfile and a Config.
|
||||||
// If dockerfile is nil, the Dockerfile specified by Config.DockerfileName,
|
// If dockerfile is nil, the Dockerfile specified by Config.DockerfileName,
|
||||||
// will be read from the Context passed to Build().
|
// will be read from the Context passed to Build().
|
||||||
|
@ -160,17 +182,6 @@ func sanitizeRepoAndTags(names []string) ([]reference.Named, error) {
|
||||||
return repoAndTags, nil
|
return repoAndTags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build creates a NewBuilder, which builds the image.
|
|
||||||
func (bm *BuildManager) Build(clientCtx context.Context, config *types.ImageBuildOptions, context builder.Context, stdout io.Writer, stderr io.Writer, out io.Writer) (string, error) {
|
|
||||||
b, err := NewBuilder(clientCtx, config, bm.backend, context, nil)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
img, err := b.build(config, context, stdout, stderr, out)
|
|
||||||
return img, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// build runs the Dockerfile builder from a context and a docker object that allows to make calls
|
// build runs the Dockerfile builder from a context and a docker object that allows to make calls
|
||||||
// to Docker.
|
// to Docker.
|
||||||
//
|
//
|
||||||
|
@ -184,9 +195,7 @@ func (bm *BuildManager) Build(clientCtx context.Context, config *types.ImageBuil
|
||||||
// * Tag image, if applicable.
|
// * Tag image, if applicable.
|
||||||
// * Print a happy message and return the image ID.
|
// * Print a happy message and return the image ID.
|
||||||
//
|
//
|
||||||
func (b *Builder) build(config *types.ImageBuildOptions, context builder.Context, stdout io.Writer, stderr io.Writer, out io.Writer) (string, error) {
|
func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (string, error) {
|
||||||
b.options = config
|
|
||||||
b.context = context
|
|
||||||
b.Stdout = stdout
|
b.Stdout = stdout
|
||||||
b.Stderr = stderr
|
b.Stderr = stderr
|
||||||
b.Output = out
|
b.Output = out
|
||||||
|
@ -198,7 +207,7 @@ func (b *Builder) build(config *types.ImageBuildOptions, context builder.Context
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repoAndTags, err := sanitizeRepoAndTags(config.Tags)
|
repoAndTags, err := sanitizeRepoAndTags(b.options.Tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
|
@ -24,6 +24,7 @@ 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"
|
||||||
|
@ -429,7 +430,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(d),
|
build.NewRouter(dockerfile.NewBuildManager(d)),
|
||||||
}
|
}
|
||||||
if d.NetworkControllerEnabled() {
|
if d.NetworkControllerEnabled() {
|
||||||
routers = append(routers, network.NewRouter(d))
|
routers = append(routers, network.NewRouter(d))
|
||||||
|
|
Loading…
Add table
Reference in a new issue