
Add support to run shell commands inside a checked out ostree branch. The way that this works is the following: 1. Determine the branch to checkout. 2. Checkout the branch in the workspace. 3. Use systemd-nspawn to create a shell inside the branch. 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 exec --repo /repo --branch bookwork-test "cat /etc/debian_version" Story: 2010867 Task: 48556 Change-Id: I6ff9658fc04ec83d50d2cb5f3b8dbb70e3065688 Signed-off-by: Charles Short <charles.short@windriver.com>
55 lines
1.1 KiB
Python
55 lines
1.1 KiB
Python
"""
|
|
Copyright (c) 2023 Wind River Systems, Inc.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
"""
|
|
|
|
import errno
|
|
import sys
|
|
|
|
import click
|
|
|
|
from apt_ostree.cmd import pass_state_context
|
|
from apt_ostree.run import RunCommand
|
|
|
|
|
|
@click.command(
|
|
name="exec",
|
|
help="Run a command or shell from an Ostree branch.")
|
|
@pass_state_context
|
|
@click.option(
|
|
"--mounts",
|
|
help="Path to yaml configuration for mount points.",
|
|
type=click.Path(exists=True)
|
|
)
|
|
@click.option(
|
|
"--root",
|
|
help="Path to operate on",
|
|
)
|
|
@click.option(
|
|
"--pre-exec",
|
|
'pre_exec',
|
|
help="Run the command before executing the container",
|
|
)
|
|
@click.argument(
|
|
"cmd",
|
|
# If command not specified then execute a shell.
|
|
default=""
|
|
)
|
|
def run(state,
|
|
mounts,
|
|
root,
|
|
pre_exec,
|
|
cmd):
|
|
try:
|
|
RunCommand(state).run_command(cmd, mounts, pre_exec, root)
|
|
except KeyboardInterrupt:
|
|
click.secho("\n" + ("Exiting at your request."))
|
|
sys.exit(130)
|
|
except BrokenPipeError:
|
|
sys.exit()
|
|
except OSError as error:
|
|
if error.errno == errno.ENOSPC:
|
|
sys.exit("error - No space left on device.")
|