-
Notifications
You must be signed in to change notification settings - Fork 5
/
remote_build
executable file
·102 lines (85 loc) · 3.25 KB
/
remote_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python3
from __future__ import annotations
from fabric import Connection
import argparse
import io
import logging
import os
import shlex
import subprocess
import sys
from typing import List
import urllib.parse
import git
try:
import coloredlogs
except ModuleNotFoundError:
coloredlogs = None
log = logging.getLogger("remote_build")
class Build:
def __init__(self, host: str):
self.host = host
self.repo = git.Repo()
self.remote = self.repo.remote(host)
self.url = self.remote.config_reader.get("url")
parsed = urllib.parse.urlparse(self.url)
if parsed.scheme != "ssh":
raise RuntimeError(f"remote url {self.url} is not a ssh:// url")
self.remote_host = parsed.netloc.rstrip(":")
self.remote_dir = parsed.path
def cmd(self, *args, cwd=None):
if cwd is None:
cwd = self.remote_dir
as_string = " ".join(shlex.quote(a) for a in args)
as_string = f"cd {shlex.quote(cwd)} && {as_string}"
log.info("Running command %s", as_string)
return as_string
def push(self, conn):
subprocess.run(["git", "push", self.host, "HEAD", "--force"], check=True)
conn.run(self.cmd("git", "reset", "--hard"))
conn.run(self.cmd("git", "clean", "-fx"))
conn.run(self.cmd("git", "checkout", "-B", "test_" + self.host, self.repo.head.commit.hexsha))
conn.run(self.cmd("git", "clean", "-fx"))
conn.run(self.cmd("autoreconf", "-if"))
def configure(self, conn, conf_args: List[str]):
conf_cmd = [
"rpm", "--eval",
(' '.join(shlex.quote(c) for c in (["%configure", "--enable-arpae-tests"] + conf_args)))]
res = conn.run(self.cmd(*conf_cmd))
with io.StringIO(res.stdout) as contents:
conn.put(contents, os.path.join(self.remote_dir, "rpm-config"))
conn.run(self.cmd("chmod", "0755", "rpm-config"))
conn.run(self.cmd("./rpm-config"))
def run(self, conf_args: List[str]):
conn = Connection(self.remote_host)
self.push(conn)
self.configure(conn, conf_args)
conn.run(self.cmd("make", "-j2"))
conn.run(self.cmd("make", "check", "-j2", "TEST_VERBOSE=1"))
def main():
parser = argparse.ArgumentParser(description="Run a build of arkimet on a remote host")
parser.add_argument("-v", "--verbose", action="store_true",
help="verbose output")
parser.add_argument("--debug", action="store_true",
help="verbose output")
parser.add_argument("host", action="store",
help="host to use for build")
args = parser.parse_args()
FORMAT = "%(asctime)-15s %(levelname)s %(name)s %(message)s"
if args.debug:
log_level = logging.DEBUG
elif args.verbose:
log_level = logging.INFO
else:
log_level = logging.WARN
if coloredlogs is not None:
coloredlogs.install(level=log_level, fmt=FORMAT, logger=log)
else:
logging.basicConfig(level=log_level, stream=sys.stderr, format=FORMAT)
conf_args = []
if args.host == "sette":
conf_args = ["--disable-docs", "--disable-splice"]
build = Build(args.host)
build.run(conf_args)
if __name__ == "__main__":
main()