Documentation
¶
Overview ¶
Package apkindex parses Alpine APKINDEX files and installs .apk packages APK packages. It replaces "apk update" and "apk add" subprocess calls.
Typical usage:
idx, err := apkindex.Update(ctx)
if err != nil {
return err
}
if err := idx.Install(ctx, []string{"gcc", "musl-dev"}); err != nil {
return err
}
Index ¶
- func DetectArch() string
- func Install(ctx context.Context, names []string) error
- type Index
- func (idx *Index) DownloadPackage(ctx context.Context, destDir, name string) (string, error)
- func (idx *Index) DownloadPackages(ctx context.Context, destDir string, names []string) (map[string]string, error)
- func (idx *Index) InstallPackages(ctx context.Context, names []string) error
- func (idx *Index) InstallPackagesWithOptions(ctx context.Context, names []string, opts InstallOptions) error
- func (idx *Index) Lookup(name string) (*Package, bool)
- func (idx *Index) ParseIndex(r io.Reader, repoBaseURL string) error
- func (idx *Index) ResolveDeps(names []string) ([]*Package, error)
- func (idx *Index) ResolveVirtual(name string) (*Package, bool)
- func (idx *Index) Stats() (packages, capabilities int)
- type InstallOptions
- type Package
- type Repo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectArch ¶
func DetectArch() string
DetectArch returns the APK architecture for this host. Prefers /etc/apk/arch; falls back to constants.GetArchMapping().
func Install ¶
Install is a convenience function that calls Update to fetch the index, then installs the requested packages. This is the main entry point for replacing "apk update && apk add <pkgs>" subprocess calls.
APK package signature verification (RSA against the trusted keyring in /etc/apk/keys) is not yet implemented; the convenience wrapper accepts that gap when running on a privileged host (uid 0 — the expected case inside a yap build container) and refuses on a developer workstation. Use InstallPackagesWithOptions for explicit control.
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is an in-memory APKINDEX from one or more Alpine repositories.
func Load ¶
func Load() *Index
Load returns the cached Index from the most recent Update call, or nil if Update has not been called yet.
func Update ¶
Update fetches APKINDEX.tar.gz from every repo in /etc/apk/repositories, writes the parsed indexes into the cache dir, and returns an Index ready for lookups. Replaces "apk update". The returned Index is cached globally so Install can reuse it without re-fetching.
func (*Index) DownloadPackage ¶
DownloadPackage downloads a .apk file to destDir and returns its path.
func (*Index) DownloadPackages ¶
func (idx *Index) DownloadPackages(ctx context.Context, destDir string, names []string) (map[string]string, error)
DownloadPackages downloads multiple packages in parallel and returns a map of name → path. Uses cavaliergopher/grab for concurrent downloads.
func (*Index) InstallPackages ¶
InstallPackages downloads each requested package + transitive deps, extracts each to /, and updates /lib/apk/db/installed. Replaces "apk add".
Equivalent to InstallPackagesWithOptions with the zero options (strict).
func (*Index) InstallPackagesWithOptions ¶
func (idx *Index) InstallPackagesWithOptions( ctx context.Context, names []string, opts InstallOptions, ) error
InstallPackagesWithOptions is the explicit-options variant of InstallPackages. Scriptlets are not currently executed; they are logged as warnings.
func (*Index) Lookup ¶
Lookup returns the Package for the named package and whether it was found. The name must be the bare package name without version constraints.
func (*Index) ParseIndex ¶
ParseIndex parses an APKINDEX text stream into the index. repoBaseURL is attached to each parsed Package for later download URL construction.
func (*Index) ResolveDeps ¶
ResolveDeps does a simple greedy BFS over the index to resolve transitive dependencies. Returns a list of packages to install (in dependency order). Alpine deps are not a true SAT problem; conflicts are rare in practice.
func (*Index) ResolveVirtual ¶
ResolveVirtual returns the first concrete provider of a virtual package, or nil if no provider is found.
type InstallOptions ¶
type InstallOptions struct {
AllowUnverifiedPackages bool
}
InstallOptions controls the safety / trust knobs for InstallPackages.
AllowUnverifiedPackages: APK packages and APKINDEX tarballs ship with RSA signatures. Verification of those signatures is not yet wired into this package. Callers that accept this gap (e.g. inside a trusted CI container fetching over HTTPS from official mirrors) must set this flag explicitly.
type Package ¶
type Package struct {
Name string
Version string
Arch string
Size int64
InstSize int64
Description string
URL string
License string
Origin string
Maintainer string
Depends []string
Provides []string
Checksum string // Q1+base64-SHA1 — for content addressing
RepoBaseURL string // populated at parse time
}
Package holds the subset of APKINDEX fields needed for install/dep resolution.