improvements to invoke tasks for installation
This commit is contained in:
parent
139323146e
commit
d4ac9e618f
1 changed files with 89 additions and 28 deletions
117
tasks.py
117
tasks.py
|
@ -1,74 +1,135 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
from invoke import task
|
from invoke import task, Context
|
||||||
|
|
||||||
UBUNTU = "ubuntu"
|
DAEMON_DIR: str = "daemon"
|
||||||
CENTOS = "centos"
|
VCMD_DIR: str = "netns"
|
||||||
DAEMON_DIR = "daemon"
|
GUI_DIR: str = "gui"
|
||||||
VCMD_DIR = "netns"
|
|
||||||
GUI_DIR = "gui"
|
|
||||||
|
|
||||||
|
|
||||||
def get_python(c):
|
class OsName(Enum):
|
||||||
|
UBUNTU = "ubuntu"
|
||||||
|
CENTOS = "centos"
|
||||||
|
|
||||||
|
|
||||||
|
class OsLike(Enum):
|
||||||
|
DEBIAN = "debian"
|
||||||
|
|
||||||
|
|
||||||
|
class OsInfo:
|
||||||
|
def __init__(self, name: OsName, like: OsLike, version: str) -> None:
|
||||||
|
self.name: OsName = name
|
||||||
|
self.like: OsLike = like
|
||||||
|
self.version: str = version
|
||||||
|
|
||||||
|
|
||||||
|
def get_python(c: Context) -> str:
|
||||||
with c.cd(DAEMON_DIR):
|
with c.cd(DAEMON_DIR):
|
||||||
venv = c.run("poetry env info -p", hide=True).stdout.strip()
|
venv = c.run("poetry env info -p", hide=True).stdout.strip()
|
||||||
return os.path.join(venv, "bin", "python")
|
return os.path.join(venv, "bin", "python")
|
||||||
|
|
||||||
|
|
||||||
def get_pytest(c):
|
def get_pytest(c: Context) -> str:
|
||||||
with c.cd(DAEMON_DIR):
|
with c.cd(DAEMON_DIR):
|
||||||
venv = c.run("poetry env info -p", hide=True).stdout.strip()
|
venv = c.run("poetry env info -p", hide=True).stdout.strip()
|
||||||
return os.path.join(venv, "bin", "pytest")
|
return os.path.join(venv, "bin", "pytest")
|
||||||
|
|
||||||
|
|
||||||
def get_os():
|
def get_os() -> OsInfo:
|
||||||
d = {}
|
d = {}
|
||||||
with open("/etc/os-release", "r") as f:
|
with open("/etc/os-release", "r") as f:
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
key, value = line.split("=")
|
key, value = line.split("=")
|
||||||
d[key] = value
|
d[key] = value.strip('"')
|
||||||
return d["ID"]
|
name_value = d["ID"]
|
||||||
|
like_value = d["ID_LIKE"]
|
||||||
|
try:
|
||||||
|
name = OsName(name_value)
|
||||||
|
like = OsLike(like_value)
|
||||||
|
except ValueError:
|
||||||
|
print(f"unsupported os({name_value}) like({like_value})")
|
||||||
|
sys.exit(1)
|
||||||
|
version = d["VERSION_ID"]
|
||||||
|
return OsInfo(name, like, version)
|
||||||
|
|
||||||
|
|
||||||
@task
|
def install_system(c: Context, os_info: OsInfo) -> None:
|
||||||
def install(c):
|
|
||||||
"""
|
|
||||||
install core
|
|
||||||
"""
|
|
||||||
# get os
|
|
||||||
os_name = get_os()
|
|
||||||
# install system dependencies
|
|
||||||
print("installing system dependencies...")
|
print("installing system dependencies...")
|
||||||
if os_name == UBUNTU:
|
if os_info.like == OsLike.DEBIAN:
|
||||||
c.run(
|
c.run(
|
||||||
"sudo apt install -y automake pkg-config gcc libev-dev ebtables iproute2 "
|
"sudo apt install -y automake pkg-config gcc libev-dev ebtables iproute2 "
|
||||||
"ethtool tk python3-tk", hide=True
|
"ethtool tk python3-tk", hide=True
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
raise Exception(f"unsupported os: {os_name}")
|
|
||||||
# install grpcio-tools for building proto files
|
def install_grpcio(c: Context) -> None:
|
||||||
print("installing grpcio-tools...")
|
print("installing grpcio-tools...")
|
||||||
c.run("python3 -m pip install --user grpcio-tools", hide=True)
|
c.run("python3 -m pip install --user grpcio-tools", hide=True)
|
||||||
# build core
|
|
||||||
|
|
||||||
|
def build(c: Context) -> None:
|
||||||
print("building core...")
|
print("building core...")
|
||||||
c.run("./bootstrap.sh", hide=True)
|
c.run("./bootstrap.sh", hide=True)
|
||||||
c.run("./configure", hide=True)
|
c.run("./configure", hide=True)
|
||||||
c.run("make -j", hide=True)
|
c.run("make -j", hide=True)
|
||||||
# install vcmd
|
|
||||||
|
|
||||||
|
def install_core(c: Context) -> None:
|
||||||
print("installing vcmd...")
|
print("installing vcmd...")
|
||||||
with c.cd(VCMD_DIR):
|
with c.cd(VCMD_DIR):
|
||||||
c.run("sudo make install", hide=True)
|
c.run("sudo make install", hide=True)
|
||||||
# install vcmd
|
|
||||||
print("installing gui...")
|
print("installing gui...")
|
||||||
with c.cd(GUI_DIR):
|
with c.cd(GUI_DIR):
|
||||||
c.run("sudo make install", hide=True)
|
c.run("sudo make install", hide=True)
|
||||||
# install poetry environment
|
|
||||||
|
|
||||||
|
def install_poetry(c: Context, dev: bool) -> None:
|
||||||
print("installing poetry...")
|
print("installing poetry...")
|
||||||
c.run("pipx install poetry", hide=True)
|
c.run("pipx install poetry", hide=True)
|
||||||
|
args = "" if dev else "--no-dev"
|
||||||
with c.cd(DAEMON_DIR):
|
with c.cd(DAEMON_DIR):
|
||||||
print("installing core environment using poetry...")
|
print("installing core environment using poetry...")
|
||||||
c.run("poetry install", hide=True)
|
c.run(f"poetry install {args}", hide=True)
|
||||||
|
if dev:
|
||||||
|
c.run("poetry run pre-commit install")
|
||||||
|
|
||||||
|
|
||||||
|
def install_ospf_mdr(c: Context, os_info: OsInfo) -> None:
|
||||||
|
if c.run("which zebra"):
|
||||||
|
print("quagga already installed, skipping ospf mdr")
|
||||||
|
return
|
||||||
|
if os_info.like == OsLike.DEBIAN:
|
||||||
|
c.run("sudo apt install -y libtool gawk libreadline-dev")
|
||||||
|
clone_dir = "/tmp/ospf-mdr"
|
||||||
|
c.run(
|
||||||
|
f"git clone https://github.com/USNavalResearchLaboratory/ospf-mdr {clone_dir}"
|
||||||
|
)
|
||||||
|
with c.cd(clone_dir):
|
||||||
|
c.run("./bootstrap.sh")
|
||||||
|
c.run(
|
||||||
|
"./configure --disable-doc --enable-user=root --enable-group=root "
|
||||||
|
"--with-cflags=-ggdb --sysconfdir=/usr/local/etc/quagga --enable-vtysh "
|
||||||
|
"--localstatedir=/var/run/quagga"
|
||||||
|
)
|
||||||
|
c.run("make -j")
|
||||||
|
c.run("sudo make install")
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def install(c, dev=False):
|
||||||
|
"""
|
||||||
|
install core
|
||||||
|
"""
|
||||||
|
os_info = get_os()
|
||||||
|
install_system(c, os_info)
|
||||||
|
install_grpcio(c)
|
||||||
|
build(c)
|
||||||
|
install_core(c)
|
||||||
|
install_poetry(c, dev)
|
||||||
|
install_ospf_mdr(c, os_info)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
|
|
Loading…
Reference in a new issue