pseudoapt

package module
v0.0.0-...-c152b52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

README

pseudoapt

Enough APT to build a rootfs for a container.

Usage

// Load repositories' metadata
repositories, err := pseudoapt.Load(ctx, aptCacheDir, digestCacheDir, apt.Repo{
	BaseURL: "https://deb.debian.org/debian",
	Distribution: "trixie",
	Components: []string{"main, "non-free"},
	Archs: []string{"amd64", "all"},
	// Get it from debian-keyring Debian package
	Keyring: `-----BEGIN PGP PUBLIC KEY BLOCK-----...`
})

// Get dependencies of the needed packages (best-effort, quite sloppy)
packages, err := pseudoapt.DependenciesClosure(repositories,
	[]string{"bash"},
	[]string{"awk"}, // ignore virtual package
)

// Unpack the packages into the rootfs dir, excluding some paths completely
err := pseudoapt.Copy(ctx, repositories, packages, rootfsDir, pseudoapt.ContainerExcludes)

// Finalize the chroot (ldconfig, /->/usr symlinks)
err := pseudoapt.Finalize(rootfsDir)

Copyright Onboard, Inc.

Licensed under Apache 2.0 license.

Documentation

Overview

Package pseudoapt creates rootfs from APT repositories

It is quite limited:

  • it does not check package versions
  • it does not support multiarch
  • it does not resolve virtual packages
  • it does not resolve dependencies with alternatives
  • it has no support for Conflicts, Replaces and other fields indispensable for long-living Debian/Ubuntu installations.
  • it does not run maintainer scripts

However for the limited use-case "populate this rootfs with shared libraries needed by this C++ binary" it works well enough.

It supports caching downloaded files. It supports package filters to cut down optional/unneded dependencies. It supports path filters to cut down unneeded files.

Typical usage:

destDir := "my-rootfs"
cacheDir := "my-cache"

// Load repositories metadata
repo, err := pseudoapt.Load(ctx, cacheDir, apt.Repo{
	BaseURL:      "https://deb.debian.org/debian",
	Distribution: "trixie",
	Components:   []string{"main"},
	Archs:        []string{"amd64", "all"},
	Keyring:      `-----BEGIN PGP PUBLIC KEY BLOCK-----...`,
}, apt.Repo{
	BaseURL:      "https://security.debian.org/debian-security",
	Distribution: "trixie-security",
	Components:   []string{"main"},
	Archs:        []string{"amd64", "all"},
	Keyring:      `-----BEGIN PGP PUBLIC KEY BLOCK-----...`,
}))

// Resolve packages to get the full set
packages, err := pseudoapt.DependenciesClosure(repo, []string{
	// Packages
	"libc-bin", // ld.so.conf
	"bash", // target package
}, []string{
	// Excludes
	"awk", // Virtual package, used only by maintainer scripts
	"debianutils", // Used only by maintainer scripts
}

// Install the packages into destDir
err = Copy(ctx, repo, packages, destDir, ContainerExcludes)

// ... Populate rootfs from other sources

// Perform finalizations
err = Finalize(destDir)

Index

Constants

This section is empty.

Variables

View Source
var ContainerExcludes = []string{

	"usr/share/common-licenses",
	"usr/share/doc",
	"usr/share/doc-base",
	"usr/share/info",
	"usr/share/man",

	"usr/share/locale",
	"usr/share/X11/locale",

	"etc/default",
	"etc/pam.d",
	"etc/skel",
	"etc/ufw",
	"usr/share/applications",
	"usr/share/apport",
	"usr/share/base-files",
	"usr/share/gcc/python",
	"usr/share/gdb",
	"usr/share/debianutils",
	"usr/share/lintian",
	"usr/share/menu",
	"usr/share/pixmaps",

	"etc/init.d",
	"etc/runit",
	"etc/sv",
	"etc/update-motd.d",
	"usr/lib/sysusers.d",
	"usr/lib/tmpfiles.d",
	"usr/lib/systemd",
	"usr/share/runit",

	"var/log",
}

ContainerExcludes is a set of excludes that match files unneeded in containers

Functions

func Copy

func Copy(ctx context.Context, repos *Repos, packages []string, destDir string, excludes []string) error

Copy copies a set of packages from the repository to the destdir

func DependenciesClosure

func DependenciesClosure(repos *Repos, seedPackages []string, skipPackages []string) ([]string, error)

DependenciesClosure adds to the seed packages all their dependencies

The resolution is not complete, see the package documentation.

Packages from skipPackages are skipped, this allows one to cut down dependency trees for optional functionality.

func Finalize

func Finalize(rootfsDir string) error

Finalize applies postprocessing to the rootfs that is usually done in maintainer scripts: - /usr merge - ld.so.cache generation

Types

type Repos

type Repos struct {
	// contains filtered or unexported fields
}

Repos contains APT repositories

func Load

func Load(ctx context.Context, aptCacheDir, digestCacheDir string, rs ...apt.Repo) (*Repos, error)

Load loads APT repositories, making them ready to apply to the rootfs.

Packages in latter repositories override packages in former, so to get a Debian with security updates use the order [debianRepo, debianSecurityRepo]

Directories

Path Synopsis
Package debversion is a pure-go implementation of dpkg version string functions (parsing, comparison) which is compatible with dpkg(1).
Package debversion is a pure-go implementation of dpkg version string functions (parsing, comparison) which is compatible with dpkg(1).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL