示例#1
0
文件: gaudi.go 项目: hungld/gaudi
func (g *Gaudi) copyRelativeFiles(filePath, destination string) bool {
	// File cannot be absolute
	if util.IsFile(filePath) && filePath[0] == '/' {
		util.LogError("File '" + filePath + "' cannot be an absolute path")
	}

	// Check if the relative file exists
	absolutePath := g.ApplicationDir + "/" + filePath
	if util.IsFile(absolutePath) {

		// Move file to the build context (and keep the same file tree)
		directories := strings.Split(filePath, "/")
		if len(directories) > 1 {
			os.MkdirAll(destination+strings.Join(directories[0:len(directories)-1], "/"), 0755)
		}

		err := util.Copy(destination+filePath, absolutePath)
		if err != nil {
			util.LogError(err)
		}

		return true
	}

	return false
}
示例#2
0
func (maestro *Maestro) InitFromString(content, relativePath string) {
	err := goyaml.Unmarshal([]byte(content), &maestro)
	if err != nil {
		panic(err)
	}
	if maestro.Applications == nil {
		panic("No application to start")
	}

	// Fill name & dependencies
	for name := range maestro.Applications {
		currentContainer := maestro.Applications[name]
		currentContainer.Name = name

		if currentContainer.IsGaudiManaged() {
			currentContainer.Image = "gaudi/" + name
		}

		for _, dependency := range currentContainer.Links {
			if depContainer, exists := maestro.Applications[dependency]; exists {
				currentContainer.AddDependency(depContainer)
			} else {
				panic(name + " references a non existing application : " + dependency)
			}
		}

		// Add relative path to volumes
		for volumeHost, volumeContainer := range currentContainer.Volumes {
			// Relative volume host
			if string(volumeHost[0]) != "/" {
				delete(currentContainer.Volumes, volumeHost)
				volumeHost = relativePath + "/" + volumeHost

				currentContainer.Volumes[volumeHost] = volumeContainer
			}

			// Check if directory exists
			if !util.IsDir(volumeHost) {
				err := os.MkdirAll(volumeHost, 0755)
				if err != nil {
					panic(err)
				}
			}
		}

		// Check if the beforeScript is a file
		beforeScript := currentContainer.BeforeScript
		if len(beforeScript) != 0 {
			if util.IsFile(beforeScript) {
				currentContainer.BeforeScript = beforeScript
			} else if util.IsFile(relativePath + "/" + beforeScript) {
				currentContainer.BeforeScript = relativePath + "/" + beforeScript
			}
		}
	}
}
示例#3
0
文件: gaudi.go 项目: hungld/gaudi
func (gaudi *Gaudi) GetContainerTemplate(container *container.Container) (string, bool) {
	templatePath := TEMPLATE_DIR + container.Type
	isCustom := container.Type == "custom"

	// Check if the application has a custom template
	if isCustom {
		templatePath = container.Template

		// Allows relative path with ./
		if len(templatePath) > 1 && templatePath[0] == '.' && templatePath[1] == '/' {
			templatePath = gaudi.ApplicationDir + "/" + strings.Join(strings.Split(templatePath, "/")[1:], "/")
		}

		// Handle relative patch without ./
		if templatePath[0] != '/' {
			templatePath = gaudi.ApplicationDir + "/" + templatePath
		}

		// Template path should be a directory
		if util.IsFile(templatePath) {
			templateParts := strings.Split(templatePath, "/")
			templatePath = strings.Join(templateParts[0:len(templateParts)-1], "/")
		}
	}

	return templatePath, isCustom
}
示例#4
0
文件: gaudi.go 项目: hungld/gaudi
func (gaudi *Gaudi) useNewVersion() bool {
	useNewVersion := true
	versionFile := gaudi.ApplicationDir + "/.gaudi/version.txt"

	if util.IsFile(versionFile) {
		oldVersion, _ := ioutil.ReadFile(versionFile)
		useNewVersion = string(oldVersion) != VERSION
	}

	// Write new version
	ioutil.WriteFile(versionFile, []byte(VERSION), 775)

	return useNewVersion
}
示例#5
0
文件: gaudi.go 项目: hungld/gaudi
func (gaudi *Gaudi) shouldRebuild() bool {
	shouldRebuild := true
	checkSumFile := gaudi.ApplicationDir + "/.gaudi/.gaudi.sum"
	currentCheckSum := util.GetFileCheckSum(gaudi.ConfigurationPath)

	if util.IsFile(checkSumFile) {
		oldCheckSum, _ := ioutil.ReadFile(checkSumFile)

		shouldRebuild = string(oldCheckSum) != currentCheckSum
	}

	// Write new checksum
	ioutil.WriteFile(checkSumFile, []byte(currentCheckSum), 775)

	return shouldRebuild
}
示例#6
0
文件: main.go 项目: hungld/gaudi
func retrieveConfigPath(configFile string) string {
	if len(configFile) == 0 {
		util.LogError("Config file name cannot be empty.")
	}

	if string(configFile[0]) != "/" {
		currentDir, err := os.Getwd()
		if err != nil {
			util.LogError(err)
		}

		configFile = currentDir + "/" + configFile
	}

	if !util.IsFile(configFile) {
		util.LogError("Configuration file not found: '" + configFile + "'. Use --config to specify a custom file")
	}

	return configFile
}
示例#7
0
文件: main.go 项目: jpetitcolas/gaudi
func retrieveConfigPath(configFile string) string {
	if len(configFile) == 0 {
		panic("Config file name cannot be empty.")
	}

	if string(configFile[0]) != "/" {
		currentDir, err := os.Getwd()
		if err != nil {
			panic(err)
		}

		configFile = currentDir + "/" + configFile
	}

	if !util.IsFile(configFile) {
		panic("Config file must be a file.")
	}

	return configFile
}