func (w *ServiceYAMLWriterBase) Write(context interface{}) error { templateName := fmt.Sprintf("%s.service.yml.template", w.GetPack().Name()) if !common.FileExists(filepath.Join(w.TemplateDir, templateName)) { templateName = "service.yml.template" // fall back on generic template } err := w.WriteTemplate(templateName, "service.yml", context) if err != nil { return err } return w.removeBlankLines() }
func (a *Analyzer) FindDatabases() *common.Lister { dbs := common.NewLister() if hasMysql, _ := common.GetGemVersion(a.Gemfile, "mysql2"); hasMysql { dbs.Add("mysql") } if hasPg, _ := common.GetGemVersion(a.Gemfile, "pg"); hasPg { dbs.Add("postgresql") } if hasRedis, _ := common.GetGemVersion(a.Gemfile, "redis", "redis-rails"); hasRedis { dbs.Add("redis") } if hasMongoDB, _ := common.GetGemVersion(a.Gemfile, "mongo", "mongo_mapper", "dm-mongo-adapter", "mongoid"); hasMongoDB { dbs.Add("mongodb") } if hasElasticsearch, _ := common.GetGemVersion(a.Gemfile, "elasticsearch", "tire", "flex", "chewy"); hasElasticsearch { dbs.Add("elasticsearch") } if hasDatabaseYaml := common.FileExists("config/database.yml"); hasDatabaseYaml { common.PrintlnL2("Found config/database.yml") a.Messages.Add( fmt.Sprintf("%s %s-> %s", "database.yml: Make sure you are using environment variables.", common.MsgReset, "http://help.cloud66.com/deployment/environment-variables")) } if hasMongoIdYaml := common.FileExists("config/mongoid.yml"); hasMongoIdYaml { common.PrintlnL2("Found config/mongoid.yml") a.Messages.Add( fmt.Sprintf("%s %s-> %s", "mongoid.yml: Make sure you are using environment variables.", common.MsgReset, "http://help.cloud66.com/deployment/environment-variables")) } return dbs }
func testApplication(t *testing.T, path string) { rootDir := "test/" + path var binPath string if common.FileExists("./starter") { binPath = "./starter" } else { binPath = "./starter-source" } command := exec.Command(binPath, "-y", "-p", rootDir+"/src") defer os.Remove(rootDir + "/src/Dockerfile") defer os.Remove(rootDir + "/src/service.yml") _, err := command.Output() if err != nil { t.FailNow() } AssertFilesHaveSameContent(t, rootDir+"/expected/Dockerfile", rootDir+"/src/Dockerfile") AssertFilesHaveSameContent(t, rootDir+"/expected/service.yml", rootDir+"/src/service.yml") }
func (a *AnalyzerBase) analyzeProcfile() ([]*common.Service, error) { services := []*common.Service{} procfilePath := filepath.Join(a.RootDir, "Procfile") if !common.FileExists(procfilePath) { a.Messages.Add("No Procfile was detected. It is strongly advised to add one in order to specify the commands to run your services.") return services, nil } common.PrintlnL2("Parsing Procfile") procs, err := common.ParseProcfile(procfilePath) if err != nil { return nil, err } for _, proc := range procs { common.PrintlnL2("Found Procfile item %s", proc.Name) services = append(services, &common.Service{Name: proc.Name, Command: proc.Command}) } return services, nil }
func (w *TemplateWriterBase) shouldOverwriteExistingFile(filename string) bool { if !common.FileExists(filename) { return true } isStarterTemplate := w.isStarterTemplate(filename) if isStarterTemplate { return true } if !w.ShouldPrompt { return isStarterTemplate } answer := "none" for answer != "o" && answer != "r" && answer != "" { common.PrintL1("%s cannot be written as it already exists. What to do? [o: overwrite, R: rename] ", filepath.Base(filename)) if _, err := fmt.Scanln(&answer); err != nil { return false } answer = strings.TrimSpace(strings.ToLower(answer)) } return answer == "o" }
func (d *Detector) Detect(rootDir string) bool { return common.FileExists(filepath.Join(rootDir, "package.json")) }
func (d *Detector) Detect(rootDir string) bool { return common.FileExists(filepath.Join(rootDir, "Gemfile")) }
func (d *Detector) Detect(rootDir string) bool { return common.FileExists(filepath.Join(rootDir, "requirements.txt")) }