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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ USER roxie

# Set environment variables
ENV HOME=/ \
RUNNING_IN_ROXIE_CONTAINER=true \
KUBECONFIG=/kubeconfig \
PATH=/usr/local/bin:$PATH

Expand Down
4 changes: 1 addition & 3 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func runDeploy(cmd *cobra.Command, args []string) error {

portForwardEnabledFinal := portForwarding || exposure == "none"

if env.RunningInContainer {
if env.RunningInRoxieContainer {
// For running containerized we have specific requirements.
if portForwardEnabledFinal {
return errors.New("containerized mode does not support port-forwarding")
Expand All @@ -117,8 +117,6 @@ func runDeploy(cmd *cobra.Command, args []string) error {
return fmt.Errorf("containerized mode requires /kubeconfig file: %w", err)
}
}
log.Dim("Using KUBECONFIG=/kubeconfig.")
os.Setenv("KUBECONFIG", "/kubeconfig")
}

if konflux {
Expand Down
8 changes: 4 additions & 4 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func runEnv(cmd *cobra.Command, args []string) error {

fmt.Println("Roxie Environment Information:")
fmt.Println("==============================")
fmt.Printf("Kube config: %s\n", os.Getenv("KUBECONFIG"))
fmt.Printf("Running in Container: %v\n", env.RunningInContainer)
fmt.Printf("Current Context: %s\n", env.GetCurrentContext())
fmt.Printf("Cluster Type: %s\n", env.GetCurrentClusterType().String())
fmt.Printf("Kube config: %s\n", os.Getenv("KUBECONFIG"))
fmt.Printf("Running in roxie container: %v\n", env.RunningInRoxieContainer)
fmt.Printf("Current Context: %s\n", env.GetCurrentContext())
fmt.Printf("Cluster Type: %s\n", env.GetCurrentClusterType().String())

return nil
}
2 changes: 1 addition & 1 deletion cmd/subshell.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func printBanner(endpoint, exposure string, haproxyAvailable, haproxyStarted boo
cyan.Println("[roxie] Central UI: http://localhost:8080 (username: admin, password: see $ROX_ADMIN_PASSWORD)")
} else if exposure != "none" && exposure != "" {
cyan.Printf("[roxie] Central UI: https://%s", endpoint)
} else if !env.RunningInContainer {
} else if !env.RunningInRoxieContainer {
cyan.Println("[roxie] Note: Installing haproxy enables automatic HTTP access to Central at http://localhost:8080")
}

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ go 1.25.0

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
k8s.io/apimachinery v0.35.3
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -20,7 +20,9 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
golang.org/x/net v0.48.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
25 changes: 14 additions & 11 deletions internal/containerutil/detect.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package containerutil

import (
"github.com/moby/sys/mountinfo"
"fmt"
"os"
"strconv"
)

// IsRunningInContainer detects if the current process is running inside
// a Docker, Podman, or Kubernetes container by checking if the root
// filesystem is an overlay filesystem (standard for containers).
func IsRunningInContainer() bool {
// Get root mount info using efficient filter
rootMounts, err := mountinfo.GetMounts(mountinfo.SingleEntryFilter("/"))
if err != nil || len(rootMounts) == 0 {
// IsRunningInRoxieContainer checks if we are running inside the released roxie container.
// This knowledge allows us to adjust behavior accordingly, allowing for some UX improvements.
func IsRunningInRoxieContainer() bool {
strVal, exists := os.LookupEnv("RUNNING_IN_ROXIE_CONTAINER")
if !exists || strVal == "" {
return false
}

// Containers use overlay filesystem for root
return rootMounts[0].FSType == "overlay"
val, err := strconv.ParseBool(strVal)
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: Invalid value for RUNNING_IN_ROXIE_CONTAINER: %s. Expected a boolean value (true/false). Defaulting to false.\n", strVal)
return false
}
return val
}
23 changes: 9 additions & 14 deletions internal/containerutil/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@ package containerutil

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsRunningInContainer(t *testing.T) {
// This test simply verifies the function doesn't panic
// The actual result depends on whether the test is running
// inside a container or not
result := IsRunningInContainer()
func TestIsRunningInRoxieContainer(t *testing.T) {
t.Setenv("RUNNING_IN_ROXIE_CONTAINER", "true")
assert.True(t, IsRunningInRoxieContainer(), "Expected to detect running in roxie container when environment variable is set")

// Log the result for informational purposes
t.Logf("IsRunningInContainer() = %v", result)
t.Setenv("RUNNING_IN_ROXIE_CONTAINER", "")
assert.False(t, IsRunningInRoxieContainer(), "Expected to not detect running in roxie container when environment variable is unset")

// We can't assert a specific value since it depends on the environment
// But we can verify it returns a boolean without errors
if result {
t.Log("Detected running inside a container")
} else {
t.Log("Detected running on host (not in container)")
}
t.Setenv("RUNNING_IN_ROXIE_CONTAINER", "garbage")
assert.False(t, IsRunningInRoxieContainer(), "Expected to not detect running in roxie container when environment variable has invalid value")
}
16 changes: 8 additions & 8 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
)

var (
RunningInContainer bool
RunningInteractively bool
initializationMutex sync.Mutex
RunningInRoxieContainer bool
RunningInteractively bool
initializationMutex sync.Mutex
)

// ClusterType represents different types of Kubernetes clusters
Expand Down Expand Up @@ -51,8 +51,8 @@ var (
)

func init() {
RunningInContainer = containerutil.IsRunningInContainer()
if RunningInContainer {
RunningInRoxieContainer = containerutil.IsRunningInRoxieContainer()
if RunningInRoxieContainer {
os.Setenv("KUBECONFIG", "/kubeconfig")
}
RunningInteractively = isRunningInteractively()
Expand Down Expand Up @@ -143,7 +143,7 @@ func Initialize(log *logger.Logger) error {
if log == nil {
log = logger.New()
}
if RunningInContainer {
if RunningInRoxieContainer {
log.Dim("Running containerized.")
}

Expand Down Expand Up @@ -284,11 +284,11 @@ func kubeconfigChecks(log *logger.Logger) error {
if err != nil {
log.Warningf("Kubeconfig %s cannot be opened for reading.", kubeConfigPath)
if errors.Is(err, os.ErrNotExist) {
if RunningInContainer {
if RunningInRoxieContainer {
log.Warningf("Make sure that your kubeconfig is mounted into the container, as in: -v $KUBECONFIG:/kubeconfig:U")
}
} else {
if RunningInContainer {
if RunningInRoxieContainer {
log.Warningf("Make sure that your kubeconfig is mounted with the 'U' option, as in: -v $KUBECONFIG:/kubeconfig:U")
}
}
Expand Down
Loading