images

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 23 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Binaries used
	// Debootstrap = "debootstrap"
	Mmdebstrap    = "mmdebstrap"
	QemuImg       = "qemu-img"
	VirtCustomize = "virt-customize"
	GuestFish     = "guestfish"

	Binaries = []string{
		Mmdebstrap,
		QemuImg,
		VirtCustomize,
		GuestFish,
	}

	DefaultConfFile  = "images.json"
	DefaultImageSize = "8G"
)
View Source
var (
	// DelImageIfExists: if set to true, image will be deleted at Cleanup() by the CreateImage step
	DelImageIfExists = "DelImageIfExist"
)
View Source
var ExampleImagesConf = []ImgConf{
	{
		Name: "base.img",
		Packages: []string{
			"less",
			"vim",
			"sudo",
			"openssh-server",
			"curl",
		},
		Actions: []Action{{
			Comment: "disable password for root",
			Op: &RunCommand{
				Cmd: "passwd -d root",
			},
		}},
	},
	{
		Name:   "k8s.qcow2",
		Parent: "base.img",
		Packages: []string{
			"docker.io",
		},
	},
}

Functions

func PullImage added in v0.0.14

func PullImage(ctx context.Context, conf PullConf) error

PullImage pulls an OCI image from a remote repository and decompresses it into a local directory.

Types

type Action

type Action struct {
	Comment string
	Op      ActionOp
}

func (*Action) MarshalJSON

func (a *Action) MarshalJSON() (b []byte, e error)

func (*Action) UnmarshalJSON

func (a *Action) UnmarshalJSON(b []byte) error

type ActionOp

type ActionOp interface {
	ActionOpName() string
	ToSteps(s *StepConf) ([]step.Step, error)
}

ActionOp is the interface that actions operations need to implement.

Note: If you create an instance of ActionOp, you need to add it to actionOpInstances so that JSON marshaling/unmarshaling works. Please also consider adding a test case in actions_json_test.go to ensure that all works.

type AppendLineCommand

type AppendLineCommand struct {
	File string
	Line string
}

AppendLineCommand

func (*AppendLineCommand) ActionOpName

func (c *AppendLineCommand) ActionOpName() string

func (*AppendLineCommand) ToSteps

func (c *AppendLineCommand) ToSteps(s *StepConf) ([]step.Step, error)

type BuildConf

type BuildConf struct {
	Log *logrus.Logger

	// if DryRun set, no actual images will be build. Instead, empty files will be created
	DryRun bool
	// if ForceRebuild is set, images will be build even if they exist already
	ForceRebuild bool
	// if MergeSteps is set, image build steps will be merged when possible (better performance at the cost making operations more complicated)
	MergeSteps bool
}

BuildConf configures how a set of images are build

type BuildImageResult

type BuildImageResult struct {
	// Error is not nil, if building the image failed.
	Error error

	// CachedImageUsed is set to true if a cached image was found and no
	// actual build happened.
	CachedImageUsed bool

	// CachedImageDeleted is set to an non empty string if the image file
	// was deleted. The string describes the reason.
	CachedImageDeleted string
}

BuildImageResult describes the result of building a single image

type BuilderResult

type BuilderResult struct {
	// Error is not nil if an error happened outside image builds
	Error error
	// ImageResults results of building images
	ImageResults map[string]BuildImageResult
}

BuilderResult encodes the result of building a set of images

func (*BuilderResult) Err

func (r *BuilderResult) Err() error

Err() returns a summary error or nil if no errors were encountered

type ChdirStep

type ChdirStep struct {
	*StepConf
	Dir string
	// contains filtered or unexported fields
}

func NewChdirStep

func NewChdirStep(cnf *StepConf, dir string) *ChdirStep

func (*ChdirStep) Cleanup

func (s *ChdirStep) Cleanup(ctx context.Context)

func (*ChdirStep) Do added in v0.0.13

func (s *ChdirStep) Do(ctx context.Context) (step.Result, error)

type ChmodCommand

type ChmodCommand struct {
	Permissions string
	File        string
}

ChmodCommand

func (*ChmodCommand) ActionOpName

func (c *ChmodCommand) ActionOpName() string

func (*ChmodCommand) ToSteps

func (c *ChmodCommand) ToSteps(s *StepConf) ([]step.Step, error)

type CopyFile

type CopyFile struct {
	HostPath  string
	ImagePath string
}

CopyFile copies a file from the host inside an image

type CopyInCommand

type CopyInCommand struct {
	LocalPath string
	RemoteDir string
}

CopyInCommand copies local files in the image (recursively)

func (*CopyInCommand) ActionOpName

func (c *CopyInCommand) ActionOpName() string

func (*CopyInCommand) ToSteps

func (c *CopyInCommand) ToSteps(s *StepConf) ([]step.Step, error)

type CreateImage

type CreateImage struct {
	*StepConf
}

func NewCreateImage

func NewCreateImage(cnf *StepConf) *CreateImage

func (*CreateImage) Cleanup

func (s *CreateImage) Cleanup(ctx context.Context)

func (*CreateImage) Do added in v0.0.13

func (s *CreateImage) Do(ctx context.Context) (step.Result, error)

type ExtractResult added in v0.0.14

type ExtractResult struct {
	Images []string
}

func ExtractImage added in v0.0.14

func ExtractImage(ctx context.Context, conf PullConf) (*ExtractResult, error)

type ImageForest

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

ImageForest is a set of images forming a forest (i.e., a set of trees)

func NewImageForest

func NewImageForest(conf *ImagesConf, saveConfFile bool) (*ImageForest, error)

NewImageForest creates a new image forest it will create a new image directory if it does not exist if saveConfigFileInDir is set, a serialized version of the configuration file will be saved in the image directory

func (*ImageForest) BuildAllImages

func (f *ImageForest) BuildAllImages(bldConf *BuildConf) *BuilderResult

BuildAllImages will build all images in the forest. It will start from the roots, and work its way down.

func (*ImageForest) BuildImage

func (f *ImageForest) BuildImage(bldConf *BuildConf, image string) (*BuilderResult, error)

BuildImage builds an image, with all of its dependencies

func (*ImageForest) Dependencies

func (f *ImageForest) Dependencies(image string) ([]string, error)

Dependencies returns the dependencies of an image, i.e., what images need to be build before it

func (*ImageForest) ImageFilename

func (f *ImageForest) ImageFilename(image string) (string, error)

ImageFilename returns the filename of an image

func (*ImageForest) IsLeafImage

func (f *ImageForest) IsLeafImage(i string) bool

func (*ImageForest) IsRootImage

func (f *ImageForest) IsRootImage(image string) (bool, error)

func (*ImageForest) LeafImages

func (f *ImageForest) LeafImages() []string

func (*ImageForest) RootImages

func (f *ImageForest) RootImages() []string

RootImages are the images which do not have dependencies (i.e., no parents)

type ImagesConf

type ImagesConf struct {
	// ImageDir is the directory for the images
	Dir string
	// Images is the configuration for all images
	Images []ImgConf
}

ImagesConf is the configuration of a set of images

type ImgConf

type ImgConf struct {
	// Name of the image
	Name string `json:"name"`
	// Parent is the name parent image (or "" if image does not have a parent)
	Parent string `json:"parent,omitempty"`
	// ImageSize is the size of the image (defaults to images.DefaultImageSize)
	ImageSize string `json:"image_size,omitempty"`
	// Bootable indicates if the image should be bootable, i.e. contain a kernel
	// and a bootloader.
	Bootable *bool `json:"bootable,omitempty"`
	// Packages is the list of packages contained in the image
	Packages []string `json:"packages"`
	// Actions is a list of additional actions for building the image.
	// Order will be maintained during execution.
	Actions []Action `json:"actions,omitempty"`
}

ImgConf is the configuration of an image

type InstallKernelCommand

type InstallKernelCommand struct {
	KernelInstallDir string
}

InstallKernelCommand

func (*InstallKernelCommand) ActionOpName

func (c *InstallKernelCommand) ActionOpName() string

func (*InstallKernelCommand) ToSteps

func (c *InstallKernelCommand) ToSteps(s *StepConf) ([]step.Step, error)

type LinkCommand

type LinkCommand struct {
	Target string
	Link   string
}

LinkCommand

func (*LinkCommand) ActionOpName

func (c *LinkCommand) ActionOpName() string

func (*LinkCommand) ToSteps

func (c *LinkCommand) ToSteps(s *StepConf) ([]step.Step, error)

type MkdirCommand

type MkdirCommand struct {
	Dir string
}

MkdirCommand creates a directory

func (*MkdirCommand) ActionOpName

func (c *MkdirCommand) ActionOpName() string

func (*MkdirCommand) ToSteps

func (c *MkdirCommand) ToSteps(s *StepConf) ([]step.Step, error)

type PullConf added in v0.0.14

type PullConf struct {
	Image     string
	TargetDir string
	Cache     bool
}

type RunCommand

type RunCommand struct {
	Cmd string
}

RunCommand runs a script in a path specified by a string

func (*RunCommand) ActionOpName

func (rc *RunCommand) ActionOpName() string

func (*RunCommand) ToSteps

func (rc *RunCommand) ToSteps(s *StepConf) ([]step.Step, error)

type SetHostnameCommand

type SetHostnameCommand struct {
	Hostname string
}

SetHostnameCommand sets the hostname

func (*SetHostnameCommand) ActionOpName

func (c *SetHostnameCommand) ActionOpName() string

func (*SetHostnameCommand) ToSteps

func (c *SetHostnameCommand) ToSteps(s *StepConf) ([]step.Step, error)

type StepConf

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

StepConf is common step configuration

type UploadCommand

type UploadCommand struct {
	File string
	Dest string
}

UploadCommand copies a file to the vim

func (*UploadCommand) ActionOpName

func (c *UploadCommand) ActionOpName() string

func (*UploadCommand) ToSteps

func (c *UploadCommand) ToSteps(s *StepConf) ([]step.Step, error)

type VirtCustomizeAction

type VirtCustomizeAction struct {
	OpName string
	// contains filtered or unexported fields
}

type VirtCustomizeStep

type VirtCustomizeStep struct {
	*StepConf
	Args []string
}

VirtCustomizeStep is a step implemented a set of arguments in virt-customize

NB: we can maybe merge multiple VirtCustomizeStep in a single virt-customize invocation. The idea here would be that virt-customize performs the actions in its arguments sequentially.

NB: we can probably do the same with guestfish as well

func (*VirtCustomizeStep) Cleanup

func (s *VirtCustomizeStep) Cleanup(ctx context.Context)

func (*VirtCustomizeStep) Do added in v0.0.13

func (*VirtCustomizeStep) Merge

func (s *VirtCustomizeStep) Merge(step step.Step) error

Jump to

Keyboard shortcuts

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