Пример #1
0
// bootstrap
func bootstrap(ccmd *cobra.Command, args []string) {

	// PreRun: boot

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

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

	// listen for status updates
	errch := make(chan error)
	go func() {
		errch <- mistutil.Listen([]string{"job", "bootstrap"}, mistutil.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
}
Пример #2
0
// updateImages
func updateImages(ccmd *cobra.Command, args []string) {

	// PreRun: boot

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

	// listen for status updates
	errch := make(chan error)
	go func() {
		errch <- mistutil.Listen([]string{"job", "imageupdate"}, mistutil.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
}
Пример #3
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
}
Пример #4
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
}
Пример #5
0
// NotifyRebuild
func NotifyRebuild(event *fsnotify.Event) (err error) {

	// pause logs
	config.Silent = true

	//
	switch event.Op {

	// only care about create, write, remove, and rename events
	case fsnotify.Create, fsnotify.Write, fsnotify.Remove, fsnotify.Rename:

		//
		errch := make(chan error)

		switch filepath.Base(event.Name) {

		// run a build for any file changes
		default:
			fmt.Printf(`
++> SOURCE CODE CHANGED, CLOSING LOG STREAM FOR REBUILD ////////////////////////////
`)

			go func() {
				errch <- mist.Listen([]string{"job", "build"}, mist.BuildUpdates)
			}()

			//
			if err = Build(""); err != nil {
				return
			}

		// if the file changes is the Boxfile, deploy
		case "Boxfile":
			fmt.Printf(`
++> BOXFILE CHANGED, CLOSING LOG STREAM FOR REBUILD ////////////////////////
`)

			go func() {
				errch <- mist.Listen([]string{"job", "deploy"}, mist.DeployUpdates)
			}()

			//
			if err = Deploy(""); err != nil {
				return
			}
		}

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

		//
		if err != nil {
			return
		}

		fmt.Printf(`
--------------------------------------------------------------------------------
[√] APP SUCCESSFULLY REBUILT   ///   DEV URL : %v
--------------------------------------------------------------------------------

++> STREAMING LOGS (ctrl-c to exit) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	`, config.Nanofile.Domain)

	}

	// resume logs
	config.Silent = false

	return
}
Пример #6
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
}
Пример #7
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 := mistutil.Connect([]string{"log", "deploy"}, mistutil.PrintLogStream)
	if err != nil {
		config.Fatal("[commands/dev] mistutil.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 <- mistutil.Listen([]string{"job", "deploy"}, mistutil.DeployUpdates)
			}()

			// 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)
		}
	}

	//
	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
}