示例#1
0
// MountLocal creates a local mount (~/.nanobox/apps/<app>/<engine>/<mount>)
func MountLocal() (mountName, mountDir string, err error) {

	// parse the boxfile and see if there is an engine declared; if none is declared
	// simply return
	engine := config.ParseBoxfile().Build.Engine
	if engine == "" {
		return
	}

	//
	mountName = filepath.Base(engine)

	// if an engine is found, ensure the path exists before continuing
	if _, err = os.Stat(engine); err != nil {
		return
	}

	//
	enginefile := filepath.Join(engine, "./Enginefile")

	// ensure there is an enginefile at the engine location
	if _, err = os.Stat(enginefile); err != nil {
		err = fmt.Errorf("No enginefile found at '%v', Exiting...\n", engine)
		return
	}

	// if there is an enginefile attempt to parse it
	mount := &struct {
		Overlays []string `json:"overlays"`
	}{}

	if err = config.ParseConfig(enginefile, mount); err != nil {
		err = fmt.Errorf("Nanobox failed to parse your Enginefile. Please ensure it is valid YAML and try again.\n")
		return
	}

	mountDir = filepath.Join(config.AppDir, filepath.Base(engine))

	// if the enginefile parses successfully create the mount only if it doesn't
	// already exist
	if _, err = os.Stat(mountDir); err != nil {
		if err = os.Mkdir(mountDir, 0755); err != nil {
			return
		}
	}

	// iterate through each overlay and untar it to the mount dir
	for _, overlay := range mount.Overlays {
		GetOverlay(overlay, mountDir)
	}

	var abs string

	abs, err = filepath.Abs(engine)
	if err != nil {
		return
	}

	// pull the remainin engine files into the mount
	for _, f := range []string{"bin", "Enginefile", "lib", "templates", "files"} {

		path := filepath.Join(abs, f)

		// just skip any files that aren't found; any required files will be
		// caught before publishing, here it doesn't matter
		if _, err := os.Stat(path); err != nil {
			continue
		}

		// copy engine file into mount
		if err = fileutil.Copy(path, mountDir); err != nil {
			return
		}
	}

	return
}
示例#2
0
// MountLocal creates a local mount (~/.nanobox/apps/<app>/<engine>/<mount>)
func MountLocal() (mountName, mountDir string, err error) {

	// parse the boxfile and see if there is an engine declared; if none is declared
	// simply return.
	enginePath := config.ParseBoxfile().Build.Engine
	if enginePath == "" {
		return
	}

	//
	mountName = filepath.Base(enginePath)

	// if no local engine is found return since there is nothing more to do here;
	// when an engine is specified but not found, it's assumed that the desired
	// engine exists on nanobox.io
	if _, err = os.Stat(enginePath); err != nil {
		return
	}

	//
	enginefile := filepath.Join(enginePath, "Enginefile")

	// ensure there is an enginefile at the engine location
	if _, err = os.Stat(enginefile); err != nil {
		err = fmt.Errorf("No enginefile found at '%v', Exiting...\n", enginePath)
		return
	}

	// if there is an enginefile attempt to parse it to get any additional build
	// files for mounting
	files := []string{"./bin", "./Enginefile", "./meta.json"}
	if err = config.ParseConfig(enginefile, files); err != nil {
		err = fmt.Errorf("Nanobox failed to parse your Enginefile. Please ensure it is valid YAML and try again.\n")
		return
	}

	// directory to mount
	mountDir = filepath.Join(config.AppDir, mountName)

	// if the enginefile parses successfully create the mount only if it doesn't
	// already exist
	if err = os.MkdirAll(mountDir, 0755); err != nil {
		return
	}

	var abs string

	//
	abs, err = filepath.Abs(enginePath)
	if err != nil {
		return
	}

	// pull the remaining engine files into the mount
	for _, files := range files {

		path := filepath.Join(abs, files)

		// just skip any files that aren't found; any required files will be
		// caught before publishing, here it doesn't matter
		if _, err := os.Stat(path); err != nil {
			continue
		}

		// copy engine file into mount
		if err = fileutil.Copy(path, mountDir); err != nil {
			return
		}
	}

	return
}