feat(templater) Add a template function to insert surrounding repo's Git hash

A template function has been added that allows one to template the
Git hash of the surrounding repo. This is useful to be able to inspect the
deployment revision of an object in Kubernetes.
This commit is contained in:
noqcks 2018-03-29 13:12:46 -04:00 committed by Vincent Ambo
parent 867f40307e
commit e1c2c19330
2 changed files with 13 additions and 0 deletions

View file

@ -15,6 +15,7 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"strings"
"text/template"
@ -169,6 +170,14 @@ func templateFuncs(rs *context.ResourceSet) template.FuncMap {
return string(b)
}
m["passLookup"] = GetFromPass
m["gitHEAD"] = func() (string, error) {
out, err := exec.Command("sh", "-c", "git rev-parse HEAD").Output()
if err != nil {
return "", err
}
output := strings.TrimSpace(string(out))
return output, nil
}
m["lookupIPAddr"] = GetIPsFromDNS
m["insertFile"] = func(file string) (string, error) {
data, err := ioutil.ReadFile(path.Join(rs.Path, file))