apkindex

package
v2.1.9 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: GPL-3.0 Imports: 21 Imported by: 0

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

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

func Install(ctx context.Context, names []string) error

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 NewIndex

func NewIndex() *Index

NewIndex creates a new empty Index.

func Update

func Update(ctx context.Context) (*Index, error)

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

func (idx *Index) DownloadPackage(ctx context.Context, destDir, name string) (string, error)

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

func (idx *Index) InstallPackages(ctx context.Context, names []string) error

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

func (idx *Index) Lookup(name string) (*Package, bool)

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

func (idx *Index) ParseIndex(r io.Reader, repoBaseURL string) error

ParseIndex parses an APKINDEX text stream into the index. repoBaseURL is attached to each parsed Package for later download URL construction.

func (*Index) ResolveDeps

func (idx *Index) ResolveDeps(names []string) ([]*Package, error)

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

func (idx *Index) ResolveVirtual(name string) (*Package, bool)

ResolveVirtual returns the first concrete provider of a virtual package, or nil if no provider is found.

func (*Index) Stats

func (idx *Index) Stats() (packages, capabilities int)

Stats returns the number of packages and capabilities (Provides) indexed. Useful for diagnostic logging after Update.

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.

type Repo

type Repo struct {
	URL string // Base URL of the repository
	Tag string // Tag for tagged repos (e.g., "@edge"), empty for untagged
}

Repo represents an Alpine repository entry from /etc/apk/repositories.

func LoadRepos

func LoadRepos() ([]Repo, error)

LoadRepos parses /etc/apk/repositories and returns the list of repositories. Returns an empty slice on non-Alpine systems or read errors.

Jump to

Keyboard shortcuts

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