Ejemplo n.º 1
0
func (f *Foundation) Infra(ctx *foundation.Context) error {
	if ctx.Action == "" {
		appInfra := ctx.Appfile.ActiveInfrastructure()
		lookup := directory.Lookup{Infra: appInfra.Type}
		infra, err := ctx.Directory.GetInfra(&directory.Infra{Lookup: lookup})
		os.Setenv("DEISCTL_TUNNEL", infra.Outputs["ip"])

		fmt.Println("DEISCTL_TUNNEL is " + os.Getenv("DEISCTL_TUNNEL"))

		cmd := exec.Command("deisctl", "config", "platform", "set", "version=v1.11.1")
		cmd.Env = os.Environ()
		err = ottoExec.Run(ctx.Ui, cmd)

		cmd = exec.Command("deisctl", "config", "platform", "set", "sshPrivateKey=~/.ssh/deis-test")
		cmd.Env = os.Environ()
		err = ottoExec.Run(ctx.Ui, cmd)

		cmd = exec.Command("deisctl", "config", "platform", "set", "domain=goings.space")
		cmd.Env = os.Environ()
		err = ottoExec.Run(ctx.Ui, cmd)

		cmd = exec.Command("deisctl", "install", "platform")
		cmd.Env = os.Environ()
		err = ottoExec.Run(ctx.Ui, cmd)

		cmd = exec.Command("deisctl", "start", "platform")
		cmd.Env = os.Environ()
		err = ottoExec.Run(ctx.Ui, cmd)

		return err
	}
	return nil
}
Ejemplo n.º 2
0
Archivo: app.go Proyecto: mbrodala/otto
func (a *App) actionRebuild(rctx router.Context) error {
	ctx := rctx.(*app.Context)
	cwd := filepath.Dir(ctx.Appfile.Path)

	// Get the path to the rebuild binary
	path := filepath.Join(ctx.Dir, "rebuild", "rebuild.go")

	// Run it to regenerate the contents
	ctx.Ui.Header("Rebuilding ScriptPack data...")
	cmd := exec.Command("go", "generate")
	cmd.Dir = cwd
	if err := execHelper.Run(ctx.Ui, cmd); err != nil {
		return err
	}

	cmd = exec.Command("go", "run", path)
	cmd.Dir = cwd
	if err := execHelper.Run(ctx.Ui, cmd); err != nil {
		return err
	}

	// Success
	ctx.Ui.Message("ScriptPack data rebuilt!")
	return nil
}
Ejemplo n.º 3
0
// Execute executes a raw Vagrant command.
func (v *Vagrant) Execute(commandRaw ...string) error {
	vagrantMutex.Lock()
	defer vagrantMutex.Unlock()

	if v.Env == nil {
		v.Env = make(map[string]string)
	}

	// Where to store data
	v.Env[vagrantDataDirEnvVar] = v.DataDir

	// Make sure we use our cwd properly
	v.Env[vagrantCwdEnvVar] = v.Dir

	// Build up the environment
	env := os.Environ()
	for k, v := range v.Env {
		env = append(env, fmt.Sprintf("%s=%s", k, v))
	}

	// Build the args
	command := make([]string, len(commandRaw)+1)
	command[0] = "--machine-readable"
	copy(command[1:], commandRaw)

	// Build the command to execute
	cmd := exec.Command("vagrant", command...)
	cmd.Dir = v.Dir
	cmd.Env = env

	// Build our custom UI that we'll use that'll call the registered
	// callbacks as well as streaming data to the UI.
	callbacks := make(map[string]OutputCallback)
	callbacks["invalid"] = v.uiCallback
	callbacks["ui"] = v.uiCallback
	for n, cb := range v.Callbacks {
		callbacks[n] = cb
	}
	ui := &vagrantUi{Callbacks: callbacks}

	// Run it with the execHelper
	err := execHelper.Run(ui, cmd)
	ui.Finish()
	if err != nil {
		return fmt.Errorf(
			"Error executing Vagrant: %s\n\n"+
				"The error messages from Vagrant are usually very informative.\n"+
				"Please read it carefully and fix any issues it mentions. If\n"+
				"the message isn't clear, please report this to the Otto project.",
			err)
	}

	return nil
}
Ejemplo n.º 4
0
// Execute executes a raw Packer command.
func (p *Packer) Execute(commandRaw ...string) error {
	varfile, err := p.varfile()
	if err != nil {
		return err
	}
	if execHelper.ShouldCleanup() {
		defer os.Remove(varfile)
	}

	// The command must always be machine-readable. We use this
	// exclusively to mirror the UI output.
	command := make([]string, len(commandRaw)+3)
	command[0] = commandRaw[0]
	command[1] = "-machine-readable"
	command[2] = "-var-file"
	command[3] = varfile
	copy(command[4:], commandRaw[1:])

	// Build the command to execute
	path := "packer"
	if p.Path != "" {
		path = p.Path
	}
	cmd := exec.Command(path, command...)
	cmd.Dir = p.Dir

	// Build our custom UI that we'll use that'll call the registered
	// callbacks as well as streaming data to the UI.
	callbacks := make(map[string]OutputCallback)
	callbacks["ui"] = p.uiCallback
	for n, cb := range p.Callbacks {
		callbacks[n] = cb
	}
	ui := &packerUi{Callbacks: callbacks}

	// Execute!
	err = execHelper.Run(ui, cmd)
	ui.Finish()
	if err != nil {
		return fmt.Errorf(
			"Error executing Packer: %s\n\n"+
				"The error messages from Packer are usually very informative.\n"+
				"Please read it carefully and fix any issues it mentions. If\n"+
				"the message isn't clear, please report this to the Otto project.",
			err)
	}

	return nil
}
Ejemplo n.º 5
0
// Execute executes a raw Vagrant command.
func (v *Vagrant) Execute(command ...string) error {
	vagrantMutex.Lock()
	defer vagrantMutex.Unlock()

	if v.Env == nil {
		v.Env = make(map[string]string)
	}

	// Where to store data
	v.Env[vagrantDataDirEnvVar] = v.DataDir

	// Make sure we use our cwd properly
	v.Env[vagrantCwdEnvVar] = v.Dir

	// Build up the environment
	env := os.Environ()
	for k, v := range v.Env {
		env = append(env, fmt.Sprintf("%s=%s", k, v))
	}

	// Build the command to execute
	cmd := exec.Command("vagrant", command...)
	cmd.Dir = v.Dir
	cmd.Env = env

	// Run it with the execHelper
	if err := execHelper.Run(v.Ui, cmd); err != nil {
		return fmt.Errorf(
			"Error executing Vagrant: %s\n\n"+
				"The error messages from Vagrant are usually very informative.\n"+
				"Please read it carefully and fix any issues it mentions. If\n"+
				"the message isn't clear, please report this to the Otto project.",
			err)
	}

	return nil
}
Ejemplo n.º 6
0
// Add takes the path of a private key and runs ssh-add locally to add it to
// the agent. It needs a Ui to be able to interact with the user for the
// password prompt.
func Add(ui ui.Ui, privateKeyPath string) error {
	cmd := exec.Command("ssh-add", privateKeyPath)
	return execHelper.Run(ui, cmd)
}
Ejemplo n.º 7
0
// Execute executes a raw Terraform command
func (t *Terraform) Execute(commandRaw ...string) error {
	command := make([]string, 1, len(commandRaw)*2)
	command[0] = commandRaw[0]
	commandArgs := commandRaw[1:]

	// Determine if we need to skip var flags or not.
	varSkip := false
	varSkip = command[0] == "get"

	// If we have variables, create the var file
	if !varSkip && len(t.Variables) > 0 {
		varfile, err := t.varfile()
		if err != nil {
			return err
		}
		if execHelper.ShouldCleanup() {
			defer os.Remove(varfile)
		}

		// Append the varfile onto our command.
		command = append(command, "-var-file", varfile)

		// Log some of the vars we're using
		for k, _ := range t.Variables {
			log.Printf("[DEBUG] setting TF var: %s", k)
		}
	}

	// Determine if we need to skip state flags or not. This is just
	// hardcoded for now.
	stateSkip := false
	stateSkip = command[0] == "get"

	// Output needs state but not state-out; more hard-coding
	stateOutSkip := false
	stateOutSkip = command[0] == "output"

	// If we care about state, then setup the state directory and
	// load it up.
	var stateDir, statePath string
	if !stateSkip && t.StateId != "" && t.Directory != nil {
		var err error
		stateDir, err = ioutil.TempDir("", "otto-tf")
		if err != nil {
			return err
		}
		if execHelper.ShouldCleanup() {
			defer os.RemoveAll(stateDir)
		}

		// State path
		stateOldPath := filepath.Join(stateDir, "state.old")
		statePath = filepath.Join(stateDir, "state")

		// Load the state from the directory
		data, err := t.Directory.GetBlob(t.StateId)
		if err != nil {
			return fmt.Errorf("Error loading Terraform state: %s", err)
		}
		if data == nil && command[0] == "destroy" {
			// Destroy we can just execute, we don't need state
			return nil
		}
		if data != nil {
			err = data.WriteToFile(stateOldPath)
			data.Close()
		}
		if err != nil {
			return fmt.Errorf("Error writing Terraform state: %s", err)
		}

		// Append the state to the args
		command = append(command, "-state", stateOldPath)
		if !stateOutSkip {
			command = append(command, "-state-out", statePath)
		}
	}

	// Append all the final args
	command = append(command, commandArgs...)

	// Build the command to execute
	log.Printf("[DEBUG] executing terraform: %v", command)
	path := "terraform"
	if t.Path != "" {
		path = t.Path
	}
	cmd := exec.Command(path, command...)
	cmd.Dir = t.Dir

	// Start the Terraform command. If there is an error we just store
	// the error but can't exit yet because we have to store partial
	// state if there is any.
	err := execHelper.Run(t.Ui, cmd)
	if err != nil {
		err = fmt.Errorf("Error running Terraform: %s", err)
	}

	// Save the state file if we have it.
	if t.StateId != "" && t.Directory != nil && statePath != "" && !stateOutSkip {
		f, ferr := os.Open(statePath)
		if ferr != nil {
			return fmt.Errorf(
				"Error reading Terraform state for saving: %s", ferr)
		}

		// Store the state
		derr := t.Directory.PutBlob(t.StateId, &directory.BlobData{
			Data: f,
		})

		// Always close the file
		f.Close()

		// If we couldn't save the data, then note the error. This is a
		// _really_ bad error to get since there isn't a good way to
		// recover. For now, we just copy the state to the pwd and note
		// the user.
		if derr != nil {
			// TODO: copy state

			err = fmt.Errorf(
				"Failed to save Terraform state: %s\n\n"+
					"This means that Otto was unable to store the state of your infrastructure.\n"+
					"At this time, Otto doesn't support gracefully recovering from this\n"+
					"scenario. The state should be in the path below. Please ask the\n"+
					"community for assistance.",
				derr)
		}
	}

	return err
}