diff --git a/stages/org.osbuild.apt b/stages/org.osbuild.apt index 39b3063a..f2d2e1fa 100644 --- a/stages/org.osbuild.apt +++ b/stages/org.osbuild.apt @@ -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...") diff --git a/stages/org.osbuild.apt.meta.json b/stages/org.osbuild.apt.meta.json index c8a6504f..246e84af 100644 --- a/stages/org.osbuild.apt.meta.json +++ b/stages/org.osbuild.apt.meta.json @@ -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"] diff --git a/stages/org.osbuild.debootstrap b/stages/org.osbuild.debootstrap index 9d99fdd1..93a7428c 100644 --- a/stages/org.osbuild.debootstrap +++ b/stages/org.osbuild.debootstrap @@ -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}") diff --git a/stages/org.osbuild.debootstrap.meta.json b/stages/org.osbuild.debootstrap.meta.json index 854392c1..ad043f62 100644 --- a/stages/org.osbuild.debootstrap.meta.json +++ b/stages/org.osbuild.debootstrap.meta.json @@ -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"]