Documentation
¶
Overview ¶
Package apkox provides tools and utilities for building and managing APKO (Alpine Package Keeper for OCI) images. APKO is a tool designed to create OCI (Open Container Initiative) images using Alpine Linux packages. This package offers a high-level interface to configure, build, and manage these images efficiently.
The builderx package includes support for various CPU architectures, configuration management, and keyring handling for package verification. It is designed to be used in a variety of build environments and supports customization through additional arguments and caching mechanisms.
Key Features: - Support for multiple CPU architectures (x86_64, aarch64, armv7, ppc64le, s390x). - Configuration management for APKO builds. - Keyring handling for package verification. - Caching mechanisms to optimize build processes. - High-level interface for building and managing APKO images.
Example usage:
import (
"github.com/Excoriate/daggerx/pkg/builderx"
)
func main() {
builder := builderx.ApkoBuilder{
configFile: "path/to/config.yaml",
outputImage: "myimage:latest",
outputTarball: "path/to/output.tar",
keyringPaths: []string{
builderx.ApkoWolfiSigninRsaKeyPath,
builderx.ApkoAlpineSigninRsaKeyPath,
},
cacheDir: "/path/to/cache",
extraArgs: []string{"--some-flag"},
}
// Use the builder to create an APKO image
err := builder.Build()
if err != nil {
fmt.Println("Error building APKO image:", err)
}
}
For more detailed information on how to use this package, refer to the documentation on Go.pkg.dev.
Index ¶
- Constants
- func GetApkoConfigOrPreset(mntPrefix, cfgFile string) (string, error)
- func GetCacheDir(mntPrefix string) string
- func GetOutputTarPath(mntPrefix string) string
- func IsKeyringFormatValid(keyrings []string, enforceHTTPS ...bool) error
- func ValidateKeyring(keyring string, enforceHTTPS bool) error
- type ApkoBuilder
- func (b *ApkoBuilder) BuildCommand() ([]string, error)
- func (b *ApkoBuilder) WithAlpineKeyring() *ApkoBuilder
- func (b *ApkoBuilder) WithAnnotations(annotations map[string]string) *ApkoBuilder
- func (b *ApkoBuilder) WithArchitecture(arch string) *ApkoBuilder
- func (b *ApkoBuilder) WithBuildArch(arch Architecture) *ApkoBuilder
- func (b *ApkoBuilder) WithBuildContext(dir string) *ApkoBuilder
- func (b *ApkoBuilder) WithBuildDate(date string) *ApkoBuilder
- func (b *ApkoBuilder) WithCacheDir(cacheDir string) *ApkoBuilder
- func (b *ApkoBuilder) WithConfigFile(configFile string) *ApkoBuilder
- func (b *ApkoBuilder) WithDebug() *ApkoBuilder
- func (b *ApkoBuilder) WithExtraArg(arg string) *ApkoBuilder
- func (b *ApkoBuilder) WithKeyRingAlpine() *ApkoBuilder
- func (b *ApkoBuilder) WithKeyRingWolfi() *ApkoBuilder
- func (b *ApkoBuilder) WithKeyring(keyringPath string) *ApkoBuilder
- func (b *ApkoBuilder) WithKeyringAppendPlaintext(keyring string) *ApkoBuilder
- func (b *ApkoBuilder) WithLockfile(path string) *ApkoBuilder
- func (b *ApkoBuilder) WithLogLevel(level string) *ApkoBuilder
- func (b *ApkoBuilder) WithLogPolicy(policies ...string) *ApkoBuilder
- func (b *ApkoBuilder) WithNoNetwork() *ApkoBuilder
- func (b *ApkoBuilder) WithOffline() *ApkoBuilder
- func (b *ApkoBuilder) WithOutputImage(outputImage string) *ApkoBuilder
- func (b *ApkoBuilder) WithOutputTarball(outputTarball string) *ApkoBuilder
- func (b *ApkoBuilder) WithPackageAppend(packages ...string) *ApkoBuilder
- func (b *ApkoBuilder) WithRepositoryAppend(repo string) *ApkoBuilder
- func (b *ApkoBuilder) WithSBOM(enable bool) *ApkoBuilder
- func (b *ApkoBuilder) WithSBOMFormats(formats ...string) *ApkoBuilder
- func (b *ApkoBuilder) WithSBOMPath(path string) *ApkoBuilder
- func (b *ApkoBuilder) WithTag(tag string) *ApkoBuilder
- func (b *ApkoBuilder) WithTimestamp(timestamp string) *ApkoBuilder
- func (b *ApkoBuilder) WithVCS(enable bool) *ApkoBuilder
- func (b *ApkoBuilder) WithWolfiKeyring() *ApkoBuilder
- func (b *ApkoBuilder) WithWorkdir(dir string) *ApkoBuilder
- type Architecture
- type KeyringInfo
- type KeyringPars
- type KeyringSkeleton
Constants ¶
const ( // ArchX8664 represents the x86_64 architecture ArchX8664 Architecture = "x86_64" // ArchAarch64 represents the aarch64 architecture ArchAarch64 Architecture = "aarch64" // ArchArmv7 represents the armv7 architecture ArchArmv7 Architecture = "armv7" // ArchPpc64le represents the ppc64le architecture ArchPpc64le Architecture = "ppc64le" // ArchS390x represents the s390x architecture ArchS390x Architecture = "s390x" // ApkoDefaultRepositoryURL is the default repository URL for APKO builds ApkoDefaultRepositoryURL = "cgr.dev/chainguard/apko" // ApkoWolfiSigninRsaKeyPath is the path to the Wolfi signing RSA public key used for package verification. ApkoWolfiSigninRsaKeyPath = "/etc/apk/keys/wolfi-signing.rsa.pub" // ApkoAlpineSigninRsaKeyPath is the path to the Alpine signing RSA public key used for package verification. ApkoAlpineSigninRsaKeyPath = "/etc/apk/keys/alpine-devel@lists.alpinelinux.org-4a6a0840.rsa.pub" )
Variables ¶
This section is empty.
Functions ¶
func GetApkoConfigOrPreset ¶
GetApkoConfigOrPreset returns the configuration file path if it is valid. It takes two string parameters: 'mntPrefix' which is the mount prefix, and 'cfgFile' which is the configuration file path. If 'mntPrefix' is empty, it defaults to fixtures.MntPrefix. If 'cfgFile' is empty, it returns an error indicating that the config file is required. If 'cfgFile' does not have an extension, it returns an error indicating that the config file must have an extension. If 'cfgFile' does not have a .yaml or .yml extension, it returns an error indicating that the config file must have a .yaml or .yml extension. It returns the configuration file path if all checks pass, otherwise it returns an error.
func GetCacheDir ¶
GetCacheDir returns the APKO cache directory path. It takes a string parameter 'mntPrefix' which is the mount prefix. It returns the full path to the cache directory.
func GetOutputTarPath ¶
GetOutputTarPath returns the APKO output tar file path. It takes a string parameter 'mntPrefix' which is the mount prefix. It returns the full path to the output tar file.
func IsKeyringFormatValid ¶
IsKeyringFormatValid validates the format of the provided keyrings. Each keyring should be in one of two valid formats: 1. "path=url" where:
- path is a relative path under "/etc/apk/keys/"
- url is a valid URL
2. "url" where:
- url is a valid URL
The function also takes an optional parameter enforceHTTPS which defaults to true. If enforceHTTPS is true, the URL must start with "https://".
Returns an error if any keyring is invalid, nil otherwise.
func ValidateKeyring ¶
ValidateKeyring validates a single keyring string. It reuses the logic from IsKeyringFormatValid in apko_validations.go.
Types ¶
type ApkoBuilder ¶
type ApkoBuilder struct {
// contains filtered or unexported fields
}
ApkoBuilder represents a builder for APKO (Alpine Package Keeper for OCI) images. It encapsulates all the configuration options and settings needed to build an APKO image.
func NewApkoBuilder ¶
func NewApkoBuilder() *ApkoBuilder
NewApkoBuilder creates a new ApkoBuilder with default settings. It initializes the ApkoBuilder with default architectures "x86_64" and "aarch64".
func (*ApkoBuilder) BuildCommand ¶
func (b *ApkoBuilder) BuildCommand() ([]string, error)
BuildCommand generates the APKO build command based on the current configuration of the ApkoBuilder. It returns a slice of strings representing the command and an error if any required fields are missing.
func (*ApkoBuilder) WithAlpineKeyring ¶
func (b *ApkoBuilder) WithAlpineKeyring() *ApkoBuilder
WithAlpineKeyring adds the Alpine keyring to the APKO build. It sets the alpineKeyring field to true. It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithAnnotations ¶
func (b *ApkoBuilder) WithAnnotations(annotations map[string]string) *ApkoBuilder
WithAnnotations adds OCI annotations to the APKO build.
func (*ApkoBuilder) WithArchitecture ¶
func (b *ApkoBuilder) WithArchitecture(arch string) *ApkoBuilder
WithArchitecture sets the build architecture for the APKO build. It takes a string parameter 'arch' which is the desired build architecture. It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithBuildArch ¶
func (b *ApkoBuilder) WithBuildArch(arch Architecture) *ApkoBuilder
WithBuildArch sets the build architecture for the APKO build. It takes an Architecture parameter 'arch' which is the desired build architecture. It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithBuildContext ¶
func (b *ApkoBuilder) WithBuildContext(dir string) *ApkoBuilder
WithBuildContext sets the build context directory
func (*ApkoBuilder) WithBuildDate ¶
func (b *ApkoBuilder) WithBuildDate(date string) *ApkoBuilder
WithBuildDate sets the build date for the APKO build.
func (*ApkoBuilder) WithCacheDir ¶
func (b *ApkoBuilder) WithCacheDir(cacheDir string) *ApkoBuilder
WithCacheDir sets the cache directory for the APKO build. It takes a string parameter 'cacheDir' which is the path to the cache directory. It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithConfigFile ¶
func (b *ApkoBuilder) WithConfigFile(configFile string) *ApkoBuilder
WithConfigFile sets the configuration file for the APKO build. It takes a string parameter 'configFile' which is the path to the configuration file. It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithDebug ¶
func (b *ApkoBuilder) WithDebug() *ApkoBuilder
WithDebug enables debug output
func (*ApkoBuilder) WithExtraArg ¶
func (b *ApkoBuilder) WithExtraArg(arg string) *ApkoBuilder
WithExtraArg adds an extra argument to the APKO build command. It takes a string parameter 'arg' which is the extra argument to be added. It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithKeyRingAlpine ¶
func (b *ApkoBuilder) WithKeyRingAlpine() *ApkoBuilder
WithKeyRingAlpine adds the Alpine keyring to the APKO build. It appends the Alpine signing key to the keyringPaths. Returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithKeyRingWolfi ¶
func (b *ApkoBuilder) WithKeyRingWolfi() *ApkoBuilder
WithKeyRingWolfi adds the Wolfi keyring to the APKO build. It appends the Wolfi signing key to the keyringPaths. Returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithKeyring ¶
func (b *ApkoBuilder) WithKeyring(keyringPath string) *ApkoBuilder
WithKeyring adds a keyring path to the APKO build. It takes a string parameter 'keyringPath' which is the path to the keyring file. It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithKeyringAppendPlaintext ¶
func (b *ApkoBuilder) WithKeyringAppendPlaintext(keyring string) *ApkoBuilder
WithKeyringAppendPlaintext appends a plaintext keyring
func (*ApkoBuilder) WithLockfile ¶
func (b *ApkoBuilder) WithLockfile(path string) *ApkoBuilder
WithLockfile sets the lockfile path for the APKO build.
func (*ApkoBuilder) WithLogLevel ¶
func (b *ApkoBuilder) WithLogLevel(level string) *ApkoBuilder
WithLogLevel sets the log level for the APKO build.
func (*ApkoBuilder) WithLogPolicy ¶
func (b *ApkoBuilder) WithLogPolicy(policies ...string) *ApkoBuilder
WithLogPolicy sets the log policy for the APKO build.
func (*ApkoBuilder) WithNoNetwork ¶
func (b *ApkoBuilder) WithNoNetwork() *ApkoBuilder
WithNoNetwork disables network access during the build
func (*ApkoBuilder) WithOffline ¶
func (b *ApkoBuilder) WithOffline() *ApkoBuilder
WithOffline enables offline mode for the APKO build.
func (*ApkoBuilder) WithOutputImage ¶
func (b *ApkoBuilder) WithOutputImage(outputImage string) *ApkoBuilder
WithOutputImage sets the output image name for the APKO build. It takes a string parameter 'outputImage' which is the name of the output image. It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithOutputTarball ¶
func (b *ApkoBuilder) WithOutputTarball(outputTarball string) *ApkoBuilder
WithOutputTarball sets the output tarball path for the APKO build. It takes a string parameter 'outputTarball' which is the path to the output tarball. It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithPackageAppend ¶
func (b *ApkoBuilder) WithPackageAppend(packages ...string) *ApkoBuilder
WithPackageAppend adds extra packages to the APKO build.
func (*ApkoBuilder) WithRepositoryAppend ¶
func (b *ApkoBuilder) WithRepositoryAppend(repo string) *ApkoBuilder
WithRepositoryAppend appends a repository to use for the build
func (*ApkoBuilder) WithSBOM ¶
func (b *ApkoBuilder) WithSBOM(enable bool) *ApkoBuilder
WithSBOM enables or disables SBOM generation.
func (*ApkoBuilder) WithSBOMFormats ¶
func (b *ApkoBuilder) WithSBOMFormats(formats ...string) *ApkoBuilder
WithSBOMFormats sets the SBOM formats for the APKO build.
func (*ApkoBuilder) WithSBOMPath ¶
func (b *ApkoBuilder) WithSBOMPath(path string) *ApkoBuilder
WithSBOMPath sets the SBOM output path for the APKO build.
func (*ApkoBuilder) WithTag ¶
func (b *ApkoBuilder) WithTag(tag string) *ApkoBuilder
WithTag adds a tag to the APKO build. If no tag is provided, it defaults to "latest". It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithTimestamp ¶
func (b *ApkoBuilder) WithTimestamp(timestamp string) *ApkoBuilder
WithTimestamp sets the timestamp for the build
func (*ApkoBuilder) WithVCS ¶
func (b *ApkoBuilder) WithVCS(enable bool) *ApkoBuilder
WithVCS enables or disables VCS detection.
func (*ApkoBuilder) WithWolfiKeyring ¶
func (b *ApkoBuilder) WithWolfiKeyring() *ApkoBuilder
WithWolfiKeyring adds the Wolfi keyring to the APKO build. It sets the wolfiKeyring field to true. It returns the updated ApkoBuilder instance.
func (*ApkoBuilder) WithWorkdir ¶
func (b *ApkoBuilder) WithWorkdir(dir string) *ApkoBuilder
WithWorkdir sets the working directory for the APKO build.
type Architecture ¶
type Architecture string
Architecture represents supported CPU architectures for APKO builds
type KeyringInfo ¶
KeyringInfo holds information about a keyring
func GetKeyringInfoForPreset ¶
func GetKeyringInfoForPreset(preset string) (KeyringInfo, error)
GetKeyringInfoForPreset returns the keyring information based on the preset. It takes a string parameter 'preset' which specifies the keyring preset ("alpine" or "wolfi"). It returns a KeyringInfo struct and an error if the preset is unsupported.
type KeyringPars ¶
type KeyringPars struct {
// Path is the file system path to the keyring file.
Path string
// URL is the web address from which the keyring can be downloaded.
URL string
}
KeyringPars holds the parameters for a keyring. It includes the path to the keyring file and the URL from which the keyring can be downloaded.
func (*KeyringPars) GetPathFromKeyring ¶
func (k *KeyringPars) GetPathFromKeyring(keyring string) (string, error)
GetPathFromKeyring extracts the path from the keyring string. The keyring string is expected to be in the format "path=url". It returns the path as a string and an error if the format is invalid.
func (*KeyringPars) GetURLFromKeyring ¶
func (k *KeyringPars) GetURLFromKeyring(keyring string, enforceHTTPS bool) (string, error)
GetURLFromKeyring extracts the URL from the keyring string. The keyring string is expected to be in the format "path=url". It returns the URL as a string and an error if the format is invalid.
type KeyringSkeleton ¶
type KeyringSkeleton struct {
// Path is the file system path to the keyring file.
// It may be empty if only a URL is provided.
Path string
// URL is the web address from which the keyring can be downloaded.
URL string
}
KeyringSkeleton represents the structure of a keyring entry.
func ParseKeyring ¶
func ParseKeyring(keyring string) (KeyringSkeleton, error)
ParseKeyring splits a keyring string into its component parts. It returns a KeyringSkeleton struct containing the path and URL. If the keyring string only contains a URL, the Path field will be empty.