mirror of https://gerrit.osmocom.org/osmo-ci
obs: build_binpkg: add --run-shell-on-error arg
Allow easy inspection of the build dir inside docker on error. Related: OS#5737 Change-Id: I218c3189d36d24c64cbd7b9eab379aff8ce2bee2
This commit is contained in:
parent
13b76cced1
commit
8d7596a311
|
@ -29,6 +29,8 @@ def main():
|
|||
f" distro (default: {distro_default})")
|
||||
parser.add_argument("-j", "--jobs", type=int, default=jobs_default,
|
||||
help=f"parallel running jobs (default: {jobs_default})")
|
||||
parser.add_argument("-r", "--run-shell-on-error", action="store_true",
|
||||
help="run an interactive shell if the build fails")
|
||||
parser.add_argument("-v", "--verbose", action="store_true",
|
||||
help="always print shell commands and their output,"
|
||||
" instead of only printing them on error")
|
||||
|
@ -52,11 +54,18 @@ def main():
|
|||
|
||||
env = {"JOBS": str(args.jobs),
|
||||
"PACKAGE": args.package,
|
||||
"BUILDUSER": os.environ["USER"]}
|
||||
"BUILDUSER": os.environ["USER"],
|
||||
"PACKAGEFORMAT": "deb"}
|
||||
|
||||
docker_args = []
|
||||
if args.run_shell_on_error:
|
||||
env["RUN_SHELL_ON_ERROR"] = "1"
|
||||
docker_args += ["-i", "-t"]
|
||||
|
||||
script_path = "data/build.sh"
|
||||
|
||||
script_path = "data/build_deb.sh"
|
||||
if not distro.startswith("debian:"):
|
||||
script_path = "data/build_rpm.sh"
|
||||
env["PACKAGEFORMAT"] = "rpm"
|
||||
|
||||
if args.docker:
|
||||
image_type = "build_binpkg"
|
||||
|
@ -71,7 +80,8 @@ def main():
|
|||
lib.docker.run_in_docker_and_exit(script_path,
|
||||
image_type=image_type,
|
||||
distro=distro,
|
||||
pass_argv=False, env=env)
|
||||
pass_argv=False, env=env,
|
||||
docker_args=docker_args)
|
||||
else:
|
||||
lib.run_cmd(["sudo", "-E", script_path], env=env,
|
||||
cwd=lib.config.path_top)
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
if ! data/build_"$PACKAGEFORMAT".sh; then
|
||||
echo
|
||||
echo "ERROR: build failed!"
|
||||
echo
|
||||
if [ -n "$RUN_SHELL_ON_ERROR" ]; then
|
||||
bash
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Build successful!"
|
||||
echo
|
|
@ -51,7 +51,7 @@ def get_oscrc():
|
|||
|
||||
def run_in_docker_and_exit(script_path, add_oscrc=False,
|
||||
image_type="build_srcpkg", distro=None,
|
||||
pass_argv=True, env={}):
|
||||
pass_argv=True, env={}, docker_args=[]):
|
||||
"""
|
||||
:param script_path: what to run inside docker, relative to scripts/obs/
|
||||
:param add_oscrc: put user's oscrc in docker (contains obs credentials!)
|
||||
|
@ -59,6 +59,7 @@ def run_in_docker_and_exit(script_path, add_oscrc=False,
|
|||
:param distro: which Linux distribution to use, e.g. "debian:11"
|
||||
:param pass_argv: pass arguments from sys.argv to the script
|
||||
:param env: dict of environment variables
|
||||
:param docker_args: extra arguments to pass to docker
|
||||
"""
|
||||
if "INSIDE_DOCKER" in os.environ:
|
||||
return
|
||||
|
@ -92,13 +93,13 @@ def run_in_docker_and_exit(script_path, add_oscrc=False,
|
|||
"-e", "PYTHONUNBUFFERED=1",
|
||||
"-v", f"{lib.config.path_top}:/obs"]
|
||||
|
||||
|
||||
for env_key, env_val in env.items():
|
||||
cmd += ["-e", f"{env_key}={env_val}"]
|
||||
|
||||
if oscrc:
|
||||
cmd += ["-v", f"{oscrc}:/home/user/.oscrc"]
|
||||
|
||||
cmd += docker_args
|
||||
cmd += [image_name, f"/obs/{script_path}"]
|
||||
|
||||
if pass_argv:
|
||||
|
|
Loading…
Reference in New Issue