Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Add warnings for env_file entries not copied
Browse files Browse the repository at this point in the history
As 'env_file' entries are not taken in account,
we warn the user to copy that and fix it's
compose file.

Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
  • Loading branch information
Ulysses Souza committed Sep 10, 2019
1 parent 964210e commit b2c349c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions internal/packager/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 {
Expand Down

0 comments on commit b2c349c

Please sign in to comment.