예제 #1
0
파일: convox.go 프로젝트: goodeggs/platform
// ConvoxReleases returns a list of releases with the Convox ReleaseId mapped
// to a Ranch ReleaseId.
func ConvoxReleases(appName string) ([]RanchRelease, error) {
	client, err := convoxClient()

	if err != nil {
		return nil, err
	}

	app, err := client.GetApp(appName)

	if err != nil {
		return nil, err
	}

	convoxReleases, err := client.GetReleases(appName)

	if err != nil {
		return nil, err
	}

	shaMap, err := buildShaMap(appName)

	if err != nil {
		return nil, err
	}

	var releases []RanchRelease

	for _, convoxRelease := range convoxReleases {
		status := ""

		if app.Release == convoxRelease.Id {
			status = "active"
		}

		appVersion, ok := shaMap[convoxRelease.Id]

		if !ok {
			continue
		}

		release := RanchRelease{
			Id:      appVersion,
			App:     appName,
			Created: convoxRelease.Created,
			Status:  status,
		}

		releases = append(releases, release)
	}

	return releases, nil
}
예제 #2
0
파일: convox.go 프로젝트: goodeggs/platform
// ConvoxWaitForStatusWithMessage waits for a Convox app to have a particular status and displays the given message.
func ConvoxWaitForStatusWithMessage(appName, status string, message string) error {
	timeout := time.After(30 * time.Minute)
	tick := time.Tick(10 * time.Second)

	failed := false

	client, err := convoxClient()
	if err != nil {
		return err
	}

	fmt.Print(message)

	for {
		select {
		case <-tick:
			app, err := client.GetApp(appName)
			if err != nil {
				fmt.Println("✘")
				return err
			}

			switch app.Status {
			case status:
				fmt.Println("✔")
				if failed {
					return fmt.Errorf("Your deploy was not healthy and was rolled back to the previous version.  Consult your app's logs or ask #delivery-eng for help.")
				}
				return nil
			case "rollback":
				if !failed {
					failed = true
					fmt.Print("✘ ROLLBACK\nWaiting for rollback... ")
				}
			default:
				if Verbose {
					fmt.Print(".")
				}
			}

		case <-timeout:
			fmt.Println("✘")
			return fmt.Errorf("The rollout took longer than 30 minutes so we gave up.")
		}
	}

}
예제 #3
0
파일: convox.go 프로젝트: goodeggs/platform
// ConvoxDeploy creates a new Convox release given an app and build directory.
func ConvoxDeploy(appName string, buildDir string) (string, error) {
	client, err := convoxClient()

	if err != nil {
		return "", err
	}

	app, err := client.GetApp(appName)

	if err != nil {
		return "", err
	}

	switch app.Status {
	case "creating":
		return "", fmt.Errorf("app is still creating: %s", appName)
	case "running", "updating":
	default:
		return "", fmt.Errorf("unable to build app: %s", appName)
	}

	tar, err := createTarball(buildDir)

	if err != nil {
		return "", err
	}

	cache := true
	config := "docker-compose.yml"

	fmt.Print("🐮  Uploading Convox build... ")

	build, err := client.CreateBuildSource(appName, tar, cache, config)
	if err != nil {
		fmt.Println("✘")
		return "", err
	}

	fmt.Println("✔")

	return finishBuild(client, appName, build)
}
예제 #4
0
파일: convox.go 프로젝트: goodeggs/platform
// ConvoxCurrentVersion returns the currently active Convox release mapped to Ranch release.
func ConvoxCurrentVersion(appName string) (string, error) {
	client, err := convoxClient()
	if err != nil {
		return "", err
	}

	app, err := client.GetApp(appName)
	if err != nil {
		return "", err
	}

	shaMap, err := buildShaMap(appName)
	if err != nil {
		return "", err
	}

	sha, exists := shaMap[app.Release]
	if !exists {
		return "", fmt.Errorf("current running an unknown convox release %s", app.Release)
	}

	return sha, nil
}