Beispiel #1
0
// CmdDomain prints out the namespace plus domain of the given environment
func CmdDomain(envID string, ie environments.IEnvironments, is services.IServices, isites sites.ISites) error {
	env, err := ie.Retrieve(envID)
	if err != nil {
		return err
	}
	serviceProxy, err := is.RetrieveByLabel("service_proxy")
	if err != nil {
		return err
	}
	sites, err := isites.List(serviceProxy.ID)
	if err != nil {
		return err
	}
	domain := ""
	for _, site := range *sites {
		if strings.HasPrefix(site.Name, env.Namespace) {
			domain = site.Name
		}
	}
	if domain == "" {
		return errors.New("Could not determine the temporary domain name of your environment")
	}
	logrus.Println(domain)
	return nil
}
Beispiel #2
0
func CmdStatus(envID string, is IStatus, ie environments.IEnvironments, iservices services.IServices) error {
	env, err := ie.Retrieve(envID)
	if err != nil {
		return err
	}
	svcs, err := iservices.ListByEnvID(env.ID, env.Pod)
	if err != nil {
		return err
	}
	return is.Status(env, svcs)
}
Beispiel #3
0
// CmdLogs is a way to stream logs from Kibana to your local terminal. This is
// useful because Kibana is hard to look at because it splits every single
// log statement into a separate block that spans multiple lines so it's
// not very cohesive. This is intended to be similar to the `heroku logs`
// command.
func CmdLogs(queryString string, follow bool, hours, minutes, seconds int, envID string, settings *models.Settings, il ILogs, ip prompts.IPrompts, ie environments.IEnvironments, is services.IServices, isites sites.ISites) error {
	if follow && (hours > 0 || minutes > 0 || seconds > 0) {
		logrus.Warnln("Specifying \"logs -f\" in combination with \"--hours\", \"--minutes\", or \"--seconds\" has been deprecated!")
		logrus.Warnln("Please specify either \"-f\" or use \"--hours\", \"--minutes\", \"--seconds\" but not both. Support for \"-f\" and a specified time frame will be removed in a later version.")
	}
	env, err := ie.Retrieve(envID)
	if err != nil {
		return err
	}
	serviceProxy, err := is.RetrieveByLabel("service_proxy")
	if err != nil {
		return err
	}
	sites, err := isites.List(serviceProxy.ID)
	if err != nil {
		return err
	}
	domain := ""
	for _, site := range *sites {
		if strings.HasPrefix(site.Name, env.Namespace) {
			domain = site.Name
			break
		}
	}
	if domain == "" {
		return errors.New("Could not determine the fully qualified domain name of your environment. Please contact Catalyze Support at [email protected] with this error message to resolve this issue.")
	}
	if follow {
		if err := il.Watch(queryString, domain, settings.SessionToken); err != nil {
			logrus.Debugf("Error attempting to stream logs from logwatch: %s", err)
		} else {
			return nil
		}
	}
	from := 0
	offset := time.Duration(hours)*time.Hour + time.Duration(minutes)*time.Minute + time.Duration(seconds)*time.Second
	timestamp := time.Now().In(time.UTC).Add(-1 * offset)
	from, timestamp, err = il.Output(queryString, settings.SessionToken, domain, follow, hours, minutes, seconds, from, timestamp, time.Now(), env)
	if err != nil {
		return err
	}
	if follow {
		return il.Stream(queryString, settings.SessionToken, domain, follow, hours, minutes, seconds, from, timestamp, env)
	}
	return nil
}
Beispiel #4
0
func CmdRedeploy(envID, svcName string, ij jobs.IJobs, is services.IServices, ie environments.IEnvironments) error {
	env, err := ie.Retrieve(envID)
	if err != nil {
		return err
	}
	service, err := is.RetrieveByLabel(svcName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", svcName)
	}
	logrus.Printf("Redeploying service %s (ID = %s) in environment %s (ID = %s)", svcName, service.ID, env.Name, env.ID)
	err = ij.Redeploy(service.ID)
	if err != nil {
		return err
	}
	logrus.Println("Redeploy successful! Check the status with \"catalyze status\" and your logging dashboard for updates")
	return nil
}
Beispiel #5
0
func CmdAssociate(envLabel, svcLabel, alias, remote string, defaultEnv bool, ia IAssociate, ig git.IGit, ie environments.IEnvironments, is services.IServices) error {
	if defaultEnv {
		logrus.Warnln("The \"--default\" flag has been deprecated! It will be removed in a future version.")
	}
	if !ig.Exists() {
		return errors.New("No git repo found in the current directory")
	}
	logrus.Printf("Existing git remotes named \"%s\" will be overwritten", remote)
	envs, errs := ie.List()
	if errs != nil && len(errs) > 0 {
		for pod, err := range errs {
			logrus.Debugf("Failed to list environments for pod \"%s\": %s", pod, err)
		}
	}
	var e *models.Environment
	var svcs *[]models.Service
	var err error
	for _, env := range *envs {
		if env.Name == envLabel {
			e = &env
			svcs, err = is.ListByEnvID(env.ID, env.Pod)
			if err != nil {
				return err
			}
			break
		}
	}
	if e == nil {
		return fmt.Errorf("No environment with name \"%s\" found", envLabel)
	}
	if svcs == nil {
		return fmt.Errorf("No services found for environment with name \"%s\"", envLabel)
	}

	var chosenService *models.Service
	availableCodeServices := []string{}
	for _, service := range *svcs {
		if service.Type == "code" {
			if service.Label == svcLabel {
				chosenService = &service
				break
			}
			availableCodeServices = append(availableCodeServices, service.Label)
		}
	}
	if chosenService == nil {
		return fmt.Errorf("No code service found with label \"%s\". Code services found: %s", svcLabel, strings.Join(availableCodeServices, ", "))
	}
	remotes, err := ig.List()
	if err != nil {
		return err
	}
	for _, r := range remotes {
		if r == remote {
			ig.Rm(remote)
			break
		}
	}
	err = ig.Add(remote, chosenService.Source)
	if err != nil {
		return err
	}
	logrus.Printf("\"%s\" remote added.", remote)

	name := alias
	if name == "" {
		name = envLabel
	}
	err = ia.Associate(name, remote, defaultEnv, e, chosenService)
	if err != nil {
		return err
	}
	logrus.Printf("Your git repository \"%s\" has been associated with code service \"%s\" and environment \"%s\"", remote, svcLabel, name)
	logrus.Println("After associating to an environment, you need to add a cert with the \"catalyze certs create\" command, if you have not done so already")
	return nil
}