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
- func ArchToAPK(in string) string
- func ArchiveFromIndex(apkindex *APKIndex) (archive io.Reader, err error)
- func CompareVersions(actual, required Version) int
- func IndexURL(repo, arch string) string
- func PackageToInstalled(pkg *Package) (out []string)
- type APK
- func (a *APK) AddInstalledPackage(pkg *Package, files []tar.Header) error
- func (a *APK) CalculateWorld(ctx context.Context, allpkgs []*RepositoryPackage) ([]*APKResolved, error)
- func (a *APK) FetchPackage(ctx context.Context, pkg InstallablePackage) (io.ReadCloser, error)
- func (a *APK) FixateWorld(ctx context.Context, sourceDateEpoch *time.Time) error
- func (a *APK) GetInstalled() ([]*InstalledPackage, error)
- func (a *APK) GetRepositories() (repos []string, err error)
- func (a *APK) GetRepositoryIndexes(ctx context.Context, ignoreSignatures bool) ([]NamedIndex, error)
- func (a *APK) GetWorld() ([]string, error)
- func (a *APK) InitDB(ctx context.Context, alpineVersions ...string) error
- func (a *APK) InitKeyring(ctx context.Context, keyFiles, extraKeyFiles []string) error
- func (a *APK) InstallPackages(ctx context.Context, sourceDateEpoch *time.Time, allpkgs []InstallablePackage) error
- func (a *APK) ListInitFiles() []tar.Header
- func (a *APK) ResolveAndCalculateWorld(ctx context.Context) ([]*APKResolved, error)
- func (a *APK) ResolveWorld(ctx context.Context) (toInstall []*RepositoryPackage, conflicts []string, err error)
- func (a *APK) SetClient(client *http.Client)
- func (a *APK) SetRepositories(ctx context.Context, repos []string) error
- func (a *APK) SetWorld(ctx context.Context, packages []string) error
- type APKIndex
- type APKResolved
- type ConstraintError
- type DateTime
- type DepError
- type DisqualifiedError
- type Executor
- type FileExistsError
- type IndexOption
- type InstallablePackage
- type InstalledPackage
- type NamedIndex
- type NoKeysFoundError
- type Option
- func WithArch(arch string) Option
- func WithAuth(domain, user, pass string) Option
- func WithCache(cacheDir string, offline bool) Option
- func WithExecutor(executor Executor) Option
- func WithFS(fs apkfs.FullFS) Option
- func WithIgnoreMknodErrors(ignore bool) Option
- func WithNoSignatureIndexes(noSignatureIndex ...string) Option
- func WithVersion(version string) Option
- type Package
- type PkgResolver
- func (p *PkgResolver) GetPackageWithDependencies(pkgName string, existing map[string]*RepositoryPackage, ...) (*RepositoryPackage, []*RepositoryPackage, []string, error)
- func (p *PkgResolver) GetPackagesWithDependencies(ctx context.Context, packages []string) (toInstall []*RepositoryPackage, conflicts []string, err error)
- func (p *PkgResolver) ResolvePackage(pkgName string, dq map[*RepositoryPackage]string) ([]*RepositoryPackage, error)
- type ReleaseBranch
- type Releases
- type Repo
- type RepoKeys
- type Repository
- type RepositoryPackage
- type RepositoryWithIndex
- type Version
- type WriteHeaderer
Constants ¶
const ( DefaultKeyRingPath = "/etc/apk/keys" DefaultSystemKeyRingPath = "/usr/share/apk/keys/" )
Variables ¶
This section is empty.
Functions ¶
func CompareVersions ¶
CompareVersions compares versions based on https://dev.gentoo.org/~ulm/pms/head/pms.html#x1-250003.2
func PackageToInstalled ¶
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 (*APK) AddInstalledPackage ¶
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 ¶
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 (*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 ¶
GetWorld - get list of packages that should be installed, according to /etc/apk/world
func (*APK) InitDB ¶
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 ¶
Installs the specified keys into the APK keyring inside the build context.
func (*APK) InstallPackages ¶
func (*APK) ListInitFiles ¶
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 ¶
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 ¶
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.
type APKIndex ¶
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 ¶
type ConstraintError ¶
func (*ConstraintError) Error ¶
func (e *ConstraintError) Error() string
func (*ConstraintError) Unwrap ¶
func (e *ConstraintError) Unwrap() error
type DateTime ¶
DateTime wrapper for time.Time because the date format is "YYYY-MM-DD"
func (DateTime) MarshalJSON ¶
func (*DateTime) UnmarshalJSON ¶
type DepError ¶
type DepError struct { Package *RepositoryPackage Wrapped 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 ¶
Executor provider of interface to execute commands, if used. Will be used primarily to execute scripts.
type FileExistsError ¶
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
func WithIndexAuth ¶
func WithIndexAuth(domain, user, pass string) IndexOption
type InstallablePackage ¶
InstallablePackage represents a minimal set of information needed to install a package within an Image.
type InstalledPackage ¶
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 ¶
WithArch sets the architecture to use. If not provided, will use the default runtime.GOARCH.
func WithCache ¶
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 ¶
WithExecutor executor to use. Not currently used.
func WithFS ¶
WithFS sets the filesystem to use. If not provided, will use the OS filesystem based at root /.
func WithIgnoreMknodErrors ¶
WithIgnoreMknodErrors sets whether to ignore errors when creating device nodes. Default is false.
func WithNoSignatureIndexes ¶
func WithVersion ¶
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 ¶
ParsePackage parses a .apk file and returns a Package struct
func ParsePackageIndex ¶
ParsePackageIndex parses a plain (uncompressed) APKINDEX file. It returns an ApkIndex struct
func (*Package) ChecksumString ¶
ChecksumString returns a human-readable version of the control section checksum.
func (*Package) PackageName ¶
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 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 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 Version ¶
type Version struct {
// contains filtered or unexported fields
}
func ParseVersion ¶
ParseVersion parses a version string into a Version struct.