apk

package
v0.0.0-...-bdccd16 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 45 Imported by: 13

Documentation

Overview

Copyright 2023 Chainguard, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	DefaultKeyRingPath       = "/etc/apk/keys"
	DefaultSystemKeyRingPath = "/usr/share/apk/keys/"
)

Variables

This section is empty.

Functions

func ArchToAPK

func ArchToAPK(in string) string

func ArchiveFromIndex

func ArchiveFromIndex(apkindex *APKIndex) (archive io.Reader, err error)

func IndexURL

func IndexURL(repo, arch string) string

IndexURL full URL to the index file for the given repo and arch

func PackageToInstalled

func PackageToInstalled(pkg *Package) (out []string)

PackageToInstalled takes a Package and returns it as the string representation of lines in a /lib/apk/db/installed file.

Types

type APK

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

func New

func New(options ...Option) (*APK, error)

func (*APK) AddInstalledPackage

func (a *APK) AddInstalledPackage(pkg *Package, files []tar.Header) error

addInstalledPackage add a package to the list of installed packages

func (*APK) CalculateWorld

func (a *APK) CalculateWorld(ctx context.Context, allpkgs []*RepositoryPackage) ([]*APKResolved, error)

func (*APK) FetchPackage

func (a *APK) FetchPackage(ctx context.Context, pkg InstallablePackage) (io.ReadCloser, error)

func (*APK) FixateWorld

func (a *APK) FixateWorld(ctx context.Context, sourceDateEpoch *time.Time) error

FixateWorld force apk's resolver to re-resolve the requested dependencies in /etc/apk/world.

func (*APK) GetInstalled

func (a *APK) GetInstalled() ([]*InstalledPackage, error)

getInstalledPackages get list of installed packages

func (*APK) GetRepositories

func (a *APK) GetRepositories() (repos []string, err error)

func (*APK) GetRepositoryIndexes

func (a *APK) GetRepositoryIndexes(ctx context.Context, ignoreSignatures bool) ([]NamedIndex, error)

GetRepositoryIndexes returns the indexes for the repositories in the specified root. The signatures for each index are verified unless ignoreSignatures is set to true.

func (*APK) GetWorld

func (a *APK) GetWorld() ([]string, error)

GetWorld - get list of packages that should be installed, according to /etc/apk/world

func (*APK) InitDB

func (a *APK) InitDB(ctx context.Context, alpineVersions ...string) error

Initialize the APK database for a given build context. Assumes base directories are in place and checks them. Returns the list of files and directories and files installed and permissions, unless those files will be included in the installed database, in which case they can be retrieved via GetInstalled().

func (*APK) InitKeyring

func (a *APK) InitKeyring(ctx context.Context, keyFiles, extraKeyFiles []string) error

Installs the specified keys into the APK keyring inside the build context.

func (*APK) InstallPackages

func (a *APK) InstallPackages(ctx context.Context, sourceDateEpoch *time.Time, allpkgs []InstallablePackage) error

func (*APK) ListInitFiles

func (a *APK) ListInitFiles() []tar.Header

ListInitFiles list the files that are installed during the InitDB phase.

func (*APK) ResolveAndCalculateWorld

func (a *APK) ResolveAndCalculateWorld(ctx context.Context) ([]*APKResolved, error)

func (*APK) ResolveWorld

func (a *APK) ResolveWorld(ctx context.Context) (toInstall []*RepositoryPackage, conflicts []string, err error)

ResolveWorld determine the target state for the requested dependencies in /etc/apk/world. Does not install anything.

func (*APK) SetClient

func (a *APK) SetClient(client *http.Client)

SetClient set the http client to use for downloading packages. In general, you can leave this unset, and it will use the default http.Client. It is useful for fine-grained control, for proxying, or for setting alternate paths.

func (*APK) SetRepositories

func (a *APK) SetRepositories(ctx context.Context, repos []string) error

SetRepositories sets the contents of /etc/apk/repositories file. The base directory of /etc/apk must already exist, i.e. this only works on an initialized APK database.

func (*APK) SetWorld

func (a *APK) SetWorld(ctx context.Context, packages []string) error

SetWorld sets the list of world packages intended to be installed. The base directory of /etc/apk must already exist, i.e. this only works on an initialized APK database.

type APKIndex

type APKIndex struct {
	Signature   []byte
	Description string
	Packages    []*Package
}

func IndexFromArchive

func IndexFromArchive(archive io.ReadCloser) (*APKIndex, error)

type APKResolved

type APKResolved struct {
	Package *RepositoryPackage

	SignatureSize int
	SignatureHash []byte

	ControlSize int
	ControlHash []byte

	DataSize int
	DataHash []byte
}

func ResolveApk

func ResolveApk(ctx context.Context, source io.Reader) (*APKResolved, error)

type ConstraintError

type ConstraintError struct {
	Constraint string
	Wrapped    error
}

func (*ConstraintError) Error

func (e *ConstraintError) Error() string

func (*ConstraintError) Unwrap

func (e *ConstraintError) Unwrap() error

type DateTime

type DateTime struct {
	time.Time
}

DateTime wrapper for time.Time because the date format is "YYYY-MM-DD"

func (DateTime) MarshalJSON

func (c DateTime) MarshalJSON() ([]byte, error)

func (*DateTime) UnmarshalJSON

func (c *DateTime) UnmarshalJSON(b []byte) error

type DepError

type DepError struct {
	Package *RepositoryPackage
	Wrapped error
}

func (*DepError) Error

func (e *DepError) Error() string

func (*DepError) Unwrap

func (e *DepError) Unwrap() error

type DisqualifiedError

type DisqualifiedError struct {
	Package *RepositoryPackage
	Wrapped error
}

func (*DisqualifiedError) Error

func (e *DisqualifiedError) Error() string

func (*DisqualifiedError) Unwrap

func (e *DisqualifiedError) Unwrap() error

type Executor

type Executor interface {
	Execute(name string, arg ...string) error
}

Executor provider of interface to execute commands, if used. Will be used primarily to execute scripts.

type FileExistsError

type FileExistsError struct {
	Path string
	Sha1 []byte
}

func (FileExistsError) Error

func (f FileExistsError) Error() string

func (FileExistsError) Is

func (f FileExistsError) Is(target error) bool

type IndexOption

type IndexOption func(*indexOpts)

func WithHTTPClient

func WithHTTPClient(c *http.Client) IndexOption

func WithIgnoreSignatureForIndexes

func WithIgnoreSignatureForIndexes(noSignatureIndexes ...string) IndexOption

func WithIgnoreSignatures

func WithIgnoreSignatures(ignoreSignatures bool) IndexOption

type InstallablePackage

type InstallablePackage interface {
	URL() string
	PackageName() string
	ChecksumString() string
}

InstallablePackage represents a minimal set of information needed to install a package within an Image.

type InstalledPackage

type InstalledPackage struct {
	Package
	Files []tar.Header
}

func ParseInstalled

func ParseInstalled(installed io.Reader) ([]*InstalledPackage, error)

parseInstalled parses an installed file. It returns the installed packages.

type NamedIndex

type NamedIndex interface {
	Name() string
	Packages() []*RepositoryPackage
	Source() string
	Count() int
}

NamedIndex an index that contains all of its packages, as well as having an optional name and source. The name and source need not be unique.

func GetRepositoryIndexes

func GetRepositoryIndexes(ctx context.Context, repos []string, keys map[string][]byte, arch string, options ...IndexOption) (indexes []NamedIndex, err error)

GetRepositoryIndexes returns the indexes for the named repositories, keys and archs. The signatures for each index are verified unless ignoreSignatures is set to true. The key-value pairs in the map for `keys` are the name of the key and the contents of the key. The name is just indicative. If it finds a match, it will use it. Else, it will try all keys.

func NewNamedRepositoryWithIndex

func NewNamedRepositoryWithIndex(name string, repo *RepositoryWithIndex) NamedIndex

type NoKeysFoundError

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

func (*NoKeysFoundError) Error

func (e *NoKeysFoundError) Error() string

type Option

type Option func(*opts) error

func WithArch

func WithArch(arch string) Option

WithArch sets the architecture to use. If not provided, will use the default runtime.GOARCH.

func WithCache

func WithCache(cacheDir string, offline bool) Option

WithCache sets to use a cache directory for downloaded apk files and APKINDEX files. If not provided, will not cache.

If offline is true, only read from the cache and do not make any network requests to populate it.

func WithExecutor

func WithExecutor(executor Executor) Option

WithExecutor executor to use. Not currently used.

func WithFS

func WithFS(fs apkfs.FullFS) Option

WithFS sets the filesystem to use. If not provided, will use the OS filesystem based at root /.

func WithIgnoreMknodErrors

func WithIgnoreMknodErrors(ignore bool) Option

WithIgnoreMknodErrors sets whether to ignore errors when creating device nodes. Default is false.

func WithNoSignatureIndexes

func WithNoSignatureIndexes(noSignatureIndex ...string) Option

func WithVersion

func WithVersion(version string) Option

WithVersion sets the version to use for downloading keys and other purposes. If not provided, finds the latest stable.

type Package

type Package struct {
	Name             string `ini:"pkgname"`
	Version          string `ini:"pkgver"`
	Arch             string `ini:"arch"`
	Description      string `ini:"pkgdesc"`
	License          string `ini:"license"`
	Origin           string `ini:"origin"`
	Maintainer       string `ini:"maintainer"`
	URL              string `ini:"url"`
	Checksum         []byte
	Dependencies     []string `ini:"depend,,allowshadow"`
	Provides         []string `ini:"provides,,allowshadow"`
	InstallIf        []string
	Size             uint64 `ini:"size"`
	InstalledSize    uint64
	ProviderPriority uint64 `ini:"provider_priority"`
	BuildTime        time.Time
	BuildDate        int64    `ini:"builddate"`
	RepoCommit       string   `ini:"commit"`
	Replaces         []string `ini:"replaces,,allowshadow"`
	DataHash         string   `ini:"datahash"`
}

Package represents a single package with the information present in an APKINDEX.

func ParsePackage

func ParsePackage(ctx context.Context, apkPackage io.Reader) (*Package, error)

ParsePackage parses a .apk file and returns a Package struct

func ParsePackageIndex

func ParsePackageIndex(apkIndexUnpacked io.Reader) ([]*Package, error)

ParsePackageIndex parses a plain (uncompressed) APKINDEX file. It returns an ApkIndex struct

func (*Package) ChecksumString

func (p *Package) ChecksumString() string

ChecksumString returns a human-readable version of the control section checksum.

func (*Package) Filename

func (p *Package) Filename() string

Filename returns the package filename as it's named in a repository.

func (*Package) PackageName

func (p *Package) PackageName() string

func (*Package) String

func (p *Package) String() string

type PkgResolver

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

PkgResolver resolves packages from a list of indexes. It is created with NewPkgResolver and passed a list of indexes. It then can be used to resolve the correct version of a package given version constraints, if any, as well as all the package and all of the required upstream dependencies. If provided multiple indexes, it will look for dependencies in all of the indexes. If you need to look only in a certain set, you should create a new PkgResolver with only those indexes. If the indexes change, you should generate a new pkgResolver.

func NewPkgResolver

func NewPkgResolver(_ context.Context, indexes []NamedIndex) *PkgResolver

NewPkgResolver creates a new pkgResolver from a list of indexes. The indexes are anything that implements NamedIndex.

func (*PkgResolver) GetPackageWithDependencies

func (p *PkgResolver) GetPackageWithDependencies(pkgName string, existing map[string]*RepositoryPackage, dq map[*RepositoryPackage]string) (*RepositoryPackage, []*RepositoryPackage, []string, error)

GetPackageWithDependencies get all of the dependencies for a single package as well as looking up the package itself and resolving its version, based on the indexes. Requires the existing set because the logic for resolving dependencies between competing options may depend on whether or not one already is installed. Must not modify the existing map directly.

func (*PkgResolver) GetPackagesWithDependencies

func (p *PkgResolver) GetPackagesWithDependencies(ctx context.Context, packages []string) (toInstall []*RepositoryPackage, conflicts []string, err error)

GetPackagesWithDependencies get all of the dependencies for the given packages based on the indexes. Does not filter for installed already or not.

func (*PkgResolver) ResolvePackage

func (p *PkgResolver) ResolvePackage(pkgName string, dq map[*RepositoryPackage]string) ([]*RepositoryPackage, error)

ResolvePackage given a single package name and optional version constraints, resolve to a list of packages that satisfy the constraint. The list will be sorted by version number, with the highest version first and decreasing from there. In general, the first one in the list is the best match. This function returns multiple in case you need to see all potential matches.

type ReleaseBranch

type ReleaseBranch struct {
	Arches        []string              `json:"arches"`
	GitBranch     string                `json:"git_branch"`
	Keys          map[string][]RepoKeys `json:"keys"`
	ReleaseBranch string                `json:"rel_branch"`
	Repos         []Repo                `json:"repos"`
}

func (ReleaseBranch) KeysFor

func (r ReleaseBranch) KeysFor(arch string, date time.Time) []string

KeysFor returns the keys for the given architecture and date. The date is used to check for deprecation.

type Releases

type Releases struct {
	Architectures   []string        `json:"architectures"`
	LatestStable    string          `json:"latest_stable"`
	ReleaseBranches []ReleaseBranch `json:"release_branches"`
}

func (Releases) GetReleaseBranch

func (r Releases) GetReleaseBranch(version string) *ReleaseBranch

GetReleaseBranch returns the release branch for the given version. If not found, nil is returned.

type Repo

type Repo struct {
	Name string   `json:"name"`
	EOL  DateTime `json:"eol_date"`
}

type RepoKeys

type RepoKeys struct {
	URL        string   `json:"url"`
	Deprecated DateTime `json:"deprecated_since"`
}

type Repository

type Repository struct {
	URI string
}

func NewRepositoryFromComponents

func NewRepositoryFromComponents(baseURI, release, repo, arch string) Repository

NewRepositoryFromComponents creates a new Repository with the uri constructed from the individual components

func (*Repository) IndexURI

func (r *Repository) IndexURI() string

IndexURI returns the uri of the APKINDEX for this repository

func (*Repository) IsRemote

func (r *Repository) IsRemote() bool

IsRemote returns whether the repository is considered remote and needs to be fetched over http(s)

func (*Repository) WithIndex

func (r *Repository) WithIndex(index *APKIndex) *RepositoryWithIndex

WithIndex returns a RepositoryWithIndex object with the

type RepositoryPackage

type RepositoryPackage struct {
	*Package
	// contains filtered or unexported fields
}

func NewRepositoryPackage

func NewRepositoryPackage(pkg *Package, repo *RepositoryWithIndex) *RepositoryPackage

func (*RepositoryPackage) Repository

func (rp *RepositoryPackage) Repository() *RepositoryWithIndex

func (*RepositoryPackage) URL

func (rp *RepositoryPackage) URL() string

type RepositoryWithIndex

type RepositoryWithIndex struct {
	*Repository
	// contains filtered or unexported fields
}

RepositoryWithIndex represents a repository with the index read and parsed

func (*RepositoryWithIndex) Count

func (r *RepositoryWithIndex) Count() int

Count returns the amout of packages that are available in this repository

func (*RepositoryWithIndex) Packages

func (r *RepositoryWithIndex) Packages() (pkgs []*RepositoryPackage)

Packages returns a list of RepositoryPackage in this repository

func (*RepositoryWithIndex) RepoAbbr

func (r *RepositoryWithIndex) RepoAbbr() string

RepoAbbr returns a short name of this repository consiting of the repo name and the architecture.

type WriteHeaderer

type WriteHeaderer interface {
	WriteHeader(hdr tar.Header, tfs fs.FS, pkg *Package) (bool, error)
}

Jump to

Keyboard shortcuts

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