func NewBuilder(daemonURL string, tlsConfig *tls.Config, contextDirectory, dockerfilePath, repoTag string) (*Builder, error) {
	// Validate that the context directory exists.
	stat, err := os.Stat(contextDirectory)
	if err != nil {
		return nil, fmt.Errorf("unable to access build context directory: %s", err)
	}
	if !stat.IsDir() {
		return nil, fmt.Errorf("context must be a directory")
	}

	if dockerfilePath == "" {
		// Use Default path.
		dockerfilePath = filepath.Join(contextDirectory, "Dockerfile")
	}

	if _, err := os.Stat(dockerfilePath); err != nil {
		return nil, fmt.Errorf("unable to access build file: %s", err)
	}

	ref, err := reference.Parse(repoTag)
	if err != nil {
		if err != reference.ErrNameEmpty {
			return nil, fmt.Errorf("invalid tag: %s", err)
		}
	}

	client, err := dockerclient.NewDockerClient(daemonURL, tlsConfig)
	if err != nil {
		return nil, fmt.Errorf("unable to initialize client: %s", err)
	}

	b := &Builder{
		daemonURL:        daemonURL,
		tlsConfig:        tlsConfig,
		client:           client,
		contextDirectory: contextDirectory,
		dockerfilePath:   dockerfilePath,
		ref:              ref,
		out:              os.Stdout,
		config: &config{
			Labels:       map[string]string{},
			ExposedPorts: map[string]struct{}{},
			Volumes:      map[string]struct{}{},
		},
	}

	// Register Dockerfile Directive Handlers
	b.handlers = map[string]handlerFunc{
		commands.Cmd:        b.handleCmd,
		commands.Copy:       b.handleCopy,
		commands.Entrypoint: b.handleEntrypoint,
		commands.Env:        b.handleEnv,
		commands.Expose:     b.handleExpose,
		commands.Extract:    b.handleExtract,
		commands.From:       b.handleFrom,
		commands.Label:      b.handleLabel,
		commands.Maintainer: b.handleMaintainer,
		commands.Run:        b.handleRun,
		commands.User:       b.handleUser,
		commands.Volume:     b.handleVolume,
		commands.Workdir:    b.handleWorkdir,

		// Not implemented for now:
		commands.Add:     b.handleAdd,
		commands.Onbuild: b.handleOnbuild,
	}

	if err := b.loadCache(); err != nil {
		return nil, fmt.Errorf("unable to load build cache: %s", err)
	}

	return b, nil
}
// NewBuilder creates a new builder.
NewBuilder creates a new builder.
// NewBuilder creates a new builder .
func NewBuilder(daemonURL string, tlsConfig *tls.Config, contextDirectory, dockerfilePath, repoTag string) (*Builder, error) {
	stat, err := os.Stat(contextDirectory)
	if err != nil {
		return nil, fmt.Errorf("unable to access build context directory: %s", err)
	}
	if !stat.IsDir() {
		return nil, fmt.Errorf("context must be a directory")
	}
	if dockerfilePath == "" {
		dockerfilePath = filepath.Join(contextDirectory, "Dockerfile")
	}
	if _, err := os.Stat(dockerfilePath); err != nil {
		return nil, fmt.Errorf("unable to access build file: %s", err)
	}
	ref, err := reference.Parse(repoTag)
	if err != nil {
		if err != reference.ErrNameEmpty {
			return nil, fmt.Errorf("invalid tag: %s", err)
		}
	}
	client, err := dockerclient.NewDockerClient(daemonURL, tlsConfig)
	if err != nil {
		return nil, fmt.Errorf("unable to initialize client: %s", err)
	}
	b := &Builder{
		daemonURL:        daemonURL,
		tlsConfig:        tlsConfig,
		client:           client,
		contextDirectory: contextDirectory,
		dockerfilePath:   dockerfilePath,
		ref:              ref,
		out:              os.Stdout,
		config: &config{
			Labels:       map[string]string{},
			ExposedPorts: map[string]struct{}{},
			Volumes:      map[string]struct{}{},
		},
	}
	b.handlers = map[string]handlerFunc{
		commands.Cmd:        b.handleCmd,
		commands.Copy:       b.handleCopy,
		commands.Entrypoint: b.handleEntrypoint,
		commands.Env:        b.handleEnv,
		commands.Expose:     b.handleExpose,
		commands.Extract:    b.handleExtract,
		commands.From:       b.handleFrom,
		commands.Label:      b.handleLabel,
		commands.Maintainer: b.handleMaintainer,
		commands.Run:        b.handleRun,
		commands.User:       b.handleUser,
		commands.Volume:     b.handleVolume,
		commands.Workdir:    b.handleWorkdir,
		commands.Add:     b.handleAdd,
		commands.Onbuild: b.handleOnbuild,
	}
	if err := b.loadCache(); err != nil {
		return nil, fmt.Errorf("unable to load build cache: %s", err)
	}
	return b, nil
}
func NewBuilder ( daemonURL string , tlsConfig * tls . Config , contextDirectory , dockerfilePath , repoTag string ) ( * Builder , error ) { stat , err := os . Stat ( contextDirectory ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if ! stat . IsDir ( ) { return nil , fmt . Errorf ( " " ) } if dockerfilePath == " " { dockerfilePath = filepath . Join ( contextDirectory , " " ) } if _ , err := os . Stat ( dockerfilePath ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } ref , err := reference . Parse ( repoTag ) if err != nil { if err != reference . ErrNameEmpty { return nil , fmt . Errorf ( " " , err ) } } client , err := dockerclient . NewDockerClient ( daemonURL , tlsConfig ) if err != nil { return nil , fmt . Errorf ( " " , err ) } b := & Builder { daemonURL : daemonURL , tlsConfig : tlsConfig , client : client , contextDirectory : contextDirectory , dockerfilePath : dockerfilePath , ref : ref , out : os . Stdout , config : & config { Labels : map [ string ] string { } , ExposedPorts : map [ string ] struct { } { } , Volumes : map [ string ] struct { } { } , } , } b . handlers = map [ string ] handlerFunc { commands . Cmd : b . handleCmd , commands . Copy : b . handleCopy , commands . Entrypoint : b . handleEntrypoint , commands . Env : b . handleEnv , commands . Expose : b . handleExpose , commands . Extract : b . handleExtract , commands . From : b . handleFrom , commands . Label : b . handleLabel , commands . Maintainer : b . handleMaintainer , commands . Run : b . handleRun , commands . User : b . handleUser , commands . Volume : b . handleVolume , commands . Workdir : b . handleWorkdir , commands . Add : b . handleAdd , commands . Onbuild : b . handleOnbuild , } if err := b . loadCache ( ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } return b , nil }
NewBuilder creates a new builder.
NewBuilder creates a new builder .
// Validate that the context directory exists. // Use Default path. // Register Dockerfile Directive Handlers // Not implemented for now: