diff --git a/examples/stacks/django/.gitignore b/examples/stacks/django/.gitignore index a59fc151d2e..40505c903de 100644 --- a/examples/stacks/django/.gitignore +++ b/examples/stacks/django/.gitignore @@ -1,3 +1,2 @@ .venv/ __pycache__ -.devbox.cloud \ No newline at end of file diff --git a/go.mod b/go.mod index af656942ae2..be73029ea74 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/denisbrodbeck/machineid v1.0.1 github.com/f1bonacc1/process-compose v1.122.0 github.com/fatih/color v1.19.0 - github.com/fsnotify/fsnotify v1.10.1 github.com/getsentry/sentry-go v0.50.0 github.com/google/go-cmp v0.7.0 github.com/google/uuid v1.6.0 @@ -114,6 +113,7 @@ require ( github.com/f1bonacc1/go-health/v2 v2.1.6 // indirect github.com/fatih/structtag v1.2.0 // indirect github.com/firefart/nonamedreturns v1.0.8 // indirect + github.com/fsnotify/fsnotify v1.10.1 // indirect github.com/fzipp/gocyclo v0.6.0 // indirect github.com/ghostiam/protogetter v1.0.1 // indirect github.com/go-critic/go-critic v0.15.0 // indirect diff --git a/internal/boxcli/midcobra/telemetry.go b/internal/boxcli/midcobra/telemetry.go index 75a98b9490b..71dba36330e 100644 --- a/internal/boxcli/midcobra/telemetry.go +++ b/internal/boxcli/midcobra/telemetry.go @@ -62,7 +62,6 @@ func (m *telemetryMiddleware) postRun(cmd *cobra.Command, args []string, runErr meta := telemetry.Metadata{ FeatureFlags: featureflag.All(), - CloudRegion: os.Getenv(envir.DevboxRegion), CloudCache: os.Getenv(envir.DevboxCache), } @@ -80,7 +79,6 @@ func (m *telemetryMiddleware) postRun(cmd *cobra.Command, args []string, runErr meta.Packages, meta.NixpkgsHash = getPackagesAndCommitHash() meta.InShell = envir.IsDevboxShellEnabled() meta.InBrowser = envir.IsInBrowser() - meta.InCloud = envir.IsDevboxCloud() if runErr != nil { telemetry.Error(runErr, meta) diff --git a/internal/envir/env.go b/internal/envir/env.go index b8c0b5e221b..34d46d2a904 100644 --- a/internal/envir/env.go +++ b/internal/envir/env.go @@ -14,7 +14,6 @@ const ( // DevboxLatestVersion is the latest version available of the devbox CLI binary. // NOTE: it should NOT start with v (like 0.4.8) DevboxLatestVersion = "DEVBOX_LATEST_VERSION" - DevboxRegion = "DEVBOX_REGION" DevboxSearchHost = "DEVBOX_SEARCH_HOST" DevboxShellEnabled = "DEVBOX_SHELL_ENABLED" DevboxShellStartTime = "DEVBOX_SHELL_START_TIME" @@ -29,7 +28,6 @@ const ( LauncherPath = "LAUNCHER_PATH" GitHubUsername = "GITHUB_USER_NAME" - SSHTTY = "SSH_TTY" XDGDataHome = "XDG_DATA_HOME" XDGConfigHome = "XDG_CONFIG_HOME" diff --git a/internal/envir/util.go b/internal/envir/util.go index 9c9f3ca8b9b..08da5195581 100644 --- a/internal/envir/util.go +++ b/internal/envir/util.go @@ -10,10 +10,6 @@ import ( "strings" ) -func IsDevboxCloud() bool { - return os.Getenv(DevboxRegion) != "" -} - func IsDevboxShellEnabled() bool { inDevboxShell, _ := strconv.ParseBool(os.Getenv(DevboxShellEnabled)) return inDevboxShell diff --git a/internal/services/status.go b/internal/services/status.go deleted file mode 100644 index 142831870f9..00000000000 --- a/internal/services/status.go +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2024 Jetify Inc. and contributors. All rights reserved. -// Use of this source code is governed by the license in the LICENSE file. - -//lint:ignore U1000 Ignore unused function temporarily for debugging - -package services - -import ( - "context" - "encoding/json" - "fmt" - "io" - "io/fs" - "os" - "path/filepath" - - "github.com/fsnotify/fsnotify" - "github.com/pkg/errors" - - "go.jetify.com/devbox/internal/envir" -) - -// updateFunc returns a possibly updated service status and a boolean indicating -// whether the status file should be saved. This prevents infinite loops when -// the status file is updated. -type updateFunc func(status *ServiceStatus) (*ServiceStatus, bool) - -type ListenerOpts struct { - HostID string - ProjectDir string - UpdateFunc updateFunc - Writer io.Writer -} - -func ListenToChanges(ctx context.Context, opts *ListenerOpts) error { - if err := initCloudDir(opts.ProjectDir, opts.HostID); err != nil { - return err - } - - // Create new watcher. - watcher, err := fsnotify.NewWatcher() - if err != nil { - return errors.WithStack(err) - } - - go func() { - <-ctx.Done() - watcher.Close() - }() - - // Start listening for events. - go listenToEvents(watcher, opts) - - // We only want events for the specific host. - return errors.WithStack(watcher.Add(filepath.Join(cloudFilePath(opts.ProjectDir), opts.HostID))) -} - -func listenToEvents(watcher *fsnotify.Watcher, opts *ListenerOpts) { - for { - select { - case event, ok := <-watcher.Events: - if !ok { - return - } - - // mutagen sync changes show up as create events - if event.Has(fsnotify.Write) || event.Has(fsnotify.Create) { - status, err := readServiceStatus(event.Name) - if err != nil { - fmt.Fprintf(opts.Writer, "Error reading status file: %s\n", err) - continue - } - - status, saveChanges := opts.UpdateFunc(status) - if saveChanges { - if err := writeServiceStatusFile(event.Name, status); err != nil { - fmt.Fprintf(opts.Writer, "Error updating status file: %s\n", err) - } - } - } - case err, ok := <-watcher.Errors: - if !ok { - return - } - fmt.Fprintf(opts.Writer, "error: %s\n", err) - } - } -} - -func cloudFilePath(projectDir string) string { - return filepath.Join(projectDir, ".devbox.cloud") -} - -// initCloudDir creates the service status directory and a .gitignore file -func initCloudDir(projectDir, hostID string) error { - cloudDirPath := cloudFilePath(projectDir) - _ = os.MkdirAll(filepath.Join(cloudDirPath, hostID), 0o755) - gitignorePath := filepath.Join(cloudDirPath, ".gitignore") - _, err := os.Stat(gitignorePath) - if !errors.Is(err, fs.ErrNotExist) { - return nil - } - return errors.WithStack(os.WriteFile(gitignorePath, []byte("*"), 0o644)) -} - -type ServiceStatus struct { - LocalPort string `json:"local_port"` - Name string `json:"name"` - Port string `json:"port"` - Running bool `json:"running"` -} - -func writeServiceStatusFile(path string, status *ServiceStatus) error { - content, err := json.Marshal(status) - if err != nil { - return errors.WithStack(err) - } - _ = os.MkdirAll(filepath.Dir(path), 0o755) // create path, ignore error - return errors.WithStack(os.WriteFile(path, content, 0o644)) -} - -//lint:ignore U1000 Ignore unused function temporarily for debugging -func updateServiceStatusOnRemote(projectDir string, s *ServiceStatus) error { - if !envir.IsDevboxCloud() { - return nil - } - host, err := os.Hostname() - if err != nil { - return errors.WithStack(err) - } - - cloudDirPath := cloudFilePath(projectDir) - return writeServiceStatusFile(filepath.Join(cloudDirPath, host, s.Name+".json"), s) -} - -func readServiceStatus(path string) (*ServiceStatus, error) { - _, err := os.Stat(path) - if errors.Is(err, fs.ErrNotExist) { - return nil, nil - } - - content, err := os.ReadFile(path) - if err != nil { - return nil, errors.WithStack(err) - } - status := &ServiceStatus{} - return status, errors.WithStack(json.Unmarshal(content, status)) -} diff --git a/internal/telemetry/segment.go b/internal/telemetry/segment.go index e285c30df4c..7220a381331 100644 --- a/internal/telemetry/segment.go +++ b/internal/telemetry/segment.go @@ -70,7 +70,6 @@ func newTrackMessage(name string, meta Metadata) *segment.Track { "nix_version": nixVersion, "packages": meta.Packages, "shell": os.Getenv(envir.Shell), - "shell_access": shellAccess(), }, } @@ -94,23 +93,3 @@ func newTrackMessage(name string, meta Metadata) *segment.Track { func bufferSegmentMessage(id string, msg segment.Message) { bufferEvent(filepath.Join(segmentBufferDir, id+".json"), msg) } - -type shellAccessKind string - -const ( - local shellAccessKind = "local" - ssh shellAccessKind = "ssh" - browser shellAccessKind = "browser" -) - -func shellAccess() shellAccessKind { - // Check if running in devbox cloud - if envir.IsDevboxCloud() { - // Check if running via ssh tty (i.e. ssh shell) - if os.Getenv(envir.SSHTTY) != "" { - return ssh - } - return browser - } - return local -} diff --git a/internal/telemetry/telemetry.go b/internal/telemetry/telemetry.go index 7081d6591b7..7386eb28ba7 100644 --- a/internal/telemetry/telemetry.go +++ b/internal/telemetry/telemetry.go @@ -266,14 +266,12 @@ type Metadata struct { FeatureFlags map[string]bool InShell bool - InCloud bool InBrowser bool NixpkgsHash string Packages []string - CloudRegion string - CloudCache string + CloudCache string } func (m *Metadata) cmdContext() map[string]any { @@ -290,15 +288,11 @@ func (m *Metadata) cmdContext() map[string]any { func (m *Metadata) envContext() map[string]any { sentryCtx := map[string]any{ "In Shell": m.InShell, - "In Cloud": m.InCloud, "In Browser": m.InBrowser, } if m.CloudCache != "" { sentryCtx["Cloud Cache"] = m.CloudCache } - if m.CloudRegion != "" { - sentryCtx["Cloud Region"] = m.CloudRegion - } return sentryCtx } diff --git a/internal/vercheck/vercheck.go b/internal/vercheck/vercheck.go index 2c9029eccd8..db74bf4e776 100644 --- a/internal/vercheck/vercheck.go +++ b/internal/vercheck/vercheck.go @@ -75,10 +75,6 @@ func CheckVersion(w io.Writer, commandPath string) { return } - if envir.IsDevboxCloud() { - return - } - hasSkipPrefix := lo.ContainsBy( commandSkipList, func(skipPath string) bool { return strings.HasPrefix(commandPath, skipPath) }, diff --git a/internal/vercheck/vercheck_test.go b/internal/vercheck/vercheck_test.go index 3c817f3c1f8..921bbee10f3 100644 --- a/internal/vercheck/vercheck_test.go +++ b/internal/vercheck/vercheck_test.go @@ -16,18 +16,6 @@ func TestCheckVersion(t *testing.T) { isDevBuild = false t.Setenv(envir.XDGCacheHome, t.TempDir()) - t.Run("skip_if_devbox_cloud", func(t *testing.T) { - defer os.Unsetenv(envName) - // if devbox cloud - t.Setenv(envir.DevboxRegion, "true") - buf := new(bytes.Buffer) - CheckVersion(buf, "devbox shell") - if buf.String() != "" { - t.Errorf("expected empty string, got %q", buf.String()) - } - t.Setenv(envir.DevboxRegion, "") - }) - // no launcher version or latest-version env var t.Run("skip_if_no_launcher_version_or_latest_version", func(t *testing.T) { defer os.Unsetenv(envName)