This repository has been archived by the owner on Jul 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mkosi.build
executable file
·88 lines (79 loc) · 2.98 KB
/
mkosi.build
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
# vim: smarttab:expandtab:ts=4:sw=4:ft=python
from os import environ
from subprocess import run
from pathlib import Path
import venv
import rpm
output_dir: Path = Path(environ["BUILDDIR"])
pip_cache_dir: Path = Path(output_dir, ".pip_cache")
virtual_env_dir: Path = Path("/ipa")
python_bin_dir: Path = Path(virtual_env_dir, "bin/python3")
dracut_module_dir: Path = Path(
"/usr/lib/dracut/modules.d/49ironic-python-agent"
)
dracut_module_setup_script: Path = Path(dracut_module_dir, "module-setup.sh")
# even though pip is a python module, the preferred interface is via the CLI
pip: list = [python_bin_dir, "-m", "pip"]
# get some information about the system we're running on
os_release: Path = Path("/etc/os-release")
if not os_release.exists():
os_release: Path = Path("/usr/lib/os-release")
os_release_env: dict = {}
with os_release.open("r") as f:
for line in f:
(key, seperator, value) = line.partition("=")
os_release_env[key.strip()]: str = value.strip()
tinyipa_initramfs: Path = Path(
output_dir, "tinyipa.{}.initramfs".format(os_release_env["ID"])
)
tinyipa_kernel: Path = Path(
output_dir, "tinyipa.{}.kernel".format(os_release_env["ID"])
)
# only one kernel will be installed.
# we need this variable to instruct dracut not to use `uname`,
# as this returns the wrong value in a container
for hdr in rpm.TransactionSet().dbMatch("name", "kernel"):
kernel_version: str = "{}-{}.{}".format(
hdr[rpm.RPMTAG_VERSION], hdr[rpm.RPMTAG_RELEASE], hdr[rpm.RPMTAG_ARCH]
)
kernel_path: Path = Path("/usr/lib/modules", kernel_version, "vmlinuz")
# creating the virtual env to install IPA into
environ["VIRTUAL_ENV"]: str = str(virtual_env_dir)
venv.create(virtual_env_dir, clear=True, symlinks=True, with_pip=True)
# install the wanted application from upstream
pip_cache_dir.mkdir(parents=True, exist_ok=True)
run(
pip
+ [
"install",
"--ignore-installed",
"--no-warn-script-location",
"--cache-dir",
pip_cache_dir,
"git+https://github.com/openstack/ironic-python-agent.git@stable/ussuri", # noqa: E501
],
check=True,
)
# create the initramfs
dracut_options: list = []
dracut_options.append("/usr/bin/dracut")
dracut_options.append("--verbose")
dracut_options.append("--force")
dracut_options.extend(["--kver", kernel_version])
dracut_options.extend(["--modules", "ironic-python-agent"])
dracut_options.append("--nofscks")
dracut_options.append("--nomdadmconf")
dracut_options.append("--nolvmconf")
dracut_options.append("--ro-mnt")
dracut_options.append("--no-hostonly")
dracut_options.append("--no-hostonly-cmdline")
dracut_options.append("--no-hostonly-default-device")
dracut_options.append("--no-hostonly-i18n")
dracut_options.append(tinyipa_initramfs)
run(dracut_options)
tinyipa_initramfs.chmod(0o644)
# capture the kernel
# as $BUILDDIR is mounted in with a bind mount, we need to read/write the file
# here, a simple mv/rename won't work
tinyipa_kernel.write_bytes(kernel_path.read_bytes())