Exemplo n.º 1
0
func runJobRun(c *cli.Context) {

	stack := mustStack(c)

	// get the job
	if len(c.Args()) != 1 {
		cli.ShowSubcommandHelp(c)
		os.Exit(2)
	}
	jobName := c.Args()[0]

	jobs, err := client.GetJobs(stack.Uid, nil)
	if err != nil {
		printFatal(err.Error())
	}

	var jobNames []string
	for _, job := range jobs {
		jobNames = append(jobNames, job.GetBasicJob().Name)
	}

	idx, err := fuzzyFind(jobNames, jobName, false)
	if err != nil {
		printFatal(err.Error())
	}
	jobUid := string(jobs[idx].GetBasicJob().Uid)

	jobArgs := ""

	if len(c.StringSlice("arg")) > 0 {
		for i, arg := range c.StringSlice("arg") {
			if i > 0 {
				jobArgs = jobArgs + " "
			}
			jobArgs = jobArgs + "\"" + arg + "\""
		}
	}

	asyncId, err := startJobRun(stack.Uid, jobUid, &jobArgs)
	if err != nil {
		printFatal(err.Error())
	}
	genericRes, err := endJobRun(*asyncId, stack.Uid)
	if err != nil {
		printFatal(err.Error())
	}
	printGenericResponse(*genericRes)
	return
}
Exemplo n.º 2
0
func runRedeploy(c *cli.Context) {
	stack := mustStack(c)

	// confirmation is needed if the stack is production
	if stack.Environment == "production" && !c.Bool("y") {
		mustConfirm("This is a production stack. Proceed with deployment? [yes/N]", "yes")
	}

	if len(c.StringSlice("service")) > 0 {
		fmt.Printf("Deploying service(s): ")
		for i, service := range c.StringSlice("service") {
			if i > 0 {
				fmt.Printf(", ")
			}
			fmt.Printf(service)
		}
		fmt.Printf("\n")
	}

	result, err := client.RedeployStack(stack.Uid, c.String("git-ref"), c.StringSlice("service"))
	must(err)

	if !c.Bool("listen") || result.Queued {
		// its queued - just message and exit
		fmt.Println(result.Message)
	} else {
		// tail the logs
		go StartListen(stack)

		stack, err = WaitStackBuild(stack.Uid, false)
		must(err)

		if stack.HealthCode == 2 || stack.HealthCode == 4 || stack.StatusCode == 2 || stack.StatusCode == 7 {
			fmt.Println("Completed with some errors!")
		} else {
			fmt.Println("Completed successfully!")
		}
	}
}