Skip to content

vagrant-virtualbox implementation (HMS-6116) - #1556

Merged
supakeen merged 4 commits into
osbuild:mainfrom
supakeen:vagrant-virtualbox
Jul 16, 2025
Merged

supakeen merged 4 commits into
osbuild:mainfrom
supakeen:vagrant-virtualbox

Conversation

@supakeen

@supakeen supakeen commented May 22, 2025 •

Copy link
Copy Markdown
Member

This is the vagrant virtualbox implementation, this PR is based on top of #1548 and is as of yet unmergeable until I fix up and merge the relevant osbuild PRs (osbuild/osbuild#1136 and osbuild/osbuild#2132) and then bump the minimum osbuild version once that lands.

I'd just like to have the PR open as it does currently build correctly.

@supakeen

supakeen commented Jun 30, 2025 •

Copy link
Copy Markdown
Member Author

Undrafting, I'm not particularly happy with the mismatch between the org.osbuild.ovf stage expecting a file at the tree root (this is the same in the ovf pipeline) and the vagrant stage taking a file as an input so I'd like some reviews to possibly refine this (or keep it as is if there's no good alternative).

There's also the problem that we already had an ovf pipeline but after trying quite a bit I didn't manage to fit it into something that can be accepted by the vagrant pipeline.

CI will fail until the associated osbuild PRs have been merged and the commit has been updated here.

@supakeen

Copy link
Copy Markdown
Member Author

We had some discussion about this and the consensus seemed to be that we'd likely prefer to take this to a follow up where we revisit how the tar stage takes inputs (allowing it to take multiple) and for pipelines to 'export' multiple files.

@supakeen

supakeen commented Jul 1, 2025

Copy link
Copy Markdown
Member Author

The first osbuild PR has merged, just the second to go now :)

bcl
bcl previously approved these changes Jul 1, 2025

@bcl bcl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good to me

@supakeen
supakeen marked this pull request as draft July 9, 2025 09:18
@supakeen

supakeen commented Jul 10, 2025 •

Copy link
Copy Markdown
Member Author

Needs more work, see osbuild/osbuild#2143 which needs to land to also succesfully have CentOS/RHEL images boot.

@supakeen

Copy link
Copy Markdown
Member Author

I've updated this branch now with the new approach suggested by @achilleas-k in osbuild/osbuild#2143; still keeping as draft until the bits are in place in osbuild.

supakeen added 2 commits July 14, 2025 07:32
To make use of the latest options in the Vagrant stage we need to bump
the osbuild version.

Signed-off-by: Simon de Vlieger <[email protected]>
We need a newer osbuild to validate and run vagrant stages.

Signed-off-by: Simon de Vlieger <[email protected]>
@supakeen

supakeen commented Jul 14, 2025 •

Copy link
Copy Markdown
Member Author

With all prerequisite PRs landed in osbuild this should now be ready to review/test.

For testing:

  • Install VirtualBox and Vagrant
  • Ensure that you have the kernel drivers loaded (on some systems at least mine, this requires disabling secureboot?)
  • Patch /usr/bin/VBox with:
152     VBoxManage|vboxmanage)
153         if [[ $@ == "--version" ]]; then
154            echo "7.0.0r164728"
155         else
156            exec "$INSTALL_DIR/VBoxManage" "$@"
157         fi
158         ;;

So it reports a version that Vagrant supports.

Then build an image and import it with vagrant box add path/to/image.box --name somethingyoulike.

Create a new empty directory and vagrant init, change the Vagrantfile to refer to the box name you chose previously.

Then vagrant up --provider=virtualbox.

@supakeen
supakeen marked this pull request as ready for review July 14, 2025 05:54

@mvo5 mvo5 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you! Some quick inline comments/ideas/suggestions, hope they are useful.

Comment thread pkg/image/disk.go Resolved
Comment thread pkg/manifest/vagrant.go Resolved
Comment thread pkg/manifest/vagrant.go Resolved
Comment thread pkg/osbuild/vagrant_stage_test.go Resolved
Comment thread pkg/osbuild/vagrant_stage_test.go Outdated
Type: VagrantSyncedFolderTypeRsync,
}

assert.Error(t, stageOptions.validate())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually checking the error is I think preferable as it allows us to also check if the error message looks "nice" and it is also a nice way in the "tests-as-documentation" sense to see what happens in this particular error case. So maybe:

...
	assert.EqualError(t, stageOptions.validate(), "syncedfolders are only available for the virtualbox provider")

which is interesting as it highlights that it might be nice to include in the error what the actual provider used is, i.e. I think modifying the error to something like syncedfolders are only available for the virtualbox provider not for libvirt would provide more information to us/our users.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The error message is now checked, however I've not expanded the error message with the supported type(s); I don't quite feel that it adds a lot of value and would be one more part of the code to keep in sync with potential additions to the enum. Users at this level (programmers, really) have enough information to know what's wrong.

Let me know if you do feel strongly about this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! Maybe I explained myself badly, for the extra info I was just thinking to provide slightly more context to the error, i.e. just adding what was passed when the error happend so that its easier to locate in the code what might have gone wrong, something super simple like:

diff --git a/pkg/osbuild/vagrant_stage.go b/pkg/osbuild/vagrant_stage.go
index 8ba7409d5..ed62a2a44 100644
--- a/pkg/osbuild/vagrant_stage.go
+++ b/pkg/osbuild/vagrant_stage.go
@@ -63,7 +63,7 @@ func (o *VagrantStageOptions) validate() error {
        }
 
        if o.Provider != VagrantProviderVirtualBox && len(o.SyncedFolders) > 0 {
-               return fmt.Errorf("syncedfolders are only available for the virtualbox provider")
+               return fmt.Errorf("syncedfolders are only available for the virtualbox provider not for %q", o.Provider)
        }
 
        return nil
diff --git a/pkg/osbuild/vagrant_stage_test.go b/pkg/osbuild/vagrant_stage_test.go
index 164fbcaf4..522915b04 100644
--- a/pkg/osbuild/vagrant_stage_test.go
+++ b/pkg/osbuild/vagrant_stage_test.go
@@ -96,5 +96,5 @@ func TestVagrantStageOptionsSyncedFoldersNoVirtualbox(t *testing.T) {
                },
        }
 
-       assert.EqualError(t, stageOptions.validate(), "syncedfolders are only available for the virtualbox provider")
+       assert.EqualError(t, stageOptions.validate(), `syncedfolders are only available for the virtualbox provider not for "libvirt"`)
 }

afaict this adds no extra burden to the test or code just makes it (hopefully) slightly easier to diagnose issues.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, then I misunderstood. I've applied this change.

Comment thread pkg/manifest/vagrant.go Resolved
@supakeen
supakeen requested review from bcl and mvo5 July 15, 2025 09:52
supakeen added 2 commits July 15, 2025 12:46
There's new support in osbuild's vagrant stage (and OVF stage) to do
Vagrant virtualbox specific things. Implement the new stage options,
provider(s), and plumb them through in manifest and disk.

Signed-off-by: Simon de Vlieger <[email protected]>
Define a new Vagrant image type which uses the VirtualBox backend
instead of libvirt for Fedora and RHEL-likes. Note that the VirtualBox
backend is only available on x86.

Signed-off-by: Simon de Vlieger <[email protected]>

@bcl bcl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good!

@supakeen
supakeen added this pull request to the merge queue Jul 16, 2025
Merged via the queue into osbuild:main with commit 38dc21f Jul 16, 2025
@supakeen
supakeen deleted the vagrant-virtualbox branch July 16, 2025 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants