Skip to content

Commit 2fe6ff5

Browse files
committed
Add .Env to access local environment variables
Fixes #17
1 parent c33c8fd commit 2fe6ff5

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

docker-gen.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ type ConfigFile struct {
7979
Config []Config
8080
}
8181

82+
type Context []*RuntimeContainer
83+
84+
func (c *Context) Env() map[string]string {
85+
86+
env := make(map[string]string)
87+
for _, i := range os.Environ() {
88+
parts := strings.Split(i, "=")
89+
env[parts[0]] = parts[1]
90+
}
91+
return env
92+
93+
}
94+
8295
func (c *ConfigFile) filterWatches() ConfigFile {
8396
configWithWatches := []Config{}
8497

template.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func contains(item map[string]string, key string) bool {
5555
return false
5656
}
5757

58-
func generateFile(config Config, containers []*RuntimeContainer) bool {
58+
func generateFile(config Config, containers Context) bool {
5959
templatePath := config.Template
6060
tmpl, err := template.New(filepath.Base(templatePath)).Funcs(template.FuncMap{
6161
"contains": contains,
@@ -68,7 +68,7 @@ func generateFile(config Config, containers []*RuntimeContainer) bool {
6868
log.Fatalf("unable to parse template: %s", err)
6969
}
7070

71-
filteredContainers := []*RuntimeContainer{}
71+
filteredContainers := Context{}
7272
if config.OnlyPublished {
7373
for _, container := range containers {
7474
if len(container.PublishedAddresses()) > 0 {
@@ -99,7 +99,7 @@ func generateFile(config Config, containers []*RuntimeContainer) bool {
9999

100100
var buf bytes.Buffer
101101
multiwriter := io.MultiWriter(dest, &buf)
102-
err = tmpl.ExecuteTemplate(multiwriter, filepath.Base(templatePath), filteredContainers)
102+
err = tmpl.ExecuteTemplate(multiwriter, filepath.Base(templatePath), &filteredContainers)
103103
if err != nil {
104104
log.Fatalf("template error: %s\n", err)
105105
}

templates/etcd.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
#!/bin/bash
33

4+
# Genenerated by {{ .Env.USER }}
5+
46
{{range $key, $value := .}}
57
{{ $addrLen := len $value.Addresses }}
68
{{ if gt $addrLen 0 }}

0 commit comments

Comments
 (0)