diff options
author | xengineering <me@xengineering.eu> | 2024-07-21 17:20:57 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-07-21 17:34:56 +0200 |
commit | 1b4affb524536ca904f09b0de65fddad3be2a75b (patch) | |
tree | f02f709850b6cd3935005713fa6c4398154f7782 | |
parent | 0db0ddcc421a5c2a85ac614d1f62e3e3374994a2 (diff) | |
download | craft-1b4affb524536ca904f09b0de65fddad3be2a75b.tar craft-1b4affb524536ca904f09b0de65fddad3be2a75b.tar.zst craft-1b4affb524536ca904f09b0de65fddad3be2a75b.zip |
Startup VM parallel to craft execution on host
This prepares moving the workbench to the virtual machine. It
furthermore adds the following command line arguments:
- image
- port
See `craft --help` or the init() function for details.
-rw-r--r-- | main.go | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -15,12 +15,16 @@ var ( repo = "" commit = "" task = "" + image = "" + port = "" ) func init() { flag.StringVar(&repo, "repo", "", "Source code as valid Git URL") flag.StringVar(&commit, "commit", "", "Commit or commit-ish reference for checkout") flag.StringVar(&task, "task", "", "Shell code to execute for the build") + flag.StringVar(&image, "image", "", "QEMU qcow2 image which contains the VM") + flag.StringVar(&port, "port", "", "localhost port which is connected to VM SSH server") } func main() { @@ -31,6 +35,18 @@ func main() { log.Println("Starting craft") defer log.Println("Exiting craft") + vm := qemu() + err := vm.Start() + if err != nil { + log.Fatal(err) + } + defer func() { + err := vm.Process.Kill() + if err != nil { + log.Fatal(err) + } + }() + workbench := prepareWorkbench(repo, commit) defer os.RemoveAll(workbench) craft(workbench) @@ -48,6 +64,30 @@ func runCommand(dir string, name string, args ...string) { } } +func qemu() *exec.Cmd { + return exec.Command( + "qemu-system-x86_64", + "-enable-kvm", + "-m", + "4G", + "-net", + "nic,model=virtio", + "-net", + fmt.Sprintf( + "user,hostfwd=tcp:127.0.0.1:%s-:22", + port, + ), + "-drive", + fmt.Sprintf( + "file=%s,media=disk,snapshot=on,if=virtio", + image, + ), + "-smp", + "cpus=4", + "-nographic", + ) +} + func craft(workbench string) { script := fmt.Sprintf(`#!/bin/sh |