Esempio n. 1
0
// bootstrap
func bootstrap(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	fmt.Printf(stylish.Bullet("Bootstrapping codebase..."))

	// stream bootstrap output
	go Mist.Stream([]string{"log", "deploy"}, Mist.PrintLogStream)

	// listen for status updates
	errch := make(chan error)
	go func() {
		errch <- Mist.Listen([]string{"job", "bootstrap"}, Mist.BootstrapUpdates)
	}()

	// run a bootstrap
	if err := server.Bootstrap(""); err != nil {
		server.Fatal("[commands/bootstrap] server.Bootstrap() failed", err.Error())
	}

	// wait for a status update (blocking)
	err := <-errch

	//
	if err != nil {
		fmt.Printf(err.Error())
		return
	}

	// PostRun: halt
}
Esempio n. 2
0
// log
func log(ccmd *cobra.Command, args []string) {

	// if stream is true, we connect to the live logs...
	if stream {

		fmt.Printf(stylish.Bullet("Opening log stream"))

		// stream logs (blocking)
		Mist.Stream([]string{"log", "app"}, Mist.ProcessLogStream)

		// ...otherwise load historical logs
	} else {

		//
		v := url.Values{}
		v.Add("level", level)
		v.Add("limit", fmt.Sprintf("%v", count))
		v.Add("offset", fmt.Sprintf("%v", offset))

		// show Mist history
		if err := server.Logs(v.Encode()); err != nil {
			server.Fatal("[commands/log] server.Logs() failed", err.Error())
		}
	}
}
Esempio n. 3
0
// updateImages
func updateImages(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	// stream update output
	go Mist.Stream([]string{"log", "deploy"}, Mist.PrintLogStream)

	// listen for status updates
	errch := make(chan error)
	go func() {
		errch <- Mist.Listen([]string{"job", "imageupdate"}, Mist.ImageUpdates)
	}()

	fmt.Printf(stylish.Bullet("Updating nanobox docker images (this may take a while)..."))

	// run an image update
	if err := server.Update(""); err != nil {
		server.Fatal("[commands/update-images] server.Update() failed", err.Error())
	}

	// wait for a status update (blocking)
	err := <-errch

	//
	if err != nil {
		fmt.Printf(err.Error())
		return
	}

	// PostRun: halt
}
Esempio n. 4
0
// dev
func dev(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	// don't rebuild
	if !nobuild {

		// if the vm has no been created or deployed, the rebuild flag, or the VM has
		// recently been reloaded do a deploy
		if Vagrant.Status() == "not created" || !config.VMfile.HasDeployed() || rebuild || config.VMfile.HasReloaded() {

			fmt.Printf(stylish.Bullet("Deploying codebase..."))

			// remount the engine file at ~/.nanobox/apps/<app>/<engine> so any new scripts
			// will be used during the deploy
			if err := engineutil.RemountLocal(); err != nil {
				config.Debug("No engine mounted (not found locally).")
			}

			// run a deploy
			if err := server.Deploy(""); err != nil {
				server.Fatal("[commands/dev] server.Deploy() failed", err.Error())
			}

			// stream log output
			go Mist.Stream([]string{"log", "deploy"}, Mist.PrintLogStream)

			// listen for status updates
			errch := make(chan error)
			go func() {
				errch <- Mist.Listen([]string{"job", "deploy"}, Mist.DeployUpdates)
			}()

			// wait for a status update (blocking)
			err := <-errch

			//
			if err != nil {
				fmt.Printf(err.Error())
				return
			}
		}
	}

	//
	if err := server.Exec("develop", ""); err != nil {
		server.Error("[commands/dev] Server.Exec failed", err.Error())
	}

	// PostRun: halt
}
Esempio n. 5
0
// deploy
func deploy(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	fmt.Printf(stylish.Bullet("Deploying codebase..."))

	// stream deploy output
	go mistutil.Stream([]string{"log", "deploy"}, mistutil.PrintLogStream)

	// listen for status updates
	errch := make(chan error)
	go func() {
		errch <- mistutil.Listen([]string{"job", "deploy"}, mistutil.DeployUpdates)
	}()

	v := url.Values{}
	v.Add("reset", strconv.FormatBool(config.Force))
	v.Add("run", strconv.FormatBool(install))

	// remount the engine file at ~/.nanobox/apps/<app>/<engine> so any new scripts
	// will be used during the deploy
	if err := engineutil.RemountLocal(); err != nil {
		config.Debug("No engine mounted (not found locally).")
	}

	// run a deploy
	if err := server.Deploy(v.Encode()); err != nil {
		server.Fatal("[commands/deploy] server.Deploy() failed", err.Error())
	}

	// wait for a status update (blocking)
	err := <-errch

	//
	if err != nil {
		fmt.Printf(err.Error())
		return
	}

	// reset "reloaded" to false after a successful deploy so as NOT to deploy on
	// subsequent runnings of "nanobox dev"
	config.VMfile.ReloadedIs(false)

	// PostRun: halt
}
Esempio n. 6
0
// build
func build(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	fmt.Printf(stylish.Bullet("Building codebase..."))

	// stream build output
	go mistutil.Stream([]string{"log", "deploy"}, mistutil.PrintLogStream)

	// listen for status updates
	errch := make(chan error)
	go func() {
		errch <- mistutil.Listen([]string{"job", "build"}, mistutil.BuildUpdates)
	}()

	// remount the engine file at ~/.nanobox/apps/<app>/<engine> so any new scripts
	// are used during the build
	if err := engineutil.RemountLocal(); err != nil {
		config.Debug("No engine mounted (not found locally).")
	}

	// run a build
	if err := server.Build(""); err != nil {
		server.Fatal("[commands/build] server.Build() failed", err.Error())
	}

	// wait for a status update (blocking)
	err := <-errch

	//
	if err != nil {
		fmt.Printf(err.Error())
		return
	}

	// PostRun: halt
}
Esempio n. 7
0
// info runs 'vagrant status'
func info(ccmd *cobra.Command, args []string) {

	// PreRun: runnable

	// determine status
	status := Vagrant.Status()

	fmt.Printf(`
Local Domain   : %s
App Name       : %s
Nanobox state  : %s
Nanobox Files  : %s

`, config.Nanofile.Domain, config.Nanofile.Name, status, config.AppDir)

	if status != "running" {
		fmt.Println("NOTE: To view 'services' information start nanobox with 'nanobox dev' or 'nanobox run'")
		return
	}

	//
	var services []server.Service
	if _, err := server.Get("/services", &services); err != nil {
		server.Fatal("[commands/info] failed", err.Error())
	}

	//
	if len(services) >= 1 {
		fmt.Printf("////////// SERVICES //////////\n")

		//
		for _, service := range services {

			fmt.Printf("\n%s :\n", service.UID)

			if service.Name != "" {
				fmt.Printf("   name  : %s\n", service.Name)
			}

			fmt.Printf("   host  : %s\n", config.Nanofile.Domain)
			fmt.Printf("   ports : %v\n", service.Ports)

			//
			if service.Username != "" {
				fmt.Printf("   username : %s\n", service.Username)
			}

			//
			if service.Password != "" {
				fmt.Printf("   password : %s\n", service.Password)
			}

			// show any environment variables
			if len(service.EnvVars) >= 1 {
				fmt.Printf("   evars :\n")

				for k, v := range service.EnvVars {
					fmt.Printf("      %s : %s\n", k, v)
				}
			}
		}
	}
}
Esempio n. 8
0
// run
func run(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	fmt.Printf(stylish.Bullet("Deploying codebase..."))

	// stream deploy output
	go mistutil.Stream([]string{"log", "deploy"}, mistutil.PrintLogStream)

	// listen for status updates
	errch := make(chan error)
	go func() {
		errch <- mistutil.Listen([]string{"job", "deploy"}, mistutil.DeployUpdates)
	}()

	// remount the engine file at ~/.nanobox/apps/<app>/<engine> so any new scripts
	// will be used during the deploy
	if err := engineutil.RemountLocal(); err != nil {
		config.Debug("No engine mounted (not found locally).")
	}

	// run a deploy
	if err := server.Deploy("run=true"); err != nil {
		server.Fatal("[commands/run] server.Deploy() failed", err.Error())
	}

	// wait for a status update (blocking)
	err := <-errch

	//
	if err != nil {
		fmt.Printf(err.Error())
		return
	}

	fmt.Printf(`
--------------------------------------------------------------------------------
[√] APP SUCCESSFULLY BUILT   ///   DEV URL : %v
--------------------------------------------------------------------------------
`, config.Nanofile.Domain)

	// if in background mode just exist w/o streaming logs or watching files
	if config.VMfile.IsBackground() {
		fmt.Println(`
To stream logs and watch files while in 'background mode' you can use
'nanobox log' and 'nanobox watch'
`)
		return
	}

	// if not in background mode begin streaming logs and watching files
	fmt.Printf(`
++> STREAMING LOGS (ctrl-c to exit) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
`)

	// stream app output
	go mistutil.Stream([]string{"log", "app"}, mistutil.ProcessLogStream)

	// begin watching for file changes (blocking)
	if err := notify.Watch(config.CWDir, server.NotifyRebuild); err != nil {
		fmt.Printf(err.Error())
	}

	// PostRun: halt
}
Esempio n. 9
0
// dev
func dev(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	// check to see if the devconfig option is one of our predetermined values. If
	// not indicate as much and return
	switch devconfig {
	case "mount", "copy", "none":
		break
	default:
		fmt.Printf("--dev-config option '%s' is not accepted. Please choose either 'mount', 'copy', or 'none'\n", devconfig)
		os.Exit(1)
	}

	// stream log output; this is done here because there might be output from hooks
	// that needs to be streamed to the client. This will also capture any output
	// that would come from a deploy (if one is run).
	mist, err := Mist.Connect([]string{"log", "deploy"}, Mist.PrintLogStream)
	if err != nil {
		config.Fatal("[commands/dev] mist.Connect() failed", err.Error())
	}

	// don't rebuild
	if !nobuild {

		// if the vm has no been created or deployed, the rebuild flag, or the VM has
		// recently been reloaded do a deploy
		if Vagrant.Status() == "not created" || !config.VMfile.HasDeployed() || rebuild || config.VMfile.HasReloaded() {

			fmt.Printf(stylish.Bullet("Deploying codebase..."))

			// remount the engine file at ~/.nanobox/apps/<app>/<engine> so any new scripts
			// will be used during the deploy
			if err := engineutil.RemountLocal(); err != nil {
				config.Debug("No engine mounted (not found locally).")
			}

			// run a deploy
			if err := server.Deploy(""); err != nil {
				server.Fatal("[commands/dev] server.Deploy() failed", err.Error())
			}

			// listen for status updates
			errch := make(chan error)
			go func() {
				errch <- Mist.Listen([]string{"job", "deploy"}, Mist.DeployUpdates)
			}()

			// wait for a status update (blocking)
			err := <-errch

			//
			if err != nil {
				fmt.Printf(err.Error())
				return
			}
		}
	}

	//
	v := url.Values{}
	v.Add("dev_config", devconfig)

	//
	if err := server.Develop(v.Encode(), mist); err != nil {
		server.Error("[commands/dev] Server.Develop failed", err.Error())
	}

	// PostRun: halt
}