debian-forge/run-stage
Lars Karlitski 7a866aa1c3 osbuild: don't show log output on the terminal
The output makes it hard to see which stage is currently processed and
how to enter the build container. Also, it doesn't include all relevant
logs.

Instead, stream log output into /tmp/output in the build container. Keep
outputting it to stdout, so that osbuild can collect it in the future.
2019-06-12 12:47:04 +02:00

46 lines
1.2 KiB
Python
Executable file

#!/usr/bin/python3
import argparse
import subprocess
import sys
RESET = "\033[0m"
BOLD = "\033[1m"
RED = "\033[31m"
def main(stage, sit):
subprocess.run(["ldconfig"], check=True)
subprocess.run(["systemd-sysusers"], check=True)
# Allow systemd-tmpfiles to return non-0. Some packages want to create
# directories owned by users that are not set up with systemd-sysusers.
subprocess.run(["systemd-tmpfiles", "--create"])
proc = subprocess.Popen([stage], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8")
with open("/tmp/output", "w") as output:
for line in proc.stdout:
sys.stdout.write(line)
output.write(line)
output.flush()
returncode = proc.wait()
if sit and returncode != 0:
import signal
print()
print(f"{RESET}{BOLD}{RED}Stage failed with code {returncode}{RESET}")
print("Keeping the build environment running...")
signal.pause()
return returncode
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("stage")
parser.add_argument("--sit", action="store_true")
args = parser.parse_args()
sys.exit(main(**vars(args)))