
Refactor prestaging/poststaging of the ostree deployment so that it supports regular Ostree and StarlingX. Story: 2010867 Task: 48556 Test Plan: PASSED Installed apt-ostree from git repo. PASSED Run sudo apt-ostree compose create \ --base config/debian/bookworm \ --repo /repo debian/bookworm \ bookworm-test PASSED Run sudo apt-ostree compose upgrade \ --repo /repo --branch bookworm-test PASSED Check the output of "ostree log --repo /repo bookworm-test". Change-Id: I892bbb2b28cc929e22476efa682d8ed0dc812462 Signed-off-by: Charles Short <charles.short@windriver.com>
80 lines
1.7 KiB
Python
80 lines
1.7 KiB
Python
"""
|
|
Copyright (c) 2023 Wind River Systems, Inc.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
|
|
import click
|
|
|
|
|
|
def run_command(cmd,
|
|
debug=False,
|
|
stdin=None,
|
|
stdout=None,
|
|
stderr=None,
|
|
check=True,
|
|
env=None,
|
|
cwd=None):
|
|
"""Run a command in a shell."""
|
|
_env = os.environ.copy()
|
|
if env:
|
|
_env.update(env)
|
|
try:
|
|
return subprocess.run(
|
|
cmd,
|
|
stdin=stdin,
|
|
stdout=stdout,
|
|
stderr=stderr,
|
|
env=_env,
|
|
cwd=cwd,
|
|
check=check,
|
|
)
|
|
except FileNotFoundError:
|
|
click.secho(f"{cmd[0]} not found in PATH.")
|
|
except subprocess.CalledProcessError as e:
|
|
click.secho(f"Failed to run command: {e}")
|
|
raise
|
|
|
|
|
|
def run_sandbox_command(
|
|
args,
|
|
rootfs,
|
|
stdin=None,
|
|
stdout=None,
|
|
stderr=None,
|
|
check=True,
|
|
env=None
|
|
):
|
|
"""Run a shell wrapped with bwrap."""
|
|
cmd = [
|
|
"bwrap",
|
|
"--proc", "/proc",
|
|
"--dev", "/dev",
|
|
"--dir", "/run",
|
|
"--bind", "/tmp", "/tmp",
|
|
"--bind", f"{rootfs}/usr", "/usr",
|
|
"--bind", f"{rootfs}/etc", "/etc",
|
|
"--bind", f"{rootfs}/var", "/var",
|
|
"--symlink", "/usr/lib", "/lib",
|
|
"--symlink", "/usr/lib64", "/lib64",
|
|
"--symlink", "/usr/bin", "/bin",
|
|
"--symlink", "/usr/sbin", "/sbin",
|
|
"--share-net",
|
|
"--die-with-parent",
|
|
"--chdir", "/",
|
|
]
|
|
cmd += args
|
|
|
|
return run_command(
|
|
cmd,
|
|
stdin=stdin,
|
|
stdout=stdout,
|
|
stderr=stderr,
|
|
check=check,
|
|
env=env,
|
|
)
|