diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-10-05 10:26:52 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-10-05 10:26:52 +0300 |
commit | 864b2ea9ff43307b2a616410d0607c63da0b6661 (patch) | |
tree | 44e83750fd1dc59a4ea7c2bd2e4e2494fb7d692c | |
parent | 469bb263c4ce52122c85647fe8b5330ff5dc2bf3 (diff) | |
download | ick-contractor-864b2ea9ff43307b2a616410d0607c63da0b6661.tar.gz |
use image file for workspace
-rwxr-xr-x | contractor | 104 |
1 files changed, 82 insertions, 22 deletions
@@ -17,8 +17,10 @@ import yaml DEFAULT_CONFIGS = {os.path.expanduser("~/.config/contractor/config.yaml")} -# The device in the manager VM for the workspace disk. -WS_DEV = "/dev/vdb" +# The disk image file on the manager VM for the workspace disk. +WS_IMG = "/home/manager/workspace.img" +WS_SIZE = "20G" +WS_MNT = "/mnt" # The worker VM image file on manager VM. @@ -29,14 +31,6 @@ WORKER_IMG = "worker.img" TEMP_IMG = "temp.img" -# The UID of the worker account, on the worker VM. -WORKER_UID = 1000 - - -# The GID of the worker account, on the worker VM. -WORKER_GID = 1000 - - class ExecResult: def __init__(self, stdout, stderr, exit_code): self.stdout = stdout @@ -258,12 +252,44 @@ class StartGuestNetworking(MayFail): return virsh("net-start", "default") +class GetUID(RemoteExecution): + def msg(self): + return "get UID on manager" + + def argv(self): + return ["id", "-u"] + + +class GetGID(RemoteExecution): + def msg(self): + return "get GID of on manager" + + def argv(self): + return ["id", "-g"] + + +class CreateWS(RemoteExecution): + def msg(self): + return "creating workspace on manager" + + def argv(self): + return ["qemu-img", "create", "-q", "-f", "raw", WS_IMG, WS_SIZE] + + +class MkfsWS(RemoteExecution): + def msg(self): + return "mkfs workspace on manager" + + def argv(self): + return ["sudo", "mkfs", "-t", "ext4", "-q", WS_IMG] + + class MountWS(RemoteExecution): def msg(self): return "mounting workspace on manager" def argv(self): - return ["sudo", "mount", WS_DEV, "/mnt"] + return ["sudo", "mount", "-oloop", WS_IMG, WS_MNT] class MountWSonWorker(RemoteExecution): @@ -279,7 +305,7 @@ class TryUnmountWS(MayFail): return "trying to unmount workspace on manager" def argv(self): - return ["sudo", "umount", "--quiet", WS_DEV] + return ["sudo", "umount", "--quiet", WS_IMG] class UnmountWS(RemoteExecution): @@ -287,15 +313,19 @@ class UnmountWS(RemoteExecution): return "unmounting workspace on manager" def argv(self): - return ["sudo", "umount", "--quiet", WS_DEV] + return ["sudo", "umount", "--quiet", WS_IMG] class ChownWS(RemoteExecution): + def __init__(self, uid, gid): + self.uid = uid + self.gid = gid + def msg(self): return "set ownerships on workspace" def argv(self): - return ["sudo", "chown", "-R", "{}:{}".format(WORKER_UID, WORKER_GID), "/mnt"] + return ["sudo", "chown", "-R", "{}:{}".format(self.uid, self.gid), WS_MNT] class Mkdir(RemoteExecution): @@ -367,7 +397,7 @@ class AttachWS(RemoteExecution): "--quiet", "attach-disk", "worker", - WS_DEV, + WS_IMG, "vdb", "--targetbus", "virtio", @@ -509,7 +539,7 @@ def upload_worker_image(vrb, filename, dest, port): def sync_to_workspace(vrb, frm, dest, port, subdir): - destdir = "/mnt/{}".format(subdir) + destdir = "{}/{}".format(WS_MNT, subdir) vrb("syncing local {} to manager {}".format(frm, destdir)) er = rsync("{}/.".format(frm), "{}:{}/.".format(dest, destdir), port) if er.failed(): @@ -518,10 +548,10 @@ def sync_to_workspace(vrb, frm, dest, port, subdir): def sync_from_workspace(vrb, dest, port, ws): - vrb("syncing manager /mnt to local {}".format(ws)) + vrb("syncing manager {} to local {}".format(WS_MNT, ws)) if not os.path.exists(ws): os.makedirs(ws) - er = rsync("{}:/mnt/.".format(dest), "{}/.".format(ws), port) + er = rsync("{}:{}/.".format(dest), "{}/.".format(WS_MNT, ws), port) if er.failed(): error("Failed to rsync workspace from worker") sys.exit(1) @@ -605,12 +635,39 @@ def cmd_build(args): CopyWorkerImage(), StartGuestNetworking(), CreateWorkerVM(), - TryUnmountWS(), - MountWS(), - ChownWS(), ] exec_quietly(manager, *execs) + with Timer(vrb, "start-worker"): + execs = [GetUID()] + er = exec_quietly(manager, *execs) + manager_uid = int(er.stdout) + + with Timer(vrb, "start-worker"): + execs = [GetGID()] + er = exec_quietly(manager, *execs) + manager_gid = int(er.stdout) + + with Timer(vrb, "start-worker"): + execs = [TryUnmountWS()] + exec_quietly(manager, *execs) + + with Timer(vrb, "start-worker"): + execs = [CreateWS()] + exec_quietly(manager, *execs) + + with Timer(vrb, "start-worker"): + execs = [MkfsWS()] + exec_quietly(manager, *execs) + + with Timer(vrb, "start-worker"): + execs = [MountWS()] + exec_quietly(manager, *execs) + + with Timer(vrb, "start-worker"): + execs = [ChownWS(manager_uid, manager_gid)] + exec_quietly(manager, *execs) + with Timer(vrb, "upload-saved-workspace"): ws = bs.workspace() if ws: @@ -619,7 +676,10 @@ def cmd_build(args): sync_to_workspace(vrb, ws, dest, port, ".") with Timer(vrb, "upload-source"): - exec_quietly(manager, Mkdir("/mnt/src", owner=WORKER_UID, group=WORKER_GID)) + exec_quietly( + manager, + Mkdir("{}/src".format(WS_MNT), owner=manager_uid, group=manager_gid), + ) src = bs.source() sync_to_workspace(vrb, src, dest, port, "src") |