feat: full rootless setup (#165)

* use local devtools configs instead of global ones

* make docker image rootless

* add migration notes

* fix setup command

* fix regress jo
This commit is contained in:
arcanis authored and GitHub committed 2026-08-14 13:34:42 +03:00
1 parent 695424fa16
commit 3548b434be
36 files changed
+581 -147

No files matched your search

@@ -28,7 +28,7 @@ from urllib.parse import quote_plus as url_encode
from ahriman.application.application import Application
from ahriman.application.handlers.handler import Handler, SubParserAction
from ahriman.core.configuration import Configuration
from ahriman.core.exceptions import MissingArchitectureError
from ahriman.core.exceptions import InitializeError, MissingArchitectureError
from ahriman.core.utils import enum_values
from ahriman.models.repository_id import RepositoryId
from ahriman.models.sign_settings import SignSettings
@@ -63,18 +63,20 @@ class Setup(Handler):
if args.architecture is None or args.repository is None:
raise MissingArchitectureError(args.command)
Setup.configuration_create_ahriman(args, repository_id, configuration)
target_directory = Setup.configuration_create_directory(configuration)
Setup.configuration_create_ahriman(args, repository_id, configuration, target_directory)
configuration.reload()
application = Application(repository_id, configuration, report=report)
paths = application.repository.paths
# basically we create configuration here as root, but it is ok, because those files are only used for reading
repository_server = f"file://{application.repository.paths.repository}" if args.server is None else args.server
Setup.configuration_create_devtools(
repository_id, args.from_configuration, args.mirror, args.multilib, repository_server)
repository_server = f"file://{paths.repository}" if args.server is None else args.server
target_directory = paths.ensure_exists(configuration.getpath("build", "devtools_configs"))
Setup.configuration_create_devtools(repository_id, args.from_configuration, target_directory, args.mirror,
args.multilib, repository_server)
# finish initialization
with application.repository.paths.preserve_owner():
with paths.preserve_owner():
application.repository.repo.init()
# lazy database sync
application.repository.pacman.handle # pylint: disable=pointless-statement
@@ -114,12 +116,12 @@ class Setup(Handler):
parser.add_argument("--web-port", help="port of the web service", type=int)
parser.add_argument("--web-unix-socket", help="path to unix socket used for interprocess communications",
type=Path)
parser.set_defaults(lock=None, quiet=True, report=False, unsafe=True)
parser.set_defaults(lock=None, quiet=True, report=False)
return parser
@staticmethod
def configuration_create_ahriman(args: argparse.Namespace, repository_id: RepositoryId,
root: Configuration) -> None:
root: Configuration, target_directory: Path) -> None:
"""
create service specific configuration
@@ -127,6 +129,7 @@ class Setup(Handler):
args(argparse.Namespace): command line args
repository_id(RepositoryId): repository unique identifier
root(Configuration): root configuration instance
target_directory(Path): path to directory where configuration files will be written
"""
configuration = Configuration()
@@ -164,15 +167,13 @@ class Setup(Handler):
if args.generate_salt:
configuration.set_option("auth", "salt", User.generate_password(20))
include_path = next(path for path in root.getpathlist("settings", "include") if os.access(path, os.W_OK))
(include_path / "00-setup-overrides.ini").unlink(missing_ok=True) # remove old-style configuration
target = include_path / f"00-setup-overrides-{repository_id.id}.ini"
target = target_directory / f"00-setup-overrides-{repository_id.id}.ini"
with target.open("w", encoding="utf8") as ahriman_configuration:
configuration.write(ahriman_configuration)
@staticmethod
def configuration_create_devtools(repository_id: RepositoryId, source: Path, mirror: str | None,
multilib: bool, repository_server: str) -> None:
def configuration_create_devtools(repository_id: RepositoryId, source: Path, target_directory: Path,
mirror: str | None, multilib: bool, repository_server: str) -> None:
"""
create configuration for devtools based on ``source`` configuration
@@ -182,6 +183,7 @@ class Setup(Handler):
Args:
repository_id(RepositoryId): repository unique identifier
source(Path): path to source configuration file
target_directory(Path): path to directory where configuration files will be written
mirror(str | None): link to package server mirror
multilib(bool): add or do not multilib repository to the configuration
repository_server(str): url of the repository
@@ -216,8 +218,32 @@ class Setup(Handler):
configuration.set_option(repository_id.name, "SigLevel", "Never") # we don't care
configuration.set_option(repository_id.name, "Server", repository_server)
target = source.parent / f"{repository_id.name}-{repository_id.architecture}.conf"
target = target_directory / f"{repository_id.name}-{repository_id.architecture}.conf"
with target.open("w", encoding="utf8") as devtools_configuration:
configuration.write(devtools_configuration)
@staticmethod
def configuration_create_directory(root: Configuration) -> Path:
"""
create directory for includes
Args:
root(Configuration): root configuration instance
Returns:
Path: path to first writable directory
Raises:
InitializeError: if no writable directories have been found
"""
for include_path in root.include:
try:
directory = root.repository_paths.ensure_exists(include_path)
if os.access(directory, os.W_OK | os.X_OK):
return directory
except OSError:
continue
raise InitializeError("No writable include directory found")
arguments = [_set_service_setup_parser]
@@ -38,6 +38,7 @@ class Task(LazyLogging):
Attributes:
archbuild_flags(list[str]): command flags for archbuild command
build_command(list[str]): build command
devtools_configs(Path): path to local directory with devtools configuration files
include_debug_packages(bool): whether to include debug packages or not
make_flags(str): MAKEFLAGS variable for makepkg command
makechrootpkg_flags(list[str]): command flags for makechrootpkg command
@@ -64,6 +65,7 @@ class Task(LazyLogging):
self.archbuild_flags = configuration.getlist("build", "archbuild_flags", fallback=[])
self.build_command = configuration.getlist("build", "devtools_wrapper")
self.devtools_configs = configuration.getpath("build", "devtools_configs")
self._legacy_build_command = configuration.getlist("build", "build_command", fallback=[])
self.include_debug_packages = configuration.getboolean("build", "include_debug_packages", fallback=True)
# even though this option is declared as list, there is no need to read it as list,
@@ -116,7 +118,12 @@ class Task(LazyLogging):
"""
command = self._legacy_build_command[:]
if not command:
command = self.build_command + ["-r", self.repository_id.name, "-a", self.repository_id.architecture, "--"]
command = self.build_command + [
"-r", self.repository_id.name,
"-a", self.repository_id.architecture,
"-c", str(self.devtools_configs),
"--",
]
command.extend(["-r", str(self.paths.chroot)] + self.archbuild_flags) # archbuild flags
command.extend(["--", "-D", str(self.paths.archive)] + self.makechrootpkg_flags) # makechrootpkg flags
@@ -108,6 +108,16 @@ class Configuration(configparser.RawConfigParser):
_, repository_id = self.check_loaded()
return repository_id.architecture
@property
def include(self) -> list[Path]:
"""
get full path to include directory
Returns:
list[Path]: paths to directories with configuration includes
"""
return self.getpathlist("settings", "include")
@property
def logging_path(self) -> Path:
"""
@@ -322,20 +332,11 @@ class Configuration(configparser.RawConfigParser):
self.includes = [] # reset state
try:
# raw processing to make sure that options are applied correctly
include_directories = shlex.split(self.get("settings", "include", raw=True))
include_directories = self.include
except (configparser.NoOptionError, configparser.NoSectionError):
return
for directory in include_directories:
value = self._interpolation.before_get( # type: ignore[attr-defined]
self,
"settings",
"include",
directory,
self._unify_values("settings", None), # type: ignore[attr-defined]
)
path = self._convert_path(value)
for path in include_directories: # pylint: disable=not-an-iterable
if not path.is_dir():
continue
@@ -200,6 +200,13 @@ CONFIGURATION_SCHEMA: ConfigurationSchema = {
"empty": False,
},
},
"devtools_configs": {
"type": "path",
"coerce": "absolute_path",
"required": True,
"path_exists": True,
"path_type": "dir",
},
"devtools_wrapper": {
"type": "list",
"coerce": "list",
@@ -103,7 +103,7 @@ class RepositoryPaths(LazyLogging):
Returns:
Path: path to directory in which build process is run
"""
uid, _ = owner(self.root)
uid, _ = self.root_owner
return self.chroot / f"{self.repository_id.name}-{self.repository_id.architecture}" / getpwuid(uid).pw_name
@property
@@ -127,6 +127,16 @@ class RepositoryPaths(LazyLogging):
# for the chroot directory devtools will create own tree, and we don't have to specify architecture here
return self.root / "chroot" / self.repository_id.name
@property
def configs(self) -> Path:
"""
get directory for local configuration files
Returns:
Path: full path to local configuration directory
"""
return self.root / ".config" / "ahriman"
@property
def packages(self) -> Path:
"""
@@ -323,6 +333,7 @@ class RepositoryPaths(LazyLogging):
self.archive,
self.cache,
self.chroot,
self.configs,
self.packages,
self.pacman,
self.repository,