shared

package
v0.0.0-...-04abbcf Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: Apache-2.0 Imports: 21 Imported by: 15

Documentation

Index

Constants

View Source
const (
	ContextKeyEnviron = ContextKey("environ")
	ContextKeyStderr  = ContextKey("stderr")
	EnvRootUUID       = "DISTROBUILDER_ROOT_UUID"
)

Variables

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

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

Functions

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 CaseInsensitive

func CaseInsensitive(s string) (pattern string)

CaseInsensitive returns case insensive pattern used by filepath.Glob or filepath.Match.

func Copy

func Copy(src, dest string) error

Copy copies a file.

func FindAllMatches

func FindAllMatches(dir string, elem ...string) (matches []string, err error)

FindAllMatches find all the matched files case insensitive.

func FindFirstMatch

func FindFirstMatch(dir string, elem ...string) (found string, err error)

FindFirstMatch find the first matched file case insensitive.

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 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 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.

Types

type ChrootMount

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

ChrootMount defines mount args.

type ContextKey

type ContextKey string

ContextKey type.

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"`
}

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 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"`
	Incus DefinitionTargetIncus `yaml:"incus,omitempty"`
	Type  DefinitionFilterType  // This field is internal only and used only for simplicity.
}

A DefinitionTarget specifies target dependent files.

type DefinitionTargetIncus

type DefinitionTargetIncus struct {
	VM DefinitionTargetIncusVM `yaml:"vm,omitempty"`
}

DefinitionTargetIncus represents Incus specific options.

type DefinitionTargetIncusVM

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

DefinitionTargetIncusVM represents Incus VM specific options.

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 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
)

type WriteFunc

type WriteFunc func([]byte) (int, error)

WriteFunc type.

func (WriteFunc) Write

func (w WriteFunc) Write(b []byte) (int, error)

Write implements io.Writer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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