Skip to content

Commit

Permalink
Mount directories directly into $HOME (#65)
Browse files Browse the repository at this point in the history
* Mount directories directly into `$HOME`

After introducing of cirruslabs/tart#733 we can use different VirtioFS tags for different directories and precisely mount them into exact locations.

`/Volumes/My Shared Files/` default path is error-prone since some tools don't like whitespaces in paths. With this change directories will be directly mounted into `$HOME`.

Fixes #64

* Fixed lint issue

* Don't forget to `mkdir -p`

* Introduce `mountPoint`
  • Loading branch information
fkorotkov authored Apr 2, 2024
1 parent 921eca7 commit 8689a13
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/commands/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ func runConfig(cmd *cobra.Command, args []string) error {
// Figure out the builds directory override to use
switch {
case tartConfig.HostDir:
gitlabRunnerConfig.BuildsDir = "/Volumes/My Shared Files/hostdir"
gitlabRunnerConfig.BuildsDir = fmt.Sprintf("/Users/%s/hostdir", tartConfig.SSHUsername)

if err := os.MkdirAll(gitLabEnv.HostDirPath(), 0700); err != nil {
return err
}
case buildsDir != "":
gitlabRunnerConfig.BuildsDir = "/Volumes/My Shared Files/buildsdir"
gitlabRunnerConfig.BuildsDir = fmt.Sprintf("/Users/%s/buildsdir", tartConfig.SSHUsername)
buildsDir = os.ExpandEnv(buildsDir)
gitlabRunnerConfig.JobEnv[tart.EnvTartExecutorInternalBuildsDir] = buildsDir

Expand All @@ -115,7 +115,7 @@ func runConfig(cmd *cobra.Command, args []string) error {
// Figure out the cache directory override to use
switch {
case cacheDir != "":
gitlabRunnerConfig.CacheDir = "/Volumes/My Shared Files/cachedir"
gitlabRunnerConfig.CacheDir = fmt.Sprintf("/Users/%s/cachedir", tartConfig.SSHUsername)
cacheDir = os.ExpandEnv(cacheDir)
gitlabRunnerConfig.JobEnv[tart.EnvTartExecutorInternalCacheDir] = cacheDir

Expand Down
36 changes: 36 additions & 0 deletions internal/commands/prepare/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,42 @@ func runPrepareVM(cmd *cobra.Command, args []string) error {
log.Printf("Timezone was set to %s!\n", tz)
}

dirsToMount := []string{}
if config.HostDir {
dirsToMount = append(dirsToMount, "hostdir")
}
if _, ok := os.LookupEnv(tart.EnvTartExecutorInternalBuildsDir); ok {
dirsToMount = append(dirsToMount, "buildsdir")
}
if _, ok := os.LookupEnv(tart.EnvTartExecutorInternalCacheDir); ok {
dirsToMount = append(dirsToMount, "cachedir")
}

for _, dirToMount := range dirsToMount {
log.Printf("Mounting %s...\n", dirToMount)

session, err := ssh.NewSession()
if err != nil {
return err
}
defer session.Close()

mountPoint := fmt.Sprintf("/Users/%s/%s", config.SSHUsername, dirToMount)
mkdirScript := fmt.Sprintf("mkdir -p %s", mountPoint)
mountScript := fmt.Sprintf("mount_virtiofs tart.virtiofs.%s %s", dirToMount, mountPoint)
session.Stdin = bytes.NewBufferString(strings.Join([]string{mkdirScript, mountScript, ""}, "\n"))
session.Stdout = os.Stdout
session.Stderr = os.Stderr

if err := session.Shell(); err != nil {
return err
}

if err := session.Wait(); err != nil {
return err
}
}

log.Println("VM is ready.")

return ssh.Close()
Expand Down
6 changes: 3 additions & 3 deletions internal/tart/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ func (vm *VM) Start(
}

if config.HostDir {
runArgs = append(runArgs, "--dir", fmt.Sprintf("hostdir:%s", gitLabEnv.HostDirPath()))
runArgs = append(runArgs, "--dir", fmt.Sprintf("%s:tag=tart.virtiofs.hostdir", gitLabEnv.HostDirPath()))
} else if buildsDir, ok := os.LookupEnv(EnvTartExecutorInternalBuildsDir); ok {
runArgs = append(runArgs, "--dir", fmt.Sprintf("buildsdir:%s", buildsDir))
runArgs = append(runArgs, "--dir", fmt.Sprintf("%s:tag=tart.virtiofs.buildsdir", buildsDir))
}

if cacheDir, ok := os.LookupEnv(EnvTartExecutorInternalCacheDir); ok {
runArgs = append(runArgs, "--dir", fmt.Sprintf("cachedir:%s", cacheDir))
runArgs = append(runArgs, "--dir", fmt.Sprintf("%s:tag=tart.virtiofs.cachedir", cacheDir))
}

runArgs = append(runArgs, vm.id)
Expand Down

0 comments on commit 8689a13

Please sign in to comment.