diff --git a/internal/commands/config/config.go b/internal/commands/config/config.go index 62556ad..fb0ce67 100644 --- a/internal/commands/config/config.go +++ b/internal/commands/config/config.go @@ -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 @@ -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 diff --git a/internal/commands/prepare/prepare.go b/internal/commands/prepare/prepare.go index dfc0da2..916bcaa 100644 --- a/internal/commands/prepare/prepare.go +++ b/internal/commands/prepare/prepare.go @@ -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() diff --git a/internal/tart/vm.go b/internal/tart/vm.go index 95457fc..20e7b97 100644 --- a/internal/tart/vm.go +++ b/internal/tart/vm.go @@ -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)