Beispiel #1
0
// init
func init() {

	// check for a ~/.nanobox/.auth file and create one if it's not found
	authfile = filepath.Clean(config.Root + "/.auth")
	if _, err := os.Stat(authfile); err != nil {
		f, err := os.Create(authfile)
		if err != nil {
			config.Fatal("[auth/auth] os.Create() failed", err.Error())
		}
		defer f.Close()
	}

	creds = &credentials{}

	//
	if err := config.ParseConfig(authfile, creds); err != nil {
		fmt.Printf("Nanobox failed to parse the .auth file.\n")
		os.Exit(1)
	}
}
Beispiel #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
	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
}
Beispiel #3
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
}