shared

package
v0.0.0-...-742b54a Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActiveChroots = make(map[string]func() error)

ActiveChroots is a map of all active chroots and their exit functions.

Functions

func AppendToFile

func AppendToFile(path string, content string) error

AppendToFile opens an existing file and appends the given content to it.

func ApplyFilter

func ApplyFilter(filter Filter, release string, architecture string, variant string, targetType DefinitionFilterType, acceptedImageTargets ImageTarget) bool

ApplyFilter returns true if the filter matches.

func Copy

func Copy(src, dest string) error

Copy copies a file.

func FileHash

func FileHash(hash hash.Hash, paths ...string) (string, error)

FileHash calculates the combined hash for the given files using the provided hash function.

func GZipFile

func GZipFile(srcPath string, dstPath string) error

GZipFile compresses the file on the source path and writes the compressed content to the destination path. If destination path is empty, the source file name is used with .gz suffix.

func GetArch

func GetArch(distro, arch string) (string, error)

GetArch returns the correct architecture name used by the specified distribution.

func GetExpiryDate

func GetExpiryDate(creationDate time.Time, format string) time.Time

GetExpiryDate returns an expiry date based on the creationDate and format.

func GetLogger

func GetLogger(debug bool) (*logrus.Logger, error)

GetLogger returns a new logger.

func HasSuffix

func HasSuffix(key string, suffixes ...string) bool

HasSuffix returns true if the key matches any of the given suffixes.

func MapKeys

func MapKeys[K comparable, V any](m map[K]V) []K

MapKeys returns map keys as a list.

func Pack

func Pack(ctx context.Context, filename, compression, path string, args ...string) (string, error)

Pack creates an uncompressed tarball.

func PackUpdate

func PackUpdate(ctx context.Context, filename, compression, path string, args ...string) (string, error)

PackUpdate updates an existing tarball.

func ParseCompression

func ParseCompression(compression string) (string, *int, error)

ParseCompression extracts the compression method and level (if any) from the compression flag.

func ParseSquashfsCompression

func ParseSquashfsCompression(compression string) (string, *int, error)

ParseSquashfsCompression extracts the compression method and level (if any) from the compression flag for use with mksquashfs.

func ReadGZipFile

func ReadGZipFile(path string) ([]byte, error)

ReadGZipFile opens the GZ file on the given path and decompresses it decode into an array of bytes.

func ReadJSONFile

func ReadJSONFile[T any](path string, obj *T) (*T, error)

ReadJSONFile opens the JSON file on the given path and tries to decode it into the given structure.

func ReadYAMLFile

func ReadYAMLFile[T any](path string, obj *T) (*T, error)

ReadYAMLFile opens the YAML file on the given path and tries to decode it into the given structure.

func RenderTemplate

func RenderTemplate(template string, iface interface{}) (string, error)

RenderTemplate renders a pongo2 template.

func Retry

func Retry(f func() error, attempts uint) error

Retry retries a function up to <attempts> times. This is especially useful for networking.

func RsyncLocal

func RsyncLocal(ctx context.Context, src string, dest string) error

RsyncLocal copies src to dest using rsync.

func RunCommand

func RunCommand(ctx context.Context, stdin io.Reader, stdout io.Writer, name string, arg ...string) error

RunCommand runs a command. Stdout is written to the given io.Writer. If nil, it's written to the real stdout. Stderr is always written to the real stderr.

func RunScript

func RunScript(ctx context.Context, content string) error

RunScript runs a script hereby setting the SHELL and PATH env variables, and redirecting the process's stdout and stderr to the real stdout and stderr respectively.

func SetupChroot

func SetupChroot(rootfs string, definition Definition, m []ChrootMount) (func() error, error)

SetupChroot sets up mount and files, a reverter and then chroots for you.

func Unpack

func Unpack(file string, path string) error

Unpack unpacks a tarball.

func WriteJSONFile

func WriteJSONFile(path string, obj any) error

WriteJSONFile encodes the given structure into JSON format and writes it to the file on a given path.

Types

type ChrootMount

type ChrootMount struct {
	Source string
	Target string
	FSType string
	Flags  uintptr
	Data   string
	IsDir  bool
}

ChrootMount defines mount args.

type CustomManagerCmd

type CustomManagerCmd struct {
	Command string   `yaml:"cmd"`
	Flags   []string `yaml:"flags,omitempty"`
}

CustomManagerCmd represents a command for a custom manager.

type Definition

type Definition struct {
	Image        DefinitionImage        `yaml:"image"`
	Source       DefinitionSource       `yaml:"source"`
	Targets      DefinitionTarget       `yaml:"targets,omitempty"`
	Files        []DefinitionFile       `yaml:"files,omitempty"`
	Packages     DefinitionPackages     `yaml:"packages,omitempty"`
	Actions      []DefinitionAction     `yaml:"actions,omitempty"`
	Mappings     DefinitionMappings     `yaml:"mappings,omitempty"`
	Environment  DefinitionEnv          `yaml:"environment,omitempty"`
	Simplestream DefinitionSimplestream `yaml:"simplestream,omitempty"`
}

A Definition a definition.

func (*Definition) GetEarlyPackages

func (d *Definition) GetEarlyPackages(action string) []string

GetEarlyPackages returns a list of packages which are to be installed or removed earlier than the actual package handling Also removes them from the package set so they aren't attempted to be re-installed again as normal packages.

func (*Definition) GetRunnableActions

func (d *Definition) GetRunnableActions(trigger string, imageTarget ImageTarget) []DefinitionAction

GetRunnableActions returns a list of actions depending on the trigger and releases.

func (*Definition) SetDefaults

func (d *Definition) SetDefaults()

SetDefaults sets some default values.

func (*Definition) SetValue

func (d *Definition) SetValue(key string, value string) error

SetValue writes the provided value to a field represented by the yaml tag 'key'.

func (*Definition) Validate

func (d *Definition) Validate() error

Validate validates the Definition.

type DefinitionAction

type DefinitionAction struct {
	DefinitionFilter `yaml:",inline"`
	Trigger          string `yaml:"trigger"`
	Action           string `yaml:"action"`
	Pongo            bool   `yaml:"pongo,omitempty"`
}

A DefinitionAction specifies a custom action (script) which is to be run after a certain action.

type DefinitionEnv

type DefinitionEnv struct {
	ClearDefaults bool                `yaml:"clear_defaults,omitempty"`
	EnvVariables  []DefinitionEnvVars `yaml:"variables,omitempty"`
}

DefinitionEnv represents the config part of the environment section.

type DefinitionEnvVars

type DefinitionEnvVars struct {
	DefinitionFilter `yaml:",inline"`
	Key              string `yaml:"key"`
	Value            string `yaml:"value"`
}

DefinitionEnvVars defines custom environment variables.

type DefinitionFile

type DefinitionFile struct {
	DefinitionFilter `yaml:",inline"`
	Generator        string                 `yaml:"generator"`
	Path             string                 `yaml:"path,omitempty"`
	Content          string                 `yaml:"content,omitempty"`
	Name             string                 `yaml:"name,omitempty"`
	Template         DefinitionFileTemplate `yaml:"template,omitempty"`
	Templated        bool                   `yaml:"templated,omitempty"`
	Mode             string                 `yaml:"mode,omitempty"`
	GID              string                 `yaml:"gid,omitempty"`
	UID              string                 `yaml:"uid,omitempty"`
	Pongo            bool                   `yaml:"pongo,omitempty"`
	Source           string                 `yaml:"source,omitempty"`
}

A DefinitionFile represents a file which is to be created inside to chroot.

type DefinitionFileTemplate

type DefinitionFileTemplate struct {
	Properties map[string]string `yaml:"properties,omitempty"`
	When       []string          `yaml:"when,omitempty"`
}

A DefinitionFileTemplate represents the settings used by generators.

type DefinitionFilter

type DefinitionFilter struct {
	Releases      []string               `yaml:"releases,omitempty"`
	Architectures []string               `yaml:"architectures,omitempty"`
	Variants      []string               `yaml:"variants,omitempty"`
	Types         []DefinitionFilterType `yaml:"types,omitempty"`
}

A DefinitionFilter defines filters for various actions.

func (*DefinitionFilter) GetArchitectures

func (d *DefinitionFilter) GetArchitectures() []string

GetArchitectures returns a list of architectures.

func (*DefinitionFilter) GetReleases

func (d *DefinitionFilter) GetReleases() []string

GetReleases returns a list of releases.

func (*DefinitionFilter) GetTypes

func (d *DefinitionFilter) GetTypes() []DefinitionFilterType

GetTypes returns a list of types.

func (*DefinitionFilter) GetVariants

func (d *DefinitionFilter) GetVariants() []string

GetVariants returns a list of variants.

type DefinitionFilterType

type DefinitionFilterType string

DefinitionFilterType represents the filter type.

const (
	// DefinitionFilterTypeVM is used for VMs.
	DefinitionFilterTypeVM DefinitionFilterType = "vm"

	// DefinitionFilterTypeContainer is used for containers.
	DefinitionFilterTypeContainer DefinitionFilterType = "container"
)

func (*DefinitionFilterType) UnmarshalYAML

func (d *DefinitionFilterType) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML validates the filter type.

type DefinitionImage

type DefinitionImage struct {
	Description  string `yaml:"description"`
	Distribution string `yaml:"distribution"`
	Release      string `yaml:"release,omitempty"`
	Architecture string `yaml:"architecture,omitempty"`
	Expiry       string `yaml:"expiry,omitempty"`
	Variant      string `yaml:"variant,omitempty"`
	Name         string `yaml:"name,omitempty"`
	Serial       string `yaml:"serial,omitempty"`

	// Internal fields (YAML input ignored)
	ArchitectureMapped      string `yaml:"architecture_mapped,omitempty"`
	ArchitectureKernel      string `yaml:"architecture_kernel,omitempty"`
	ArchitecturePersonality string `yaml:"architecture_personality,omitempty"`
}

A DefinitionImage represents the image.

type DefinitionMappings

type DefinitionMappings struct {
	Architectures   map[string]string `yaml:"architectures,omitempty"`
	ArchitectureMap string            `yaml:"architecture_map,omitempty"`
}

DefinitionMappings defines custom mappings.

type DefinitionPackages

type DefinitionPackages struct {
	Manager       string                           `yaml:"manager,omitempty"`
	CustomManager *DefinitionPackagesCustomManager `yaml:"custom_manager,omitempty"`
	Update        bool                             `yaml:"update,omitempty"`
	Cleanup       bool                             `yaml:"cleanup,omitempty"`
	Sets          []DefinitionPackagesSet          `yaml:"sets,omitempty"`
	Repositories  []DefinitionPackagesRepository   `yaml:"repositories,omitempty"`
}

A DefinitionPackages represents a package handler.

type DefinitionPackagesCustomManager

type DefinitionPackagesCustomManager struct {
	Clean   CustomManagerCmd `yaml:"clean"`
	Install CustomManagerCmd `yaml:"install"`
	Remove  CustomManagerCmd `yaml:"remove"`
	Refresh CustomManagerCmd `yaml:"refresh"`
	Update  CustomManagerCmd `yaml:"update"`
	Flags   []string         `yaml:"flags,omitempty"`
}

DefinitionPackagesCustomManager represents a custom package manager.

type DefinitionPackagesRepository

type DefinitionPackagesRepository struct {
	DefinitionFilter `yaml:",inline"`
	Name             string `yaml:"name"`           // Name of the repository
	URL              string `yaml:"url"`            // URL (may differ based on manager)
	Type             string `yaml:"type,omitempty"` // For distros that have more than one repository manager
	Key              string `yaml:"key,omitempty"`  // GPG armored keyring
}

A DefinitionPackagesRepository contains data of a specific repository.

type DefinitionPackagesSet

type DefinitionPackagesSet struct {
	DefinitionFilter `yaml:",inline"`
	Packages         []string `yaml:"packages"`
	Action           string   `yaml:"action"`
	Early            bool     `yaml:"early,omitempty"`
	Flags            []string `yaml:"flags,omitempty"`
}

A DefinitionPackagesSet is a set of packages which are to be installed or removed.

type DefinitionSimplestream

type DefinitionSimplestream struct {
	// Pretty distro name.
	DistroName string `yaml:"distro_name,omitempty"`

	// Map of release aliases. Key represents the release name and value
	// is a comma delimited string of additional release aliases.
	ReleaseAliases map[string]string `yaml:"release_aliases,omitempty"`

	// List of the image requirements.
	Requirements []DefinitionSimplestreamRequirements `yaml:"requirements,omitempty"`
}

DefinitionSimplestream contains additional information about the image. It is parsed by the simplestream-maintainer when building a product catalog.

type DefinitionSimplestreamRequirements

type DefinitionSimplestreamRequirements struct {
	DefinitionFilter `yaml:",inline"`

	// Map of the image requirements.
	Requirements map[string]string `yaml:"requirements,omitempty"`
}

DefinitionSimplestreamRequirements contains a map of image requirements and filters to selectively apply the requirements.

type DefinitionSource

type DefinitionSource struct {
	Downloader       string   `yaml:"downloader"`
	URL              string   `yaml:"url,omitempty"`
	Keys             []string `yaml:"keys,omitempty"`
	Keyserver        string   `yaml:"keyserver,omitempty"`
	Variant          string   `yaml:"variant,omitempty"`
	Suite            string   `yaml:"suite,omitempty"`
	SameAs           string   `yaml:"same_as,omitempty"`
	SkipVerification bool     `yaml:"skip_verification,omitempty"`
	Components       []string `yaml:"components,omitempty"`
}

A DefinitionSource specifies the download type and location.

type DefinitionTarget

type DefinitionTarget struct {
	LXC  DefinitionTargetLXC  `yaml:"lxc,omitempty"`
	LXD  DefinitionTargetLXD  `yaml:"lxd,omitempty"`
	Type DefinitionFilterType // This field is internal only and used only for simplicity.
}

A DefinitionTarget specifies target dependent files.

type DefinitionTargetLXC

type DefinitionTargetLXC struct {
	CreateMessage string                      `yaml:"create_message,omitempty"`
	Config        []DefinitionTargetLXCConfig `yaml:"config,omitempty"`
}

A DefinitionTargetLXC represents LXC specific files as part of the metadata.

type DefinitionTargetLXCConfig

type DefinitionTargetLXCConfig struct {
	DefinitionFilter `yaml:",inline"`
	Type             string `yaml:"type"`
	Before           uint   `yaml:"before,omitempty"`
	After            uint   `yaml:"after,omitempty"`
	Content          string `yaml:"content"`
}

A DefinitionTargetLXCConfig represents the config part of the metadata.

type DefinitionTargetLXD

type DefinitionTargetLXD struct {
	VM DefinitionTargetLXDVM `yaml:"vm,omitempty"`
}

DefinitionTargetLXD represents LXD specific options.

type DefinitionTargetLXDVM

type DefinitionTargetLXDVM struct {
	Size       uint64 `yaml:"size,omitempty"`
	Filesystem string `yaml:"filesystem,omitempty"`
}

DefinitionTargetLXDVM represents LXD VM specific options.

type EnvVariable

type EnvVariable struct {
	Value string
	Set   bool
}

EnvVariable represents a environment variable.

type Environment

type Environment map[string]EnvVariable

Environment represents a set of environment variables.

func SetEnvVariables

func SetEnvVariables(env Environment) Environment

SetEnvVariables sets the provided environment variables and returns the old ones.

type Filter

type Filter interface {
	GetReleases() []string
	GetArchitectures() []string
	GetVariants() []string
	GetTypes() []DefinitionFilterType
}

Filter represents a filter.

type ImageTarget

type ImageTarget int

ImageTarget represents the image target.

const (
	// ImageTargetAll is used for all targets.
	ImageTargetAll ImageTarget = 1

	// ImageTargetContainer is used for container targets.
	ImageTargetContainer ImageTarget = 1 << 1

	// ImageTargetVM is used for VM targets.
	ImageTargetVM ImageTarget = 1 << 2

	// ImageTargetUndefined is used when no type has been specified.
	ImageTargetUndefined ImageTarget = 1 << 3
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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