Ejemplo n.º 1
0
func (b *Build) readRuntimeConfig(data []byte) error {

	// Temp work dir
	tmpPath, err := ioutil.TempDir("", bson.NewObjectId().Hex())
	if err != nil {
		return err
	}
	defer os.RemoveAll(tmpPath)

	// Write zip file
	zipPath := path.Join(tmpPath, "karhu.zip")
	if err := ioutil.WriteFile(zipPath, data, 0644); err != nil {
		return err
	}

	// Unzip file
	if err := file.Unzip(zipPath, tmpPath); err != nil {
		return err
	}

	// Read karhu file
	data, err = ioutil.ReadFile(path.Join(tmpPath, KARHU_FILE_NAME))
	if err != nil {
		log.Println("models/Build: ReadFile:", err)
		return err
	}

	config := new(RuntimeConfiguration)
	if err := yaml.Unmarshal(data, config); err != nil {
		log.Println("models/Build: Unmarshal:", err)
		return err
	}

	app, err := b.GetApplication()
	if err != nil {
		log.Println("models/Build: GetApplication:", err)
		return err
	}

	// Setup workdir if needed
	if config.Workdir == "" {
		config.Workdir = path.Join(KARHU_DEFAULT_RUNTIME_WORKDIR_BASE, app.Name)
	}

	if config.User == "" {
		config.User = "******"
	}

	if config.Binary != nil && config.Binary.User == "" {
		config.Binary.User = config.User
	}

	if err := config.isValid(); err != nil {
		return err
	}

	b.RuntimeCfg = config

	return nil
}
Ejemplo n.º 2
0
func (d *Deployment) extractArchive(workdir string) error {

	if d.Application.Type != APPLICATION_TYPE_APP {
		return nil
	}

	// Fetch zip
	data, err := file.Get(d.Build.FilePath)
	if err != nil {
		return err
	}

	// Write zip file
	zipPath := path.Join(workdir, "karhu.zip")
	if err := ioutil.WriteFile(zipPath, data, 0644); err != nil {
		return err
	}

	destDir := path.Join(workdir, "karhu")
	if err := os.MkdirAll(destDir, 0755); err != nil {
		return err
	}

	// Unzip file
	if err := file.Unzip(zipPath, destDir); err != nil {
		return err
	}

	return nil
}