Example #1
0
File: deploy.go Project: ch3lo/yale
func deployBefore(c *cli.Context) error {
	if c.String("image") == "" {
		return errors.New("El nombre de la imagen esta vacio")
	}

	if c.String("tag") == "" {
		return errors.New("El TAG de la imagen esta vacio")
	}

	if c.String("smoke-request") == "" {
		return errors.New("El endpoint de Smoke Test esta vacio")
	}

	if c.String("memory") != "" {
		if _, err := bytefmt.ToMegabytes(c.String("memory")); err != nil {
			return errors.New("Valor del parámetro memory invalido")
		}

	}

	for _, file := range c.StringSlice("env-file") {
		if err := util.FileExists(file); err != nil {
			return errors.New(fmt.Sprintf("El archivo %s con variables de entorno no existe", file))
		}
	}

	return nil
}
Example #2
0
// string such as "10 MB" or "1 GB" to mb
func MegabytesFromString(size string) Megabytes {
	size = strings.Replace(strings.TrimSuffix(size, "B"), " ", "", -1)
	mb, err := bytefmt.ToMegabytes(size)
	if err != nil {
		return 0
	}
	return Megabytes(mb)
}
Example #3
0
File: add.go Project: sb10/vrpipe
added them, not the possibly different environment variables you could have in
the future when the commands actually get run.`,
	Run: func(cmd *cobra.Command, args []string) {
		// check the command line options
		if cmdFile == "" {
			die("--file is required")
		}
		if cmdRepGroup == "" {
			cmdRepGroup = "manually_added"
		}
		var cmdMB int
		var err error
		if cmdMem == "" {
			cmdMB = 0
		} else {
			mb, err := bytefmt.ToMegabytes(cmdMem)
			if err != nil {
				die("--memory was not specified correctly: %s", err)
			}
			cmdMB = int(mb)
		}
		var cmdDuration time.Duration
		if cmdTime == "" {
			cmdDuration = 0 * time.Second
		} else {
			cmdDuration, err = time.ParseDuration(cmdTime)
			if err != nil {
				die("--time was not specified correctly: %s", err)
			}
		}
		if cmdCPUs < 1 {
Example #4
0
File: deploy.go Project: ch3lo/yale
func deployCmd(c *cli.Context) {

	envs, err := util.ParseMultiFileLinesToArray(c.StringSlice("env-file"))
	if err != nil {
		util.Log.Fatalln("No se pudo procesar el archivo con variables de entorno", err)
	}

	for _, v := range c.StringSlice("env") {
		envs = append(envs, v)
	}

	serviceConfig := service.ServiceConfig{
		ServiceId: c.String("service-id"),
		CpuShares: c.Int("cpu"),
		Envs:      envs,
		ImageName: c.String("image"),
		Tag:       c.String("tag"),
	}

	if c.String("memory") != "" {
		megabytes, _ := bytefmt.ToMegabytes(c.String("memory"))
		memory := megabytes * 1024 * 1024
		serviceConfig.Memory = int64(memory)
	}

	smokeConfig := monitor.MonitorConfig{
		Retries:  c.Int("smoke-retries"),
		Type:     monitor.GetMonitor(c.String("smoke-type")),
		Request:  c.String("smoke-request"),
		Expected: c.String("smoke-expected"),
	}

	warmUpConfig := monitor.MonitorConfig{
		Retries:  1,
		Type:     monitor.HTTP,
		Request:  c.String("warmup-request"),
		Expected: c.String("warmup-expected"),
	}

	util.Log.Debugf("La configuración del servicio es: %#v", serviceConfig.String())

	handleDeploySigTerm(stackManager)
	if stackManager.Deploy(serviceConfig, smokeConfig, warmUpConfig, c.Int("instances"), c.Float64("tolerance")) {
		services := stackManager.DeployedContainers()
		var resume []callbackResume

		for k := range services {
			if addr, err := services[k].AddressAndPort(8080); err != nil {
				util.Log.Errorln(err)
			} else {
				util.Log.Infof("Se desplegó %s con el tag de registrator %s y dirección %s", services[k].GetId(), services[k].RegistratorId(), addr)
				containerInfo := callbackResume{
					RegisterId: services[k].RegistratorId(),
					Address:    addr,
				}
				resume = append(resume, containerInfo)
			}
		}

		jsonResume, _ := json.Marshal(resume)

		fmt.Println(string(jsonResume))
	} else {
		util.Log.Fatalln("Proceso de deploy con errores")
	}
}