Add apt-cacher-ng support to Debian stages for improved build performance

This commit is contained in:
robojerk 2025-08-22 18:14:00 -07:00
parent 31162116f8
commit 85e0c04d21
4 changed files with 39 additions and 2 deletions

View file

@ -40,11 +40,23 @@ def main(tree, options):
recommends = options.get("recommends", False)
unauthenticated = options.get("unauthenticated", False)
update = options.get("update", True)
apt_proxy = options.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)
# Update package lists if requested
if update:
print("Updating package lists...")

View file

@ -26,6 +26,10 @@
"type": "boolean",
"default": true,
"description": "Update package lists before installation"
},
"apt_proxy": {
"type": "string",
"description": "apt-cacher-ng proxy URL (e.g., http://localhost:3142)"
}
},
"required": ["packages"]

View file

@ -8,7 +8,7 @@ import shutil
import osbuild.api
def run_debootstrap(suite, target, mirror, arch=None, variant=None, extra_packages=None):
def run_debootstrap(suite, target, mirror, arch=None, variant=None, extra_packages=None, apt_proxy=None):
"""Run debootstrap to create base Debian filesystem"""
cmd = ["debootstrap"]
@ -22,6 +22,11 @@ def run_debootstrap(suite, target, mirror, arch=None, variant=None, extra_packag
if extra_packages:
cmd.extend(["--include", ",".join(extra_packages)])
# Add proxy configuration if specified
if apt_proxy:
cmd.extend(["--keyring", "/usr/share/keyrings/debian-archive-keyring.gpg"])
# debootstrap doesn't directly support proxy, but we'll configure it after creation
cmd.extend([suite, target, mirror])
print(f"Running debootstrap: {' '.join(cmd)}")
@ -63,6 +68,7 @@ def main(tree, options):
arch = options.get("arch")
variant = options.get("variant", "minbase")
extra_packages = options.get("extra_packages", [])
apt_proxy = options.get("apt_proxy")
if not suite:
print("No suite specified for debootstrap")
@ -77,12 +83,23 @@ def main(tree, options):
print(f"Creating base Debian filesystem in {temp_dir}")
# Run debootstrap
if not run_debootstrap(suite, temp_dir, mirror, arch, variant, extra_packages):
if not run_debootstrap(suite, temp_dir, mirror, arch, variant, extra_packages, apt_proxy):
return 1
# Set up apt sources
setup_apt_sources(temp_dir, 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(temp_dir, "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)
# Copy files to target tree
print(f"Copying filesystem to target tree: {tree}")

View file

@ -31,6 +31,10 @@
},
"default": [],
"description": "Additional packages to include in base filesystem"
},
"apt_proxy": {
"type": "string",
"description": "apt-cacher-ng proxy URL (e.g., http://localhost:3142)"
}
},
"required": ["suite", "mirror"]