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 { if string(volumeHost[0]) != "/" { delete(currentContainer.Volumes, volumeHost) if !util.IsDir(relativePath + "/" + volumeHost) { panic(relativePath + "/" + volumeHost + " should be a directory") } currentContainer.Volumes[relativePath+"/"+volumeHost] = volumeContainer } else if !util.IsDir(volumeHost) { panic(volumeHost + " should be a directory") } } // 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 } } } }
func (gaudi *Gaudi) Init(content string) { err := goyaml.Unmarshal([]byte(content), &gaudi) if err != nil { util.LogError(err) } emptyCmdForContainers = strings.Split(*emptyCmdFlag, ",") // Init all containers gaudi.Applications.AddAmbassadors() gaudi.All = containerCollection.Merge(gaudi.Applications, gaudi.Binaries) if len(gaudi.All) == 0 { util.LogError("No application or binary to start. Are you missing a 'applications' or 'binaries' field in your configuration ?") } hasGaudiManagedContainer := gaudi.All.Init(gaudi.ApplicationDir) // Apply extends gaudi.applyInheritance() // Check if docker is installed if !docker.HasDocker() { util.LogError("Docker should be installed to use Gaudi (see: https://www.docker.io/gettingstarted/).") } // Check if base image is pulled if hasGaudiManagedContainer && !docker.ImageExists(DEFAULT_BASE_IMAGE) { util.PrintGreen("Pulling base image (this may take a few minutes) ...") docker.Pull(DEFAULT_BASE_IMAGE_WITH_TAG) } if gaudi.useNewVersion() { os.RemoveAll(TEMPLATE_DIR) } // Check if templates are present if !util.IsDir(TEMPLATE_DIR) { util.PrintGreen("Retrieving templates ...") retrieveTemplates() extractTemplates() } gaudi.build() }
func (collection ContainerCollection) Init(relativePath string) bool { hasGaudiManagedContainer := false // Fill name & dependencies for name, currentContainer := range collection { currentContainer.Name = name currentContainer.Init() if currentContainer.IsGaudiManaged() { hasGaudiManagedContainer = true currentContainer.Image = "gaudi/" + name } for _, dependency := range currentContainer.Links { if depContainer, exists := collection[dependency]; exists { currentContainer.AddDependency(depContainer) } else { util.LogError(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 } // Create directory if needed if !util.IsDir(volumeHost) { err := os.MkdirAll(volumeHost, 0755) if err != nil { util.LogError(err) } } } } return hasGaudiManagedContainer }