Exemplo n.º 1
0
//initialize the provisioner and setup the requirements for provisioner
func (p *chefsoloProvisioner) Initialize(m map[string]string) error {
	var outBuffer bytes.Buffer
	start := time.Now()

	p.Cookbook = m[CHEFREPO_COOKBOOK]
	logWriter := carton.NewLogWriter(&provision.Box{CartonName: m[NAME]})
	writer := io.MultiWriter(&outBuffer, &logWriter)
	defer logWriter.Close()

	cr := NewChefRepo(m, writer)
	if err := cr.Download(true); err != nil {
		err = provision.EventNotify(constants.StatusCookbookFailure)
		return err
	}
	if err := cr.Torr(); err != nil {
		err = provision.EventNotify(constants.StatusCookbookFailure)
		return err
	}
	elapsed := time.Since(start)

	log.Debugf("%s in (%s)\n%s",
		cmd.Colorfy(m[NAME], "cyan", "", "bold"),
		cmd.Colorfy(elapsed.String(), "green", "", "bold"),
		cmd.Colorfy(outBuffer.String(), "yellow", "", ""))
	_ = provision.EventNotify(constants.StatusCookbookSuccess)
	return nil
}
Exemplo n.º 2
0
func (p *DockerProvisioner) LogExec() {
	var outBuffer bytes.Buffer
	var closeChan chan bool
	b := &provision.Box{Id: p.ContainerId, Name: p.ContainerName, Tosca: p.Tosca_type}
	logWriter := carton.NewLogWriter(b)

	writer := io.MultiWriter(&outBuffer, &logWriter)
	p.createLogPipeline(writer, closeChan)

	go func(closeChan chan bool, logWriter carton.LogWriter) {
		select {
		case <-closeChan:
			logWriter.Close()
		default:
		}
	}(closeChan, logWriter)
}