Skip to content

Commit

Permalink
fix(build): terminate program if docker build fails
Browse files Browse the repository at this point in the history
  • Loading branch information
tunahanertekin committed May 23, 2023
1 parent 1e74861 commit 517a669
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pkg/docker/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -108,7 +109,7 @@ func printBuildLogs(dst io.Writer, rd io.Reader) error {
scanner := bufio.NewScanner(rd)
for scanner.Scan() {
lastLine = scanner.Text()
io.Copy(dst, rd)
fmt.Fprintln(dst, lastLine)
}

errLine := &ErrorLine{}
Expand Down
13 changes: 10 additions & 3 deletions pkg/process/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,38 @@ func handleSignal() {
go func() {
for sig := range c {
fmt.Println("Stopped process: " + sig.String())
if logSpinner.Enabled() {
logSpinner.Stop()
}
terminateSpinner()
os.Exit(1)
}
}()
}

func terminateSpinner() {
if logSpinner.Enabled() {
logSpinner.Stop()
}
}

func start(step *api.Step, status *api.StepStatus, lc api.LaunchConfig) error {

go handleSignal()
status.Step = *step

baseStep, err := step.GetBaseStep(lc)
if err != nil {
terminateSpinner()
return err
}

if err := build(step, baseStep, status, lc); err != nil {
status.Phase = api.StepPhaseFailed
terminateSpinner()
return err
}
if step.Push && len(step.Platforms) == 0 {
if err := push(step, status, lc); err != nil {
status.Phase = api.StepPhaseFailed
terminateSpinner()
return err
}
}
Expand Down

0 comments on commit 517a669

Please sign in to comment.