func (p *Plugin) Execute() error {
	// start the Docker daemon server
	if !p.settings.Daemon.Disabled {
		p.startDaemon()
	}

	// poll the docker daemon until it is started. This ensures the daemon is
	// ready to accept connections before we proceed.
	for i := 0; i < 15; i++ {
		cmd := commandInfo()
		err := cmd.Run()
		if err == nil {
			break
		}
		time.Sleep(time.Second * 1)
	}

	// Create Auth Config File
	if p.settings.Login.Config != "" {
		os.MkdirAll(dockerHome, 0600)

		path := filepath.Join(dockerHome, "config.json")
		err := ioutil.WriteFile(path, []byte(p.settings.Login.Config), 0600)
		if err != nil {
			return fmt.Errorf("error writing config.json: %s", err)
		}
	}

	// login to the Docker registry
	if p.settings.Login.Password != "" {
		cmd := commandLogin(p.settings.Login)
		err := cmd.Run()
		if err != nil {
			return fmt.Errorf("error authenticating: %s", err)
		}
	}

	switch {
	case p.settings.Login.Password != "":
		fmt.Println("Detected registry credentials")
	case p.settings.Login.Config != "":
		fmt.Println("Detected registry credentials file")
	default:
		fmt.Println("Registry credentials or Docker config not provided. Guest mode enabled.")
	}

	// add proxy build args
	addProxyBuildArgs(&p.settings.Build)

	var cmds []*exec.Cmd
	cmds = append(cmds, commandVersion()) // docker version
	cmds = append(cmds, commandInfo())    // docker info

	// pre-pull cache images
	for _, img := range p.settings.Build.CacheFrom.Value() {
		cmds = append(cmds, commandPull(img))
	}

	cmds = append(cmds, commandBuild(p.settings.Build)) // docker build

	for _, tag := range p.settings.Build.Tags.Value() {
		cmds = append(cmds, commandTag(p.settings.Build, tag)) // docker tag

		if !p.settings.Dryrun {
			cmds = append(cmds, commandPush(p.settings.Build, tag)) // docker push
		}
	}

	if p.settings.Cleanup {
		cmds = append(cmds, commandRmi(p.settings.Build.Name)) // docker rmi
		cmds = append(cmds, commandPrune())                    // docker system prune -f
	}

	// execute all commands in batch mode.
	for _, cmd := range cmds {
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		trace(cmd)

		err := cmd.Run()
		if err != nil && isCommandPull(cmd.Args) {
			fmt.Printf("Could not pull cache-from image %s. Ignoring...\n", cmd.Args[2])
		} else if err != nil && isCommandPrune(cmd.Args) {
			fmt.Printf("Could not prune system containers. Ignoring...\n")
		} else if err != nil && isCommandRmi(cmd.Args) {
			fmt.Printf("Could not remove image %s. Ignoring...\n", cmd.Args[2])
		} else if err != nil {
			return err
		}
	}

	return nil
}
// Execute provides the implementation of the plugin.
Execute provides the implementation of the plugin.
// Execute provides the implementation of the plugin .
func (p *Plugin) Execute() error {
	if !p.settings.Daemon.Disabled {
		p.startDaemon()
	}
	for i := 0; i < 15; i++ {
		cmd := commandInfo()
		err := cmd.Run()
		if err == nil {
			break
		}
		time.Sleep(time.Second * 1)
	}
	if p.settings.Login.Config != "" {
		os.MkdirAll(dockerHome, 0600)
		path := filepath.Join(dockerHome, "config.json")
		err := ioutil.WriteFile(path, []byte(p.settings.Login.Config), 0600)
		if err != nil {
			return fmt.Errorf("error writing config.json: %s", err)
		}
	}
	if p.settings.Login.Password != "" {
		cmd := commandLogin(p.settings.Login)
		err := cmd.Run()
		if err != nil {
			return fmt.Errorf("error authenticating: %s", err)
		}
	}
	switch {
	case p.settings.Login.Password != "":
		fmt.Println("Detected registry credentials")
	case p.settings.Login.Config != "":
		fmt.Println("Detected registry credentials file")
	default:
		fmt.Println("Registry credentials or Docker config not provided. Guest mode enabled.")
	}
	addProxyBuildArgs(&p.settings.Build)
	var cmds []*exec.Cmd
	cmds = append(cmds, commandVersion()) 
	cmds = append(cmds, commandInfo())    
	for _, img := range p.settings.Build.CacheFrom.Value() {
		cmds = append(cmds, commandPull(img))
	}
	cmds = append(cmds, commandBuild(p.settings.Build)) 
	for _, tag := range p.settings.Build.Tags.Value() {
		cmds = append(cmds, commandTag(p.settings.Build, tag)) 
		if !p.settings.Dryrun {
			cmds = append(cmds, commandPush(p.settings.Build, tag)) 
		}
	}
	if p.settings.Cleanup {
		cmds = append(cmds, commandRmi(p.settings.Build.Name)) 
		cmds = append(cmds, commandPrune())                    
	}
	for _, cmd := range cmds {
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		trace(cmd)
		err := cmd.Run()
		if err != nil && isCommandPull(cmd.Args) {
			fmt.Printf("Could not pull cache-from image %s. Ignoring...\n", cmd.Args[2])
		} else if err != nil && isCommandPrune(cmd.Args) {
			fmt.Printf("Could not prune system containers. Ignoring...\n")
		} else if err != nil && isCommandRmi(cmd.Args) {
			fmt.Printf("Could not remove image %s. Ignoring...\n", cmd.Args[2])
		} else if err != nil {
			return err
		}
	}
	return nil
}
func ( p * Plugin ) Execute ( ) error { if ! p . settings . Daemon . Disabled { p . startDaemon ( ) } for i := 0 ; i < 15 ; i ++ { cmd := commandInfo ( ) err := cmd . Run ( ) if err == nil { break } time . Sleep ( time . Second * 1 ) } if p . settings . Login . Config != " " { os . MkdirAll ( dockerHome , 0600 ) path := filepath . Join ( dockerHome , " " ) err := ioutil . WriteFile ( path , [ ] byte ( p . settings . Login . Config ) , 0600 ) if err != nil { return fmt . Errorf ( " " , err ) } } if p . settings . Login . Password != " " { cmd := commandLogin ( p . settings . Login ) err := cmd . Run ( ) if err != nil { return fmt . Errorf ( " " , err ) } } switch { case p . settings . Login . Password != " " : fmt . Println ( " " ) case p . settings . Login . Config != " " : fmt . Println ( " " ) default : fmt . Println ( " " ) } addProxyBuildArgs ( & p . settings . Build ) var cmds [ ] * exec . Cmd cmds = append ( cmds , commandVersion ( ) ) cmds = append ( cmds , commandInfo ( ) ) for _ , img := range p . settings . Build . CacheFrom . Value ( ) { cmds = append ( cmds , commandPull ( img ) ) } cmds = append ( cmds , commandBuild ( p . settings . Build ) ) for _ , tag := range p . settings . Build . Tags . Value ( ) { cmds = append ( cmds , commandTag ( p . settings . Build , tag ) ) if ! p . settings . Dryrun { cmds = append ( cmds , commandPush ( p . settings . Build , tag ) ) } } if p . settings . Cleanup { cmds = append ( cmds , commandRmi ( p . settings . Build . Name ) ) cmds = append ( cmds , commandPrune ( ) ) } for _ , cmd := range cmds { cmd . Stdout = os . Stdout cmd . Stderr = os . Stderr trace ( cmd ) err := cmd . Run ( ) if err != nil && isCommandPull ( cmd . Args ) { fmt . Printf ( " \n " , cmd . Args [ 2 ] ) } else if err != nil && isCommandPrune ( cmd . Args ) { fmt . Printf ( " \n " ) } else if err != nil && isCommandRmi ( cmd . Args ) { fmt . Printf ( " \n " , cmd . Args [ 2 ] ) } else if err != nil { return err } } return nil }
Execute provides the implementation of the plugin.
Execute provides the implementation of the plugin .
// start the Docker daemon server // poll the docker daemon until it is started. This ensures the daemon is // ready to accept connections before we proceed. // Create Auth Config File // login to the Docker registry // add proxy build args // docker version // docker info // pre-pull cache images // docker build // docker tag // docker push // docker rmi // docker system prune -f // execute all commands in batch mode.