Exemplo n.º 1
0
Arquivo: apps.go Projeto: convox/rack
func cmdAppCreate(c *cli.Context) error {
	_, app, err := stdcli.DirApp(c, ".")
	if err != nil {
		return stdcli.Error(err)
	}

	if len(c.Args()) > 0 {
		app = c.Args()[0]
	}

	if app == "" {
		return stdcli.Error(fmt.Errorf("must specify an app name"))
	}

	stdcli.Startf("Creating app <app>%s</app>", app)

	_, err = rackClient(c).CreateApp(app)
	if err != nil {
		return stdcli.Error(err)
	}

	stdcli.Wait("CREATING")

	if c.Bool("wait") {
		stdcli.Startf("Waiting for <app>%s</app>", app)

		if err := waitForAppRunning(c, app); err != nil {
			stdcli.Error(err)
		}

		stdcli.OK()
	}

	return nil
}
Exemplo n.º 2
0
Arquivo: apps.go Projeto: convox/rack
func waitForAppRunning(c *cli.Context, app string) error {
	timeout := time.After(30 * time.Minute)
	tick := time.Tick(5 * time.Second)

	failed := false

	for {
		select {
		case <-tick:
			a, err := rackClient(c).GetApp(app)
			if err != nil {
				return err
			}

			switch a.Status {
			case "failed", "running":
				if failed {
					stdcli.Writef("<ok>DONE</ok>\n")
					return fmt.Errorf("Update rolled back")
				}
				return nil
			case "rollback":
				if !failed {
					failed = true
					stdcli.Writef("<fail>FAILED</fail>\n")
					stdcli.Startf("Rolling back")
				}
			}
		case <-timeout:
			return fmt.Errorf("timeout")
		}
	}

	return nil
}
Exemplo n.º 3
0
Arquivo: apps.go Projeto: convox/rack
func cmdAppParamsSet(c *cli.Context) error {
	_, app, err := stdcli.DirApp(c, ".")
	if err != nil {
		return stdcli.Error(err)
	}

	params := map[string]string{}

	for _, arg := range c.Args() {
		parts := strings.SplitN(arg, "=", 2)

		if len(parts) != 2 {
			return stdcli.Error(fmt.Errorf("invalid argument: %s", arg))
		}

		params[parts[0]] = parts[1]
	}

	stdcli.Startf("Updating parameters")

	err = rackClient(c).SetParameters(app, params)
	if err != nil {
		return stdcli.Error(err)
	}

	stdcli.OK()

	return nil
}
Exemplo n.º 4
0
Arquivo: apps.go Projeto: convox/rack
func cmdAppDelete(c *cli.Context) error {
	if len(c.Args()) < 1 {
		stdcli.Usage(c, "delete")
		return nil
	}

	app := c.Args()[0]

	stdcli.Startf("Deleting <app>%s</app>", app)

	_, err := rackClient(c).DeleteApp(app)
	if err != nil {
		return stdcli.Error(err)
	}

	stdcli.Wait("DELETING")

	return nil
}
Exemplo n.º 5
0
Arquivo: apps.go Projeto: convox/rack
func cmdAppCancel(c *cli.Context) error {
	_, app, err := stdcli.DirApp(c, ".")
	if err != nil {
		return stdcli.Error(err)
	}

	if app == "" {
		return stdcli.Error(fmt.Errorf("must specify an app name"))
	}

	stdcli.Startf("Cancelling update for <app>%s</app>", app)

	if err := rackClient(c).CancelApp(app); err != nil {
		return stdcli.Error(err)
	}

	stdcli.Wait("CANCELLED")

	return nil
}
Exemplo n.º 6
0
Arquivo: rack.go Projeto: convox/rack
func cmdRackUpdate(c *cli.Context) error {
	vs, err := version.All()
	if err != nil {
		return stdcli.Error(err)
	}

	target, err := vs.Latest()
	if err != nil {
		return stdcli.Error(err)
	}

	if len(c.Args()) > 0 {
		t, err := vs.Find(c.Args()[0])
		if err != nil {
			return stdcli.Error(err)
		}
		target = t
	}

	system, err := rackClient(c).GetSystem()
	if err != nil {
		return stdcli.Error(err)
	}

	nv, err := vs.Next(system.Version)
	if err != nil && strings.HasSuffix(err.Error(), "is latest") {
		nv = target.Version
	} else if err != nil {
		return stdcli.Error(err)
	}

	next, err := vs.Find(nv)
	if err != nil {
		return stdcli.Error(err)
	}

	// stop at a required release if necessary
	if next.Version < target.Version {
		stdcli.Writef("WARNING: Required update found.\nPlease run `convox rack update` again once this update completes.\n")
		target = next
	}

	stdcli.Startf("Updating to <release>%s</release>", target.Version)

	_, err = rackClient(c).UpdateSystem(target.Version)
	if err != nil {
		return stdcli.Error(err)
	}

	stdcli.Wait("UPDATING")

	if c.Bool("wait") {
		stdcli.Startf("Waiting for completion")

		// give the rack a few seconds to start updating
		time.Sleep(5 * time.Second)

		if err := waitForRackRunning(c); err != nil {
			return stdcli.Error(err)
		}

		stdcli.OK()
	}

	return nil
}