Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mount directories directly into $HOME #65

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
37 changes: 37 additions & 0 deletions internal/commands/prepare/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,43 @@ 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()

mountScript := fmt.Sprintf(
"mount_virtiofs tart.virtiofs.%s /Users/%s/%s\n",
Copy link
Contributor

@edigaryev edigaryev Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mount_virtiofs expects a directory to be already created, so we should probably stuff an mkdir -p && ... here to avoid the job failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch. See 012a73f

dirToMount, config.SSHUsername, dirToMount,
)
session.Stdin = bytes.NewBufferString(mountScript)
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