Add dynamic apt-cacher-ng configuration system for collaborators
Some checks are pending
Checks / Spelling (push) Waiting to run
Checks / Python Linters (push) Waiting to run
Checks / Shell Linters (push) Waiting to run
Checks / 📦 Packit config lint (push) Waiting to run
Checks / 🔍 Check for valid snapshot urls (push) Waiting to run
Checks / 🔍 Check JSON files for formatting consistency (push) Waiting to run
Generate / Documentation (push) Waiting to run
Generate / Test Data (push) Waiting to run
Tests / Unittest (push) Waiting to run
Tests / Assembler test (legacy) (push) Waiting to run
Tests / Smoke run: unittest as normal user on default runner (push) Waiting to run

This commit is contained in:
robojerk 2025-08-26 15:52:43 -07:00
parent 39abab18f7
commit eb18f1a514
7 changed files with 570 additions and 25 deletions

View file

@ -6,6 +6,17 @@ import json
import osbuild.api
# Import our configuration manager
try:
from osbuild.config_manager import get_apt_proxy, is_apt_proxy_enabled
except ImportError:
# Fallback if config manager is not available
def get_apt_proxy():
return None
def is_apt_proxy_enabled():
return False
def run_apt_command(tree, command, env=None):
"""Run apt command in the target filesystem"""
@ -32,6 +43,21 @@ def run_apt_command(tree, command, env=None):
return True
def configure_apt_proxy(tree, proxy_url):
"""Configure apt proxy if specified"""
if not proxy_url or not proxy_url.strip():
return
print(f"Configuring apt proxy: {proxy_url}")
proxy_config = f"""Acquire::http::Proxy "{proxy_url}";
Acquire::https::Proxy "{proxy_url}";
"""
proxy_file = os.path.join(tree, "etc/apt/apt.conf.d/99proxy")
os.makedirs(os.path.dirname(proxy_file), exist_ok=True)
with open(proxy_file, "w") as f:
f.write(proxy_config)
def main(tree, options):
"""Main function for apt stage"""
@ -40,22 +66,21 @@ def main(tree, options):
recommends = options.get("recommends", False)
unauthenticated = options.get("unauthenticated", False)
update = options.get("update", True)
# Get apt proxy from multiple sources (priority order):
# 1. Stage options (highest priority)
# 2. Configuration file
# 3. Environment variable
apt_proxy = options.get("apt_proxy")
if not apt_proxy:
apt_proxy = get_apt_proxy()
if not packages:
print("No packages specified for installation")
return 1
# Configure apt proxy if specified
if apt_proxy:
print(f"Configuring apt proxy: {apt_proxy}")
proxy_config = f"""Acquire::http::Proxy "{apt_proxy}";
Acquire::https::Proxy "{apt_proxy}";
"""
proxy_file = os.path.join(tree, "etc/apt/apt.conf.d/99proxy")
os.makedirs(os.path.dirname(proxy_file), exist_ok=True)
with open(proxy_file, "w") as f:
f.write(proxy_config)
configure_apt_proxy(tree, apt_proxy)
# Update package lists if requested
if update:

View file

@ -25,6 +25,17 @@ from osbuild import api
from osbuild.util.mnt import mount
from osbuild.util.runners import create_machine_id_if_needed
# Import our configuration manager
try:
from osbuild.config_manager import get_apt_proxy, get_build_setting
except ImportError:
# Fallback if config manager is not available
def get_apt_proxy():
return None
def get_build_setting(key, default=None):
return default
def run_debootstrap(suite, target, mirror, arch=None, variant=None, extra_packages=None, apt_proxy=None):
"""Run debootstrap to create base Debian filesystem"""
@ -77,6 +88,21 @@ deb {mirror} {suite}-security main
print(f"Created sources.list for {suite}")
def configure_apt_proxy(tree, proxy_url):
"""Configure apt proxy if specified"""
if not proxy_url or not proxy_url.strip():
return
print(f"Configuring apt proxy: {proxy_url}")
proxy_config = f"""Acquire::http::Proxy "{proxy_url}";
Acquire::https::Proxy "{proxy_url}";
"""
proxy_file = os.path.join(tree, "etc/apt/apt.conf.d/99proxy")
os.makedirs(os.path.dirname(proxy_file), exist_ok=True)
with open(proxy_file, "w") as f:
f.write(proxy_config)
def generate_base_metadata(tree, suite, arch):
"""Generate metadata about the created base system"""
@ -128,13 +154,20 @@ def generate_base_metadata(tree, suite, arch):
def main(tree, options):
"""Main function for debootstrap stage"""
# Get options
suite = options.get("suite", "bookworm")
# Get options with fallbacks to configuration
suite = options.get("suite", get_build_setting("default_suite", "bookworm"))
mirror = options.get("mirror", "http://deb.debian.org/debian")
arch = options.get("arch")
arch = options.get("arch", get_build_setting("default_arch"))
variant = options.get("variant", "minbase")
extra_packages = options.get("extra_packages", [])
# Get apt proxy from multiple sources (priority order):
# 1. Stage options (highest priority)
# 2. Configuration file
# 3. Environment variable
apt_proxy = options.get("apt_proxy")
if not apt_proxy:
apt_proxy = get_apt_proxy()
if not suite:
print("No suite specified for debootstrap")
@ -154,15 +187,7 @@ def main(tree, options):
setup_apt_sources(tree, suite, mirror)
# Configure apt proxy if specified
if apt_proxy:
print(f"Configuring apt proxy: {apt_proxy}")
proxy_config = f"""Acquire::http::Proxy "{apt_proxy}";
Acquire::https::Proxy "{apt_proxy}";
"""
proxy_file = os.path.join(tree, "etc/apt/apt.conf.d/99proxy")
os.makedirs(os.path.dirname(proxy_file), exist_ok=True)
with open(proxy_file, "w") as f:
f.write(proxy_config)
configure_apt_proxy(tree, apt_proxy)
# Mount essential filesystems for package operations (similar to rpm stage)
for source in ("/dev", "/sys", "/proc"):
@ -189,6 +214,6 @@ Acquire::https::Proxy "{apt_proxy}";
if __name__ == '__main__':
args = osbuild.api.arguments()
args = api.arguments()
r = main(args["tree"], args["options"])
sys.exit(r)