diff --git a/cli/recipe/new.go b/cli/recipe/new.go index 5109ba76..3bf27a98 100644 --- a/cli/recipe/new.go +++ b/cli/recipe/new.go @@ -78,6 +78,7 @@ recipe and domain in the sample environment config). if err != nil { logrus.Fatal(err) } + defer file.Close() tpl, err := template.ParseFiles(path) if err != nil { diff --git a/pkg/config/app.go b/pkg/config/app.go index a413c336..2332ae2f 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "html/template" "io/ioutil" "os" "path" @@ -260,15 +261,27 @@ func TemplateAppEnvSample(recipeName, appName, server, domain string) error { return fmt.Errorf("%s already exists?", appEnvPath) } - envSample = []byte(strings.Replace(string(envSample), fmt.Sprintf("%s.example.com", recipeName), domain, -1)) - envSample = []byte(strings.Replace(string(envSample), "example.com", domain, -1)) - err = ioutil.WriteFile(appEnvPath, envSample, 0664) if err != nil { return err } - logrus.Debugf("copied %s to %s", envSamplePath, appEnvPath) + file, err := os.OpenFile(appEnvPath, os.O_RDWR, 0664) + if err != nil { + return err + } + defer file.Close() + + tpl, err := template.ParseFiles(appEnvPath) + if err != nil { + return err + } + + if err := tpl.Execute(file, struct{ Name string }{recipeName}); err != nil { + return err + } + + logrus.Debugf("copied & templated %s to %s", envSamplePath, appEnvPath) return nil }