diff options
author | xengineering <me@xengineering.eu> | 2024-07-30 18:14:55 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-07-30 18:32:45 +0200 |
commit | 9a21437358bea8f347e98cba564a5b214bb6607b (patch) | |
tree | ca2e55d7354dd1d35a9734e2cdcb6719f1439be9 | |
parent | 86c9fcc747374e29a9b3af7f2742e28921bfba52 (diff) | |
download | craft-9a21437358bea8f347e98cba564a5b214bb6607b.tar craft-9a21437358bea8f347e98cba564a5b214bb6607b.tar.zst craft-9a21437358bea8f347e98cba564a5b214bb6607b.zip |
Clone source on host and upload to VM with rsync
This prepares to disable internet access for the VM.
-rw-r--r-- | main.go | 64 |
1 files changed, 44 insertions, 20 deletions
@@ -42,8 +42,15 @@ func main() { log.Println("Starting craft") defer log.Println("Exiting craft") + source, err := os.MkdirTemp("", "*-craft") + if err != nil { + log.Fatal(err) + } + defer os.RemoveAll(source) + checkout(repo, commit, source) + vm := qemu() - err := vm.Start() + err = vm.Start() if err != nil { log.Fatal(err) } @@ -53,22 +60,11 @@ func main() { log.Fatal(err) } }() - waitBoot() - checkoutSources(repo, commit) - craft() -} + upload(source) -func runCommand(name string, args ...string) { - log.Printf("Remote execution: %s %s\n", name, strings.Join(args, " ")) - command := sshCommand(name, args...) - command.Stderr = os.Stderr - command.Stdout = os.Stdout - err := command.Run() - if err != nil { - log.Fatal(err) - } + craft() } func qemu() *exec.Cmd { @@ -148,20 +144,31 @@ cd %s } } -func checkoutSources(repo string, commit string) string { +func runCommand(name string, args ...string) { + log.Printf("Execution: %s %s\n", name, strings.Join(args, " ")) + command := exec.Command(name, args...) + command.Stderr = os.Stderr + command.Stdout = os.Stdout + err := command.Run() + if err != nil { + log.Fatal(err) + } +} + +func checkout(repo string, commit string, target string) { runCommand( "git", "clone", repo, - workbench, + target, ) runCommand( "git", "--git-dir", - filepath.Join(workbench, ".git"), + filepath.Join(target, ".git"), "--work-tree", - workbench, + target, "checkout", commit, ) @@ -169,7 +176,7 @@ func checkoutSources(repo string, commit string) string { runCommand( "git", "-C", - workbench, + target, "submodule", "update", "--depth=1", @@ -177,5 +184,22 @@ func checkoutSources(repo string, commit string) string { "--recursive", ) - return workbench + log.Printf("Checked source out to '%s'", target) +} + +func upload(directory string) { + mkdir := sshCommand("mkdir", "/root/build") + err := mkdir.Run() + if err != nil { + log.Fatal(err) + } + + runCommand( + "rsync", + "-a", + filepath.Clean(directory)+"/", + "--rsh", + "ssh -p "+port+" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "+key, + "root@localhost:/root/build/", + ) } |