Support for environment variables substitution

Now user can put environment variables in docker-compose
file and it will be read by kompose from environment

Fixes # 56
This commit is contained in:
Suraj Deshmukh
2016-07-26 12:55:23 +00:00
parent 278a8af04f
commit 934a3e1a9a
9 changed files with 106 additions and 81 deletions
+22
View File
@@ -20,6 +20,7 @@ import (
"fmt"
"math/rand"
"os"
"path/filepath"
"strconv"
"strings"
@@ -27,7 +28,9 @@ import (
"github.com/urfave/cli"
"github.com/docker/docker/api/client/bundlefile"
"github.com/docker/libcompose/config"
"github.com/docker/libcompose/docker"
"github.com/docker/libcompose/lookup"
"github.com/docker/libcompose/project"
"encoding/json"
@@ -742,6 +745,25 @@ func loadComposeFile(file string, c *cli.Context) KomposeObject {
}
context.ComposeFiles = []string{file}
if context.ResourceLookup == nil {
context.ResourceLookup = &lookup.FileResourceLookup{}
}
if context.EnvironmentLookup == nil {
cwd, err := os.Getwd()
if err != nil {
return KomposeObject{}
}
context.EnvironmentLookup = &lookup.ComposableEnvLookup{
Lookups: []config.EnvironmentLookup{
&lookup.EnvfileLookup{
Path: filepath.Join(cwd, ".env"),
},
&lookup.OsEnvLookup{},
},
}
}
// load compose file into composeObject
composeObject := project.NewProject(&context.Context, nil, nil)
err := composeObject.Parse()