-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (64 loc) · 1.72 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"log"
"os"
"path/filepath"
"sync"
"time"
"github.com/resinstack/emissary/pkg/secret"
"github.com/resinstack/emissary/pkg/tmpl"
_ "github.com/resinstack/emissary/pkg/secret/awssm"
_ "github.com/resinstack/emissary/pkg/secret/insecure"
)
func doTemplate(path string, wg *sync.WaitGroup) {
log.Println("Launching template worker for", path)
defer wg.Done()
t, err := tmpl.Parse(path)
if err != nil {
log.Printf("Error parsing template at %s: %s", path, err)
return
}
if err := t.Render(); err != nil {
log.Printf("Error rendering template at %s: %s", path, err)
return
}
log.Printf("Template worker for %s is terminating.", path)
}
func startupDelay() error {
if delay := os.Getenv("EMISSARY_STARTUP_DELAY"); delay != "" {
d, err := time.ParseDuration(delay)
if err != nil {
// This is really the cleanest solution to
// just jump out of this case.
return err
}
log.Printf("Initial startup delay of %s", d)
time.Sleep(d)
}
return nil
}
func main() {
log.Println("Emissary is starting")
if err := startupDelay(); err != nil {
log.Printf("Startup delay error: %s", err)
}
log.Println("Startup delay phase is complete")
secret.InitializeProviders()
basepath := os.Getenv("EMISSARY_TPL_DIR")
if basepath == "" {
basepath, _ = os.Getwd()
}
log.Printf("Searching for templates in %s", basepath)
// The only errors that filepath can throw are related to
// parsing the glob. Its hardcoded here and this is known to
// work.
tmpls, _ := filepath.Glob(filepath.Join(basepath, "*.tpl"))
var wg sync.WaitGroup
for _, t := range tmpls {
wg.Add(1)
go doTemplate(t, &wg)
}
wg.Wait()
log.Println("All template workers terminated")
log.Println("Emissary is shutting down")
}