Skip to content

Commit

Permalink
Fix references to root directory (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest committed Jul 3, 2023
1 parent e07c054 commit b5bd041
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func copyKernel(buildMountPoint string, storage config.Storage, buildID types.BuildID) error {
buildBootDir := filepath.Join(buildMountPoint, "root", "boot")
buildBootDir := filepath.Join(buildMountPoint, "boot")
return forEachBootMaster(bootPrefix(storage.Root), func(diskMountpoint string) error {
kernelDir := filepath.Join(diskMountpoint, "zfs", string(buildID))
if err := os.MkdirAll(kernelDir, 0o755); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/google/uuid v1.3.0
github.com/outofforest/go-zfs/v3 v3.1.14
github.com/outofforest/ioc/v2 v2.5.2
github.com/outofforest/isolator v0.7.0
github.com/outofforest/isolator v0.7.1
github.com/outofforest/logger v0.4.0
github.com/outofforest/parallel v0.2.3
github.com/outofforest/run v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ github.com/outofforest/go-zfs/v3 v3.1.14 h1:F0MosonFuGwiIotlMVKoMsvAmISnOWOAncev
github.com/outofforest/go-zfs/v3 v3.1.14/go.mod h1:H8SgVKbvhso4bQGQMn6P21mFEd3oDOIaBH2w0Bcsu3c=
github.com/outofforest/ioc/v2 v2.5.2 h1:4mNzLuzoZTXL/cO0qf1TrSYvejMgbZz5OUhdLzAUbek=
github.com/outofforest/ioc/v2 v2.5.2/go.mod h1:yI+FHuHchC/t6nVo3WJ96qEgCXdHQKFI/4wW2/75YcU=
github.com/outofforest/isolator v0.7.0 h1:xlHhWuUI2G/zIWXyynmQQOdreHCcC29o0fGNra8/7k4=
github.com/outofforest/isolator v0.7.0/go.mod h1:02EyC+kX65/xHY0TWHec52JmYLJ8mb+04Cd+Sn2lN5s=
github.com/outofforest/isolator v0.7.1 h1:S8Gk8H0UB8QpiHhrS+qqVWjCVi2icgiffeYDPymz/k0=
github.com/outofforest/isolator v0.7.1/go.mod h1:02EyC+kX65/xHY0TWHec52JmYLJ8mb+04Cd+Sn2lN5s=
github.com/outofforest/libexec v0.3.9 h1:KvVLuKDHqpydwNoKm+j36hi9DVPU61X4oHonlZ5cw88=
github.com/outofforest/libexec v0.3.9/go.mod h1:J2rUB/m0ER8UNOHd3/UQM55bvh1cbMwhb8gibeF/zyo=
github.com/outofforest/logger v0.3.3/go.mod h1:+M5sO17Va9V33t28Qs9VqRQ8bFV501Uhq2PtQY+R3Ms=
Expand Down
2 changes: 1 addition & 1 deletion infra/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (b *Builder) build(ctx context.Context, stack map[types.BuildKey]bool, img
var path string
defer func() {
if path != "" {
if err := os.Remove(filepath.Join(path, "root", ".specdir")); err != nil && !os.IsNotExist(err) {
if err := os.Remove(filepath.Join(path, ".specdir")); err != nil && !os.IsNotExist(err) {
if retErr == nil {
retErr = err
}
Expand Down
10 changes: 6 additions & 4 deletions infra/storage/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ func (d *zfsDriver) BuildID(ctx context.Context, buildKey types.BuildKey) (types
// CreateEmpty creates blank build
func (d *zfsDriver) CreateEmpty(ctx context.Context, imageName string, buildID types.BuildID) (FinalizeFn, string, error) {
buildDir := filepath.Join("/", d.config.Root, string(buildID))
mountPoint := filepath.Join(buildDir, "root")
filesystem, err := zfs.CreateFilesystem(ctx, d.config.Root+"/"+string(buildID), zfs.CreateFilesystemOptions{Properties: map[string]string{
"mountpoint": filepath.Join(buildDir, "root"),
"mountpoint": mountPoint,
propertyName: string(must.Bytes(json.Marshal(types.BuildInfo{
BuildID: buildID,
Name: imageName,
Expand All @@ -129,7 +130,7 @@ func (d *zfsDriver) CreateEmpty(ctx context.Context, imageName string, buildID t
}
_, err := filesystem.Snapshot(ctx, "image")
return err
}, buildDir, nil
}, mountPoint, nil
}

// Clone clones source build to destination build
Expand All @@ -141,8 +142,9 @@ func (d *zfsDriver) Clone(ctx context.Context, srcBuildID types.BuildID, dstImag

properties := dstBuildID.Type().Properties()
buildDir := filepath.Join("/", d.config.Root, string(dstBuildID))
mountPoint := filepath.Join(buildDir, "root")
filesystem, err := snapshot.Clone(ctx, d.config.Root+"/"+string(dstBuildID), zfs.CloneOptions{Properties: map[string]string{
"mountpoint": filepath.Join(buildDir, "root"),
"mountpoint": mountPoint,
propertyName: string(must.Bytes(json.Marshal(types.BuildInfo{
BuildID: dstBuildID,
BasedOn: srcBuildID,
Expand Down Expand Up @@ -177,7 +179,7 @@ func (d *zfsDriver) Clone(ctx context.Context, srcBuildID types.BuildID, dstImag
}
}
return nil
}, buildDir, nil
}, mountPoint, nil
}

// StoreManifest stores manifest of build
Expand Down
5 changes: 2 additions & 3 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,6 @@ func deployVM(
}
domainDoc.Metadata = metaLibvirt

rootDir := filepath.Join(mount.Mounted, "root")
domainDoc.Devices.Filesystems = append(domainDoc.Devices.Filesystems, libvirtxml.DomainFilesystem{
Driver: &libvirtxml.DomainFilesystemDriver{
Type: "virtiofs",
Expand All @@ -982,7 +981,7 @@ func deployVM(
},
Source: &libvirtxml.DomainFilesystemSource{
Mount: &libvirtxml.DomainFilesystemSourceMount{
Dir: rootDir,
Dir: mount.Mounted,
},
},
Target: &libvirtxml.DomainFilesystemTarget{
Expand All @@ -993,7 +992,7 @@ func deployVM(
if domainDoc.OS == nil {
domainDoc.OS = &libvirtxml.DomainOS{}
}
bootDir := filepath.Join(rootDir, "boot")
bootDir := filepath.Join(mount.Mounted, "boot")
domainDoc.OS.Kernel = filepath.Join(bootDir, "vmlinuz")
domainDoc.OS.Initrd = filepath.Join(bootDir, "initramfs.img")
domainDoc.OS.Cmdline = strings.Join(append([]string{"root=virtiofs:root"}, mount.Params...), " ")
Expand Down

0 comments on commit b5bd041

Please sign in to comment.