aboutsummaryrefslogtreecommitdiff
path: root/workstation/test.py
blob: 467c0fb5eb186bb5540004851370ade1814b57a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python3
import os
import pathlib
import subprocess
import time


INSTANCE_NAME="workstation-test"
USER="alex"

THIS_REPO = pathlib.Path(__file__).parent.parent
THIS_UID = os.getuid()


def _(*args, check=True, input=None):
    return subprocess.run(args, check=check, input=input, text=True)


_("incus", "launch",
  "images:debian/13",
  INSTANCE_NAME,
  "--ephemeral",
  "--vm",
  "-c", "limits.cpu=4",
  "-c", "limits.memory=6GiB",
  "-d", "root,size=50GiB")

while _("incus", "exec", INSTANCE_NAME, "uptime", check=False).returncode != 0:
    print("waiting...")
    time.sleep(1)

_("incus", "config", "device", "add", INSTANCE_NAME, "here", "disk", f"source={THIS_REPO}", "path=/here")
_("incus", "exec", INSTANCE_NAME, "--", "apt", "full-upgrade", "-U")
_("incus", "exec", INSTANCE_NAME, "--", "apt", "install", "-y", "python3")
_("incus", "exec", INSTANCE_NAME, "--", "/here/workstation/root-setup.py")
_("incus", "exec", INSTANCE_NAME, "--", "adduser", USER, "--disabled-password", "--comment", "")
_("incus", "exec", INSTANCE_NAME, "--", "passwd", USER, "--stdin", input=USER)

# Comment out to test with real repo
_("incus", "exec", INSTANCE_NAME, "--", "mount", "/here/", f"/home/{USER}/git/alexpdp7/", "-o", f"bind,X-mount.idmap={THIS_UID}:1000:1")

_("incus", "exec", INSTANCE_NAME, "--", "sudo", "-u", USER, "/here/workstation/user-setup.py")