about summary refs log tree commit diff
path: root/templater/templater.go
diff options
context:
space:
mode:
authornoqcks <benny@noqcks.io>2018-03-29T17·12-0400
committerVincent Ambo <github@tazj.in>2018-03-29T18·05+0200
commite1c2c19330911d9e35b03b8b08681e0a7cd0cb70 (patch)
treeec4806e58399fb34eb94a0b618dcdc8b03564d97 /templater/templater.go
parent867f40307e9038406625bccf8047f627dd7cb148 (diff)
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.
Diffstat (limited to 'templater/templater.go')
-rw-r--r--templater/templater.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/templater/templater.go b/templater/templater.go
index bfd2af1f61bf..89cc1cd732b5 100644
--- a/templater/templater.go
+++ b/templater/templater.go
@@ -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))