Use ImageBuildOptions in builder.
dockerfile.Config is almost redundant with ImageBuildOptions. Unify the two so that the latter can be removed. This also helps build's API endpoint code to be less dependent on package dockerfile. Signed-off-by: Anusha Ragunathan <anusha@docker.com> Upstream-commit: 5190794f1d85d5406611eb69c270df62ac1cdc7f Component: engine
This commit is contained in:
@ -10,11 +10,11 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/builder"
|
||||
"github.com/docker/docker/builder/dockerfile/parser"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
var validCommitCommands = map[string]bool{
|
||||
@ -41,38 +41,10 @@ var BuiltinAllowedBuildArgs = map[string]bool{
|
||||
"no_proxy": true,
|
||||
}
|
||||
|
||||
// Config constitutes the configuration for a Dockerfile builder.
|
||||
type Config struct {
|
||||
// only used if Dockerfile has to be extracted from Context
|
||||
DockerfileName string
|
||||
|
||||
Verbose bool
|
||||
UseCache bool
|
||||
Remove bool
|
||||
ForceRemove bool
|
||||
Pull bool
|
||||
BuildArgs map[string]string // build-time args received in build context for expansion/substitution and commands in 'run'.
|
||||
Isolation container.IsolationLevel
|
||||
|
||||
// resource constraints
|
||||
// TODO: factor out to be reused with Run ?
|
||||
|
||||
Memory int64
|
||||
MemorySwap int64
|
||||
ShmSize *int64
|
||||
CPUShares int64
|
||||
CPUPeriod int64
|
||||
CPUQuota int64
|
||||
CPUSetCpus string
|
||||
CPUSetMems string
|
||||
CgroupParent string
|
||||
Ulimits []*units.Ulimit
|
||||
}
|
||||
|
||||
// Builder is a Dockerfile builder
|
||||
// It implements the builder.Backend interface.
|
||||
type Builder struct {
|
||||
*Config
|
||||
options *types.ImageBuildOptions
|
||||
|
||||
Stdout io.Writer
|
||||
Stderr io.Writer
|
||||
@ -101,18 +73,18 @@ type Builder struct {
|
||||
// NewBuilder creates a new Dockerfile builder from an optional dockerfile and a Config.
|
||||
// If dockerfile is nil, the Dockerfile specified by Config.DockerfileName,
|
||||
// will be read from the Context passed to Build().
|
||||
func NewBuilder(config *Config, docker builder.Backend, context builder.Context, dockerfile io.ReadCloser) (b *Builder, err error) {
|
||||
func NewBuilder(config *types.ImageBuildOptions, backend builder.Backend, context builder.Context, dockerfile io.ReadCloser) (b *Builder, err error) {
|
||||
if config == nil {
|
||||
config = new(Config)
|
||||
config = new(types.ImageBuildOptions)
|
||||
}
|
||||
if config.BuildArgs == nil {
|
||||
config.BuildArgs = make(map[string]string)
|
||||
}
|
||||
b = &Builder{
|
||||
Config: config,
|
||||
options: config,
|
||||
Stdout: os.Stdout,
|
||||
Stderr: os.Stderr,
|
||||
docker: docker,
|
||||
docker: backend,
|
||||
context: context,
|
||||
runConfig: new(container.Config),
|
||||
tmpContainers: map[string]struct{}{},
|
||||
@ -162,14 +134,14 @@ func (b *Builder) Build() (string, error) {
|
||||
// Not cancelled yet, keep going...
|
||||
}
|
||||
if err := b.dispatch(i, n); err != nil {
|
||||
if b.ForceRemove {
|
||||
if b.options.ForceRemove {
|
||||
b.clearTmp()
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
shortImgID = stringid.TruncateID(b.image)
|
||||
fmt.Fprintf(b.Stdout, " ---> %s\n", shortImgID)
|
||||
if b.Remove {
|
||||
if b.options.Remove {
|
||||
b.clearTmp()
|
||||
}
|
||||
}
|
||||
@ -177,7 +149,7 @@ func (b *Builder) Build() (string, error) {
|
||||
// check if there are any leftover build-args that were passed but not
|
||||
// consumed during build. Return an error, if there are any.
|
||||
leftoverArgs := []string{}
|
||||
for arg := range b.BuildArgs {
|
||||
for arg := range b.options.BuildArgs {
|
||||
if !b.isBuildArgAllowed(arg) {
|
||||
leftoverArgs = append(leftoverArgs, arg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user