diff --git a/packages/kn-plugin-workflow/e2e-tests/run_test.go b/packages/kn-plugin-workflow/e2e-tests/run_test.go index f3f371b4b21..e9b724827a4 100644 --- a/packages/kn-plugin-workflow/e2e-tests/run_test.go +++ b/packages/kn-plugin-workflow/e2e-tests/run_test.go @@ -44,8 +44,8 @@ type cfgTestInputRun struct { } var cfgTestInputRun_Success = []cfgTestInputRun{ - {input: command.RunCmdConfig{PortMapping: "8081", OpenDevUI: false}}, - {input: command.RunCmdConfig{}}, + {input: command.RunCmdConfig{PortMapping: "8081", OpenDevUI: false, StopContainerOnUserInput: false}}, + {input: command.RunCmdConfig{StopContainerOnUserInput: false}}, } func transformRunCmdCfgToArgs(cfg command.RunCmdConfig) []string { @@ -56,6 +56,9 @@ func transformRunCmdCfgToArgs(cfg command.RunCmdConfig) []string { if cfg.PortMapping != "" { args = append(args, "--port", cfg.PortMapping) } + if cfg.StopContainerOnUserInput { + args = append(args, "--stop-container-on-user-input", cfg.StopContainerOnUserInput) + } return args } diff --git a/packages/kn-plugin-workflow/pkg/command/run.go b/packages/kn-plugin-workflow/pkg/command/run.go index ca0c462f789..b9218240e58 100644 --- a/packages/kn-plugin-workflow/pkg/command/run.go +++ b/packages/kn-plugin-workflow/pkg/command/run.go @@ -35,6 +35,7 @@ import ( type RunCmdConfig struct { PortMapping string OpenDevUI bool + StopContainerOnUserInput bool } func NewRunCommand() *cobra.Command { @@ -57,6 +58,10 @@ func NewRunCommand() *cobra.Command { # Disable automatic browser launch of SonataFlow Dev UI {{.Name}} run --open-dev-ui=false + + # Stop the container when the user presses any key + {{.Name}} run --stop-container-on-user-input=false + `, SuggestFor: []string{"rnu", "start"}, //nolint:misspell PreRunE: common.BindEnv("port", "open-dev-ui"), @@ -68,6 +73,7 @@ func NewRunCommand() *cobra.Command { cmd.Flags().StringP("port", "p", "8080", "Maps a different host port to the running container port.") cmd.Flags().Bool("open-dev-ui", true, "Disable automatic browser launch of SonataFlow Dev UI") + cmd.Flags().Bool("stop-container-on-user-input", true, "Stop the container when the user presses any key") cmd.SetHelpFunc(common.DefaultTemplatedHelp) return cmd @@ -93,8 +99,9 @@ func run() error { func runDevCmdConfig() (cfg RunCmdConfig, err error) { cfg = RunCmdConfig{ - PortMapping: viper.GetString("port"), - OpenDevUI: viper.GetBool("open-dev-ui"), + PortMapping: viper.GetString("port"), + OpenDevUI: viper.GetBool("open-dev-ui"), + StopContainerOnUserInput: viper.GetBool("stop-container-on-user-input"), } return } @@ -138,8 +145,10 @@ func runSWFProjectDevMode(containerTool string, cfg RunCmdConfig) (err error) { pollInterval := 5 * time.Second common.ReadyCheck(readyCheckURL, pollInterval, cfg.PortMapping, cfg.OpenDevUI) - if err := stopContainer(containerTool); err != nil { - return err + if cfg.StopContainerOnUserInput { + if err := stopContainer(containerTool); err != nil { + return err + } } wg.Wait()