Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions cmd/bauklotze/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func start(cmd *cobra.Command, args []string) error {
logrus.Infof("Check the status of the parent process: %d", allFlag.PPID)
isRunning, err := system.IsProcessAliveV4(int(allFlag.PPID))
if !isRunning {
return fmt.Errorf("PPID[%d] exited, possible error: %w", allFlag.PPID, err)
return fmt.Errorf("PPID[ %d ] exited, possible error: %w", allFlag.PPID, err)
}

// Check if the process of the PID passed in via --ppid is active.
Expand Down Expand Up @@ -117,7 +117,7 @@ func start(cmd *cobra.Command, args []string) error {

// Start a goroutine running api service,if catch error, return error
g.Go(func() error {
endPoint := filepath.Join(mc.Dirs.TmpDir.GetPath(), define.RESTAPIEndpointName)
endPoint := filepath.Join(filepath.Dir(mc.Dirs.SocksDir.GetPath()), define.RESTAPIEndpointName)
logrus.Infof("Start rest api service at %q", endPoint)
return server.RestService(ctx, mc, endPoint) // server.RestService must now subscribe to ctx
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/define/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
LogPrefixDir = "logs"
LibexecPrefixDir = "libexec"
DataPrefixDir = "data"
TmpPrefixDir = "tmp"
SocksPrefixDir = "socks"

DefaultIdentityName = "sshkey"

Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/shim/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Init(mp vmconfig.VMProvider) error {
}
logrus.Infof("ConfigDir: %s", dirs.ConfigDir.GetPath())
logrus.Infof("DataDir: %s", dirs.DataDir.GetPath())
logrus.Infof("TmpDir: %s", dirs.TmpDir.GetPath())
logrus.Infof("SocksDir: %s", dirs.SocksDir.GetPath())
logrus.Infof("LogsDir: %s", dirs.LogsDir.GetPath())

sshKey, err := vmconfig.GetSSHIdentityPath(mp.VMType())
Expand Down
4 changes: 2 additions & 2 deletions pkg/machine/shim/network_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func startForwarder(mc *vmconfig.MachineConfig, socksOnHost string, socksOnGuest
return fmt.Errorf("%s does not exist", gvpBin.GetPath())
}

tmpDir := mc.Dirs.TmpDir
socksDir := mc.Dirs.SocksDir
gvproxyCommand := gvproxy.NewGvproxyCommand() // New a GvProxyCommands

gvpPidFile, _ := tmpDir.AppendToNewVMFile(fmt.Sprintf("%s-%s", mc.VMName, define.GvProxyPidName))
gvpPidFile, _ := socksDir.AppendToNewVMFile(fmt.Sprintf("%s-%s", mc.VMName, define.GvProxyPidName))
if err := gvpPidFile.Delete(true); err != nil {
return fmt.Errorf("failed to delete pid file: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/vmconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type ResourceConfig struct {
type MachineDirs struct {
ConfigDir *io.VMFile `json:"ConfigDir"`
DataDir *io.VMFile `json:"DataDir"`
TmpDir *io.VMFile `json:"RuntimeDir"`
LogsDir *io.VMFile `json:"LogsDir"`
Hypervisor *Hypervisor `json:"Hypervisor"`
NetworkProvider *NetworkProvider `json:"NetworkProvider"`
SocksDir *io.VMFile `json:"SocksDir"`
}

type Hypervisor struct {
Expand Down
25 changes: 13 additions & 12 deletions pkg/machine/vmconfig/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
package vmconfig

import (
"bauklotze/pkg/machine/defconfig"
"bauklotze/pkg/machine/define"
"bauklotze/pkg/machine/io"
"fmt"
"os"
"path/filepath"
"sync"

"bauklotze/pkg/machine/defconfig"
"bauklotze/pkg/machine/define"
"bauklotze/pkg/machine/io"
)

var (
Expand Down Expand Up @@ -46,14 +47,14 @@ func GetMachineDirs(vmType defconfig.VMType) (*MachineDirs, error) {
return nil, fmt.Errorf("failed to get workspace: %w", err)
}

tmpDir, err := io.NewMachineFile(filepath.Join(d.GetPath(), define.TmpPrefixDir, vmType.String()))
socksDir, err := io.NewMachineFile(filepath.Join(d.GetPath(), define.SocksPrefixDir, vmType.String()))
if err != nil {
return nil, fmt.Errorf("unable to new machine file in %s: %w", tmpDir, err)
return nil, fmt.Errorf("unable to new machine file in %s: %w", socksDir, err)
}

dataDir, err := io.NewMachineFile(filepath.Join(d.GetPath(), define.DataPrefixDir, vmType.String()))
if err != nil {
return nil, fmt.Errorf("unable to new machine file in %s: %w", tmpDir, err)
return nil, fmt.Errorf("unable to new machine file in %s: %w", dataDir, err)
}

configDir, err := io.NewMachineFile(filepath.Join(d.GetPath(), define.ConfigPrefixDir, vmType.String()))
Expand Down Expand Up @@ -95,10 +96,10 @@ func GetMachineDirs(vmType defconfig.VMType) (*MachineDirs, error) {
}

Dirs = MachineDirs{
ConfigDir: configDir, // ${BauklotzeHomePath}/config/{wsl,libkrun,qemu,hyper...}/
DataDir: dataDir, // ${BauklotzeHomePath}/data/{wsl2,libkrun,qemu,hyper...}/
TmpDir: tmpDir, // ${BauklotzeHomePath}/tmp/{wsl2,libkrun,qemu,hyper...}/
LogsDir: logsDir, // ${BauklotzeHomePath}/logs/{wsl2,libkrun,qemu,hyper...}/
ConfigDir: configDir,
DataDir: dataDir,
SocksDir: socksDir,
LogsDir: logsDir,
Hypervisor: &Hypervisor{
Bin: hypervisorBin,
LibsDir: libexecDir,
Expand All @@ -109,8 +110,8 @@ func GetMachineDirs(vmType defconfig.VMType) (*MachineDirs, error) {
},
}

if err = os.MkdirAll(tmpDir.GetPath(), 0755); err != nil {
return nil, fmt.Errorf("unable to create runtime dir: %s: %w", tmpDir.GetPath(), err)
if err = os.MkdirAll(socksDir.GetPath(), 0755); err != nil {
return nil, fmt.Errorf("unable to create runtime dir: %s: %w", socksDir.GetPath(), err)
}
if err = os.MkdirAll(configDir.GetPath(), 0755); err != nil {
return nil, fmt.Errorf("unable to create config dir: %s: %w", configDir.GetPath(), err)
Expand Down
22 changes: 11 additions & 11 deletions pkg/machine/vmconfig/vmconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type VMProvider interface { //nolint:interfacebloat
}

func (mc *MachineConfig) PodmanAPISocketHost() *io.VMFile {
tmpDir := mc.Dirs.TmpDir
socksDir := mc.Dirs.SocksDir
s := fmt.Sprintf("%s-podman-api.sock", mc.VMName)
podmanAPI, _ := tmpDir.AppendToNewVMFile(s)
podmanAPI, _ := socksDir.AppendToNewVMFile(s)
return podmanAPI
}

Expand Down Expand Up @@ -76,12 +76,12 @@ type MachineConfig struct {

type Bootable struct {
Image *io.VMFile `json:"ImagePath" validate:"required"`
Version string `json:"Version" validate:"required"`
Version string `json:"Version" validate:"required"`
}

type DataDisk struct {
Image *io.VMFile `json:"ImagePath" validate:"required"`
Version string `json:"Version" validate:"required"`
Version string `json:"Version" validate:"required"`
}

type GvproxyCommand struct {
Expand Down Expand Up @@ -218,19 +218,19 @@ func loadMachineFromFQPath(f *io.VMFile) (*MachineConfig, error) {
}

func (mc *MachineConfig) GVProxyNetworkBackendSocks() (*io.VMFile, error) {
tmpDir, err := mc.TmpDir()
socksDir, err := mc.SocksDir()
if err != nil {
return nil, fmt.Errorf("failed to get workspace tmp dir: %w", err)
}
return tmpDir.AppendToNewVMFile(fmt.Sprintf("%s-gvproxy.sock", mc.VMName)) //nolint:wrapcheck
return socksDir.AppendToNewVMFile(fmt.Sprintf("%s-gvproxy.sock", mc.VMName)) //nolint:wrapcheck
}

// TmpDir is simple helper function to obtain the workspace tmp dir
func (mc *MachineConfig) TmpDir() (*io.VMFile, error) {
if mc.Dirs == nil || mc.Dirs.TmpDir == nil || mc.Dirs.TmpDir.GetPath() == "" {
return nil, errors.New("no workspace tmp directory set")
// SocksDir is simple helper function to obtain the workspace tmp dir
func (mc *MachineConfig) SocksDir() (*io.VMFile, error) {
if mc.Dirs == nil || mc.Dirs.SocksDir.GetPath() == "" {
return nil, errors.New("no workspace socks directory set")
}
return mc.Dirs.TmpDir, nil
return mc.Dirs.SocksDir, nil
}

// write is a non-locking way to write the machine configuration file to disk
Expand Down
7 changes: 4 additions & 3 deletions pkg/test/env/env_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package env

import (
"bauklotze/pkg/machine/provider"
"bauklotze/pkg/machine/vmconfig"
"fmt"
"os"
"path/filepath"
"testing"

"bauklotze/pkg/machine/provider"
"bauklotze/pkg/machine/vmconfig"
)

func TestGetSSHIdentityPath(t *testing.T) {
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestGetMachineDirs(t *testing.T) {
t.Errorf("GetMachineDirs() failed: %v", err)
}
t.Logf("DataDir: %s", dirs.DataDir.Path)
t.Logf("TmpDir: %s", dirs.TmpDir.Path)
t.Logf("SocksDir: %s", dirs.SocksDir.Path)
t.Logf("LogDir: %s", dirs.LogsDir.Path)
t.Logf("ConfigDir: %s", dirs.ConfigDir.Path)
}
Expand Down