Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/hashicorp/go-version v1.2.0
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c // indirect
github.com/imdario/mergo v0.3.11
github.com/joho/godotenv v1.3.0
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/pierrec/lz4 v2.3.0+incompatible // indirect
github.com/r3labs/diff v0.0.0-20190801153147-a71de73c46ad
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5i
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/joyent/triton-go v0.0.0-20190112182421-51ffac552869/go.mod h1:U+RSyWxWd04xTqnuOQxnai7XGS2PrPY2cfGoDKtMHjA=
github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down
7 changes: 7 additions & 0 deletions pkg/tmpl/context_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tmpl

import (
"fmt"
"github.com/joho/godotenv"
"github.com/roboll/helmfile/pkg/helmexec"
"golang.org/x/sync/errgroup"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -201,6 +202,12 @@ func SetValueAtPath(path string, value interface{}, values Values) (Values, erro
}

func RequiredEnv(name string) (string, error) {
var dotEnv map[string]string
dotEnv, _ = godotenv.Read(".env")
if val := dotEnv[name]; len(val) > 0 {
return val, nil
}

if val, exists := os.LookupEnv(name); exists && len(val) > 0 {
return val, nil
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/tmpl/context_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tmpl
import (
"bytes"
"github.com/Masterminds/sprig/v3"
"github.com/joho/godotenv"
"os"
"text/template"
)

Expand All @@ -15,6 +17,8 @@ func (c *Context) newTemplate() *template.Template {

funcMap := sprig.TxtFuncMap()

funcMap["env"] = Getenv

for orig, alias := range aliases {
aliased[alias] = funcMap[orig]
}
Expand All @@ -36,6 +40,16 @@ func (c *Context) newTemplate() *template.Template {
return tmpl
}

func Getenv(key string) string {
var dotEnv map[string]string
dotEnv, _ = godotenv.Read(".env")
if val := dotEnv[key]; len(val) > 0 {
return val
} else {
return os.Getenv(key)
}
}

func (c *Context) RenderTemplateToBuffer(s string, data ...interface{}) (*bytes.Buffer, error) {
var t, parseErr = c.newTemplate().Parse(s)
if parseErr != nil {
Expand Down