Ejemplo n.º 1
0
func updateConfig(conn db.Conn, configPath string) error {
	pathStr, _ := os.LookupEnv(quiltPath)
	if pathStr == "" {
		pathStr = stitch.GetQuiltPath()
	}

	f, err := util.Open(configPath)
	if err != nil {
		f, err = util.Open(filepath.Join(pathStr, configPath))
		if err != nil {
			return err
		}
	}

	defer f.Close()

	sc := scanner.Scanner{
		Position: scanner.Position{
			Filename: configPath,
		},
	}

	spec, err := stitch.New(*sc.Init(bufio.NewReader(f)), pathStr, false)
	if err != nil {
		return err
	}

	return engine.UpdatePolicy(conn, spec)
}
Ejemplo n.º 2
0
Archivo: run.go Proyecto: NetSys/quilt
// Run starts the run for the provided Stitch.
func (rCmd *Run) Run() int {
	stitchPath := rCmd.stitch
	compiled, err := stitch.FromFile(stitchPath, stitch.DefaultImportGetter)
	if err != nil && os.IsNotExist(err) && !filepath.IsAbs(stitchPath) {
		// Automatically add the ".js" file suffix if it's not provided.
		if !strings.HasSuffix(stitchPath, ".js") {
			stitchPath += ".js"
		}
		compiled, err = stitch.FromFile(
			filepath.Join(stitch.GetQuiltPath(), stitchPath),
			stitch.DefaultImportGetter)
	}
	if err != nil {
		// Print the stacktrace if it's an Otto error.
		if ottoError, ok := err.(*otto.Error); ok {
			log.Error(ottoError.String())
		} else {
			log.Error(err)
		}
		return 1
	}
	deployment := compiled.String()

	c, err := rCmd.clientGetter.Client(rCmd.common.host)
	if err != nil {
		log.Error(err)
		return 1
	}
	defer c.Close()

	curr, err := getCurrentDeployment(c)
	if err != nil {
		log.WithError(err).Error("Unable to get current deployment.")
		return 1
	}

	if !rCmd.force && curr != emptyDeployment {
		diff, err := diffDeployment(curr, deployment)
		if err != nil {
			log.WithError(err).Error("Unable to diff deployments.")
			return 1
		}

		if diff == "" {
			fmt.Println("No change.")
		} else {
			fmt.Println(diff)
		}
		shouldDeploy, err := confirm(os.Stdin, "Continue with deployment?")
		if err != nil {
			log.WithError(err).Error("Unable to get user response.")
			return 1
		}

		if !shouldDeploy {
			fmt.Println("Deployment aborted by user.")
			return 0
		}
	}

	err = c.Deploy(deployment)
	if err != nil {
		log.WithError(err).Error("Error while starting run.")
		return 1
	}

	log.Debug("Successfully started run")
	return 0
}