Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func runDeploy(cmd *cobra.Command, args []string) error {
log.Dim("Running containerized.")
}

if env.RunningInteractively {
log.Dim("Running with a controlling terminal.")
} else {
log.Dim("Running without a controlling terminal.")
}

component := "both"
if len(args) > 0 {
component = args[0]
Expand All @@ -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 without a controlling terminal 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")
}
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -14,5 +15,5 @@ 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
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ 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=
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=
Expand Down
16 changes: 15 additions & 1 deletion internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())) {
Comment thread
mclasmeier marked this conversation as resolved.
return false
}
}
return true
}

// ensureInitialized performs lazy initialization of cluster information
Expand Down
Loading