forked from toolshed/abra
refactor(recipe): use method or variable for .env.sample
This commit is contained in:
@ -358,9 +358,8 @@ func GetAppNames() ([]string, error) {
|
||||
|
||||
// TemplateAppEnvSample copies the example env file for the app into the users
|
||||
// env files.
|
||||
func TemplateAppEnvSample(recipeName, appName, server, domain string) error {
|
||||
envSamplePath := path.Join(config.RECIPES_DIR, recipeName, ".env.sample")
|
||||
envSample, err := os.ReadFile(envSamplePath)
|
||||
func TemplateAppEnvSample(r recipe.Recipe2, appName, server, domain string) error {
|
||||
envSample, err := os.ReadFile(r.SampleEnvPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -380,14 +379,14 @@ func TemplateAppEnvSample(recipeName, appName, server, domain string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
newContents := strings.Replace(string(read), recipeName+".example.com", domain, -1)
|
||||
newContents := strings.Replace(string(read), r.Name+".example.com", domain, -1)
|
||||
|
||||
err = os.WriteFile(appEnvPath, []byte(newContents), 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("copied & templated %s to %s", envSamplePath, appEnvPath)
|
||||
log.Debugf("copied & templated %s to %s", r.SampleEnvPath, appEnvPath)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -511,15 +510,8 @@ func ExposeAllEnv(stackName string, compose *composetypes.Config, appEnv envfile
|
||||
func CheckEnv(app App) ([]envfile.EnvVar, error) {
|
||||
var envVars []envfile.EnvVar
|
||||
|
||||
envSamplePath := path.Join(config.RECIPES_DIR, app.Recipe, ".env.sample")
|
||||
if _, err := os.Stat(envSamplePath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return envVars, fmt.Errorf("%s does not exist?", envSamplePath)
|
||||
}
|
||||
return envVars, err
|
||||
}
|
||||
|
||||
envSample, err := envfile.ReadEnv(envSamplePath)
|
||||
r := recipe.Get2(app.Recipe)
|
||||
envSample, err := r.SampleEnv()
|
||||
if err != nil {
|
||||
return envVars, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user