Skip to content

Commit

Permalink
fix(cli): make sure kamel local run clean up dirs at ctrl+c
Browse files Browse the repository at this point in the history
Fix #3029
  • Loading branch information
tadayosi committed Mar 9, 2022
1 parent ed3d71b commit 819dda0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions pkg/cmd/local_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package cmd

import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -43,6 +46,19 @@ func newCmdLocalRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localRunCm
if err := options.init(); err != nil {
return err
}

// make sure cleanup is done when process is stopped externally
cs := make(chan os.Signal, 1)
signal.Notify(cs, os.Interrupt, syscall.SIGTERM)
go func() {
<-cs
if err := options.deinit(); err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(0)
}()

if err := options.run(cmd, args); err != nil {
fmt.Println(err.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/util_containerization.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func createAndBuildBaseImage(ctx context.Context) error {
cmd := exec.CommandContext(ctx, "docker", args...)

// Output executed command.
fmt.Printf("Executing: " + strings.Join(cmd.Args, " ") + "\n")
fmt.Printf("Executing: %s\n", strings.Join(cmd.Args, " "))

// Run the command.
if err := cmd.Run(); err != nil {
Expand Down Expand Up @@ -192,7 +192,7 @@ func createAndBuildIntegrationImage(ctx context.Context, containerRegistry strin
cmd.Stdout = stdout

// Output executed command.
fmt.Printf("Executing: " + strings.Join(cmd.Args, " ") + "\n")
fmt.Printf("Executing: %s\n", strings.Join(cmd.Args, " "))

// Run the command.
if err := cmd.Run(); err != nil {
Expand Down Expand Up @@ -225,7 +225,7 @@ func runIntegrationImage(ctx context.Context, image string, stdout, stderr io.Wr
cmd.Stdout = stdout

// Output executed command.
fmt.Printf("Executing: " + strings.Join(cmd.Args, " ") + "\n")
fmt.Printf("Executing: %s\n", strings.Join(cmd.Args, " "))

// Run the command.
if err := cmd.Run(); err != nil {
Expand Down

0 comments on commit 819dda0

Please sign in to comment.