diff options
Diffstat (limited to 'main.go')
-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 |