diff --git a/internal/packager/init.go b/internal/packager/init.go index 221847e48..a8e5e3915 100644 --- a/internal/packager/init.go +++ b/internal/packager/init.go @@ -122,6 +122,45 @@ func checkComposeFileVersion(compose map[string]interface{}) error { return schema.Validate(compose, fmt.Sprintf("%v", version)) } +func getEnvFiles(svcName string, envFileEntry interface{}) []string { + var envFiles []string + switch envFileEntry.(type) { + case string: + envFiles = append(envFiles, envFileEntry.(string)) + case []string: + envFiles = append(envFiles, envFileEntry.([]string)...) + case []interface{}: + for _, env := range envFileEntry.([]interface{}) { + envFiles = append(envFiles, env.(string)) + } + default: + logrus.Warnf("unknown entries in 'env_file' for service %s -> %v\n", + svcName, envFileEntry) + return envFiles + } + return envFiles +} + +func checkEnvFiles(cfgMap map[string]interface{}) { + services, ok := cfgMap["services"] + if !ok { + return + } + servicesMap := services.(map[string]interface{}) + for svcName, svc := range servicesMap { + svcContent := svc.(map[string]interface{}) + envFileEntry, ok := svcContent["env_file"] + if !ok { + return + } + for _, envFilePath := range getEnvFiles(svcName, envFileEntry) { + logrus.Warnf("\"env_file: %s\" entry of service %q will NOT be copied automatically! "+ + "Please, copy the file inside the application folder and update your compose file"+ + " referring to it.", envFilePath, svcName) + } + } +} + func initFromComposeFile(name string, composeFile string) error { logrus.Debugf("Initializing from compose file %s", composeFile) @@ -138,6 +177,7 @@ func initFromComposeFile(name string, composeFile string) error { if err := checkComposeFileVersion(cfgMap); err != nil { return err } + checkEnvFiles(cfgMap) params := make(map[string]string) envs, err := opts.ParseEnvFile(filepath.Join(filepath.Dir(composeFile), ".env")) if err == nil {