From f733ada512c2b9a3adcbbe11fa343d2f1de79bfd Mon Sep 17 00:00:00 2001 From: Vibhav Pant Date: Fri, 18 Mar 2016 11:33:20 +0530 Subject: [PATCH] Add workdir --- main.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 06cca1c..5835391 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "os/exec" + "path/filepath" ) type image struct { @@ -18,9 +19,10 @@ type image struct { } var ( - conf = flag.String("conf", "", "configuration file to read from") - addr = flag.String("http", ":8080", "http address to listen on") - images []image + conf = flag.String("conf", "", "configuration file to read from") + addr = flag.String("http", ":8080", "http address to listen on") + workdir = flag.String("workdir", ".", "work directory") + images []image ) func execHook(image, tag string, commands [][]string) { @@ -106,6 +108,17 @@ func main() { return } + path, err := filepath.Abs(*workdir) + if err != nil { + log.Fatal(err) + } + + err = os.Chdir(path) + if err != nil { + log.Fatal(err) + } + + log.Printf("Reading hooks from %s/%s", path, *conf) bytes, err := ioutil.ReadFile(*conf) if err != nil { log.Fatal(err)