Skip to content

Commit a7c45a5

Browse files
authored
[cloud] enable multiple projects opening shells in same VM (#371)
## Summary This minimal fix creates a mutagen session for each code project that a user starts a `devbox cloud shell` for. In a future PR, we can refactor SessionSpec so that sanitize name is always applied by adding `WithName` options to a constructor function. ## How was it tested? started cloud shells for rust and golang example projects. Synced files in each. `MUTAGEN_DATA_DIRECTORY=~/.config/devbox/mutagen mutagen sync list` -> reports 2 active sessions. Closed shells. Stopped VM. `MUTAGEN_DATA_DIRECTORY=~/.config/devbox/mutagen mutagen sync list` -> reports no active sessions.
1 parent 19a1183 commit a7c45a5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

internal/cloud/cloud.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func syncFiles(username, hostname, configDir string) error {
141141
_, err = mutagen.Sync(&mutagen.SessionSpec{
142142
// If multiple projects can sync to the same machine, we need the name to also include
143143
// the project's id.
144-
Name: fmt.Sprintf("devbox-%s", machineID),
144+
Name: mutagen.SanitizeSessionName(fmt.Sprintf("devbox-%s-%s", projectName, machineID)),
145145
AlphaPath: configDir,
146146
BetaAddress: fmt.Sprintf("%s@%s", username, hostname),
147147
// It's important that the beta path is a "clean" directory that will contain *only*

internal/cloud/mutagen/types.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package mutagen
22

3-
import "errors"
3+
import (
4+
"errors"
5+
"strings"
6+
)
47

58
type SessionSpec struct {
69
AlphaAddress string
@@ -25,6 +28,12 @@ func (s *SessionSpec) Validate() error {
2528
return nil
2629
}
2730

31+
// TODO savil. Refactor SessionSpec so that this is always applied.
32+
// We can make it a struct that uses a constructor, and make Sync a method on the struct.
33+
func SanitizeSessionName(input string) string {
34+
return strings.ReplaceAll(input, ".", "-")
35+
}
36+
2837
// Based on the structs available at: https://github.com/mutagen-io/mutagen/blob/master/pkg/api/models/synchronization/session.go
2938
// These contain a subset of fields.
3039

0 commit comments

Comments
 (0)