From 8436dc39196989596d749469f6dd4312c2c586fe Mon Sep 17 00:00:00 2001 From: Dean Hunter Date: Mon, 19 Feb 2024 15:59:13 +0100 Subject: [PATCH] Added error handling for dockerbuild. --- Client/kaniko/cmd.go | 12 ++++++++++-- Client/kaniko/kaniko.go | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Client/kaniko/cmd.go b/Client/kaniko/cmd.go index 55a6bdb..03d705c 100644 --- a/Client/kaniko/cmd.go +++ b/Client/kaniko/cmd.go @@ -118,9 +118,17 @@ func (kd *KanikoDocker) BuildImage(options shared.BuildOptions, contextPath stri } for _,stage := range stages{ kanikoExecutor.Destination[0] = stage - stdout, stderr, _ := kanikoExecutor.Execute() + stdout, stderr, err := kanikoExecutor.Execute() + if err !=nil{ + panic(err) + } + if len(stdout)==0{ + panic("No output from docker build.") + } + if len(stderr)>0{ + panic(stderr) + } fmt.Println(stdout) - fmt.Println(stderr) } } else { fmt.Println("Executor is not of type *KanikoExecutor and does not have a Context field.") diff --git a/Client/kaniko/kaniko.go b/Client/kaniko/kaniko.go index 4012567..72e59d6 100644 --- a/Client/kaniko/kaniko.go +++ b/Client/kaniko/kaniko.go @@ -8,7 +8,6 @@ import ( "fmt" "os" "syscall" - "log" ) type KanikoExecutor struct { @@ -85,17 +84,18 @@ func (ke *KanikoExecutor) Execute() (string, string, error) { //ke.Registry.RecordImage(ke.Destination[0], "/path/to/local/image/or/remote/repository") // Change root to the new directory if err := syscall.Chroot(ke.RootDir); err != nil { - log.Fatalf("Chroot to %s failed: %v", ke.RootDir, err) + fmt.Println("Change root to the new directory failed") return "","",err } // Changing directory to "/" if err := os.Chdir("/"); err != nil { - log.Fatalf("Chdir to / failed: %v", err) + fmt.Println("Change directory to / failed") + return "","",err } fmt.Println(args) - cmd := exec.Command("executor", args...) + cmd := exec.Command("/kaniko/executor", args...) var stdout, stderr bytes.Buffer cmd.Stdout = &stdout cmd.Stderr = &stderr