示例#1
0
文件: git.go 项目: richardjoo/tsuru
func Git(provisioner provision.Provisioner, app provision.App, w io.Writer) error {
	log.Write(w, []byte("\n ---> Tsuru receiving push\n"))
	log.Write(w, []byte("\n ---> Replicating the application repository across units\n"))
	out, err := clone(provisioner, app)
	if err != nil {
		out, err = pull(provisioner, app)
	}
	if err != nil {
		msg := fmt.Sprintf("Got error while clonning/pulling repository: %s -- \n%s", err.Error(), string(out))
		log.Write(w, []byte(msg))
		return errors.New(msg)
	}
	log.Write(w, out)
	log.Write(w, []byte("\n ---> Installing dependencies\n"))
	if err := provisioner.InstallDeps(app, w); err != nil {
		log.Write(w, []byte(err.Error()))
		return err
	}
	log.Write(w, []byte("\n ---> Restarting application\n"))
	if err := app.Restart(w); err != nil {
		log.Write(w, []byte(err.Error()))
		return err
	}
	return log.Write(w, []byte("\n ---> Deploy done!\n\n"))
}
示例#2
0
func (p *dockerProvisioner) Deploy(a provision.App, w io.Writer) error {
	var deploy = func() error {
		c, err := newContainer(a)
		if err != nil {
			return err
		}
		err = c.deploy(w)
		if err != nil {
			c.remove()
		}
		return err
	}
	if containers, err := listAppContainers(a.GetName()); err == nil && len(containers) > 0 {
		for _, c := range containers {
			err = deploy()
			if err != nil {
				return err
			}
			a.RemoveUnit(c.Id)
		}
	} else if err := deploy(); err != nil {
		return err
	}
	a.Restart(w)
	app.Enqueue(queue.Message{
		Action: app.RegenerateApprcAndStart,
		Args:   []string{a.GetName()},
	})
	return nil
}
示例#3
0
func injectEnvsAndRestart(a provision.App) {
	time.Sleep(5e9)
	err := a.SerializeEnvVars()
	if err != nil {
		log.Printf("Failed to serialize env vars: %s.", err)
	}
	var buf bytes.Buffer
	w := app.LogWriter{App: a, Writer: &buf}
	err = a.Restart(&w)
	if err != nil {
		log.Printf("Failed to restart app %q (%s): %s.", a.GetName(), err, buf.String())
	}
}