Skip to content

Commit

Permalink
Added error handling for dockerbuild.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeanHnter committed Feb 19, 2024
1 parent 606173b commit 8436dc3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 10 additions & 2 deletions Client/kaniko/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
8 changes: 4 additions & 4 deletions Client/kaniko/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"os"
"syscall"
"log"
)

type KanikoExecutor struct {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8436dc3

Please sign in to comment.