From cef87c4350d2bb8a60b1617ac73f5a6f3978471c Mon Sep 17 00:00:00 2001 From: Moritz Clasmeier Date: Fri, 9 Jan 2026 13:07:51 +0100 Subject: [PATCH 1/5] Detect running non-interactively. Disable sub-shell spawning if non-interactively. --- cmd/deploy.go | 11 +++++++++++ go.mod | 3 ++- go.sum | 4 ++++ internal/env/env.go | 16 +++++++++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/cmd/deploy.go b/cmd/deploy.go index 2b4ecc50..0c6a20cb 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -53,6 +53,12 @@ func runDeploy(cmd *cobra.Command, args []string) error { log.Dim("Running containerized.") } + if env.RunningInteractively { + log.Dim("Running interactively.") + } else { + log.Dim("Running non-interactively.") + } + component := "both" if len(args) > 0 { component = args[0] @@ -62,6 +68,10 @@ func runDeploy(cmd *cobra.Command, args []string) error { return errors.New("already in a roxie sub-shell (ROXIE_SHELL environment variable is set), please exit the shell and try again") } + if !env.RunningInteractively && envrc == "" { + return errors.New("running non-interactively requires --envrc to be set") + } + if envrc != "" && portForwarding { return errors.New("cannot use --envrc with --port-forwarding. The --envrc flag is for non-interactive mode with remote cluster access") } @@ -116,6 +126,7 @@ func runDeploy(cmd *cobra.Command, args []string) error { } if envrc != "" { + log.Dimf("Writing environment variables to %s", envrc) d.SetEnvrcFile(envrc) } diff --git a/go.mod b/go.mod index 91f382c0..123949a7 100644 --- a/go.mod +++ b/go.mod @@ -14,5 +14,6 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/sys v0.14.0 // indirect + golang.org/x/sys v0.39.0 // indirect + golang.org/x/term v0.38.0 // indirect ) diff --git a/go.sum b/go.sum index 651f17ee..f1342ea9 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,10 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= +golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q= +golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/env/env.go b/internal/env/env.go index 0f9adbc3..75026755 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -9,10 +9,12 @@ import ( "strings" "github.com/stackrox/roxie/internal/containerutil" + "golang.org/x/term" ) var ( - RunningInContainer bool + RunningInContainer bool + RunningInteractively bool ) // ClusterType represents different types of Kubernetes clusters @@ -47,6 +49,18 @@ func init() { if RunningInContainer { os.Setenv("KUBECONFIG", "/kubeconfig") } + RunningInteractively = isRunningInteractively() +} + +// isRunningInteractively detects if roxie is running interactively +// by checking if stdin, stdout, and stderr are all connected to a terminal. +func isRunningInteractively() bool { + for _, f := range []*os.File{os.Stdin, os.Stdout, os.Stderr} { + if !term.IsTerminal(int(f.Fd())) { + return false + } + } + return true } // ensureInitialized performs lazy initialization of cluster information From 4560bc7bbf7786b080fd269d41fb70af22bc789b Mon Sep 17 00:00:00 2001 From: Moritz Clasmeier Date: Tue, 13 Jan 2026 15:43:42 +0100 Subject: [PATCH 2/5] Updated go.mod,go.sum --- go.mod | 2 +- go.sum | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 123949a7..a457e6c9 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/fatih/color v1.16.0 github.com/moby/sys/mountinfo v0.7.2 github.com/spf13/cobra v1.8.0 + golang.org/x/term v0.38.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -15,5 +16,4 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/spf13/pflag v1.0.5 // indirect golang.org/x/sys v0.39.0 // indirect - golang.org/x/term v0.38.0 // indirect ) diff --git a/go.sum b/go.sum index f1342ea9..d1733f43 100644 --- a/go.sum +++ b/go.sum @@ -17,8 +17,6 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q= From 5d679e7df34a10bff3c8c64d3ec0e51c4ecbe9cc Mon Sep 17 00:00:00 2001 From: Moritz Clasmeier Date: Fri, 16 Jan 2026 09:23:42 +0100 Subject: [PATCH 3/5] Change message --- cmd/deploy.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/deploy.go b/cmd/deploy.go index 0c6a20cb..cc2eb513 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -54,9 +54,9 @@ func runDeploy(cmd *cobra.Command, args []string) error { } if env.RunningInteractively { - log.Dim("Running interactively.") + log.Dim("Running with controlling terminal.") } else { - log.Dim("Running non-interactively.") + log.Dim("Running without controlling terminal.") } component := "both" From 8e8a88c965517298d4398a232764243c6da4c0ba Mon Sep 17 00:00:00 2001 From: Moritz Clasmeier <111092021+mclasmeier@users.noreply.github.com> Date: Mon, 19 Jan 2026 09:50:40 +0100 Subject: [PATCH 4/5] Update cmd/deploy.go Co-authored-by: Marcin Owsiany --- cmd/deploy.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/deploy.go b/cmd/deploy.go index cc2eb513..2b1e5949 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -54,9 +54,9 @@ func runDeploy(cmd *cobra.Command, args []string) error { } if env.RunningInteractively { - log.Dim("Running with controlling terminal.") + log.Dim("Running with a controlling terminal.") } else { - log.Dim("Running without controlling terminal.") + log.Dim("Running without a controlling terminal.") } component := "both" From b5a8789bd80e12744d8906d14bc895bcf936bcb4 Mon Sep 17 00:00:00 2001 From: Moritz Clasmeier <111092021+mclasmeier@users.noreply.github.com> Date: Mon, 19 Jan 2026 09:51:07 +0100 Subject: [PATCH 5/5] Update cmd/deploy.go Co-authored-by: Marcin Owsiany --- cmd/deploy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/deploy.go b/cmd/deploy.go index 2b1e5949..eb7f2afd 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -69,7 +69,7 @@ func runDeploy(cmd *cobra.Command, args []string) error { } if !env.RunningInteractively && envrc == "" { - return errors.New("running non-interactively requires --envrc to be set") + return errors.New("running without a controlling terminal requires --envrc to be set") } if envrc != "" && portForwarding {