chroot

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2021 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package chroot is able to create an Outscale OMI without requiring the launch of a new instance for every build. It does this by attaching and mounting the root volume of another OMI and chrooting into that directory. It then creates an OMI from that attached drive.

Index

Constants

View Source
const BuilderId = "oapi.outscale.chroot"

The unique ID for this builder

View Source
const LOCK_EX = 2

See: http://linux.die.net/include/sys/file.h

View Source
const LOCK_NB = 4
View Source
const LOCK_UN = 8

Variables

This section is empty.

Functions

func AvailableDevice

func AvailableDevice() (string, error)

AvailableDevice finds an available device and returns it. Note that you should externally hold a flock or something in order to guarantee that this device is available across processes.

func RunLocalCommands

func RunLocalCommands(commands []string, wrappedCommand CommandWrapper, ictx interpolate.Context, ui packersdk.Ui) error

func ShellCommand

func ShellCommand(command string) *exec.Cmd

ShellCommand takes a command string and returns an *exec.Cmd to execute it within the context of a shell (/bin/sh).

Types

type Builder

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

func (*Builder) ConfigSpec added in v1.5.0

func (b *Builder) ConfigSpec() hcldec.ObjectSpec

func (*Builder) Prepare

func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error)

func (*Builder) Run

type Cleanup

type Cleanup interface {
	CleanupFunc(multistep.StateBag) error
}

Cleanup is an interface that some steps implement for early cleanup.

type CommandWrapper

type CommandWrapper func(string) (string, error)

CommandWrapper is a type that given a command, will possibly modify that command in-flight. This might return an error.

type Communicator

type Communicator struct {
	Chroot     string
	CmdWrapper CommandWrapper
}

Communicator is a special communicator that works by executing commands locally but within a chroot.

func (*Communicator) Download

func (c *Communicator) Download(src string, w io.Writer) error

func (*Communicator) DownloadDir

func (c *Communicator) DownloadDir(src string, dst string, exclude []string) error

func (*Communicator) Start

func (c *Communicator) Start(ctx context.Context, cmd *packersdk.RemoteCmd) error

func (*Communicator) Upload

func (c *Communicator) Upload(dst string, r io.Reader, fi *os.FileInfo) error

func (*Communicator) UploadDir

func (c *Communicator) UploadDir(dst string, src string, exclude []string) error

type Config

type Config struct {
	common.PackerConfig       `mapstructure:",squash"`
	osccommon.OMIBlockDevices `mapstructure:",squash"`
	osccommon.OMIConfig       `mapstructure:",squash"`
	osccommon.AccessConfig    `mapstructure:",squash"`

	ChrootMounts      [][]string                 `mapstructure:"chroot_mounts"`
	CommandWrapper    string                     `mapstructure:"command_wrapper"`
	CopyFiles         []string                   `mapstructure:"copy_files"`
	DevicePath        string                     `mapstructure:"device_path"`
	NVMEDevicePath    string                     `mapstructure:"nvme_device_path"`
	FromScratch       bool                       `mapstructure:"from_scratch"`
	MountOptions      []string                   `mapstructure:"mount_options"`
	MountPartition    string                     `mapstructure:"mount_partition"`
	MountPath         string                     `mapstructure:"mount_path"`
	PostMountCommands []string                   `mapstructure:"post_mount_commands"`
	PreMountCommands  []string                   `mapstructure:"pre_mount_commands"`
	RootDeviceName    string                     `mapstructure:"root_device_name"`
	RootVolumeSize    int64                      `mapstructure:"root_volume_size"`
	RootVolumeType    string                     `mapstructure:"root_volume_type"`
	SourceOMI         string                     `mapstructure:"source_omi"`
	SourceOMIFilter   osccommon.OmiFilterOptions `mapstructure:"source_omi_filter"`
	RootVolumeTags    osccommon.TagMap           `mapstructure:"root_volume_tags"`
	// contains filtered or unexported fields
}

Config is the configuration that is chained through the steps and settable from the template.

func (*Config) FlatMapstructure added in v1.4.5

func (*Config) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec }

FlatMapstructure returns a new FlatConfig. FlatConfig is an auto-generated flat version of Config. Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.

type FlatConfig added in v1.4.5

type FlatConfig struct {
	PackerBuildName         *string                      `mapstructure:"packer_build_name" cty:"packer_build_name" hcl:"packer_build_name"`
	PackerBuilderType       *string                      `mapstructure:"packer_builder_type" cty:"packer_builder_type" hcl:"packer_builder_type"`
	PackerCoreVersion       *string                      `mapstructure:"packer_core_version" cty:"packer_core_version" hcl:"packer_core_version"`
	PackerDebug             *bool                        `mapstructure:"packer_debug" cty:"packer_debug" hcl:"packer_debug"`
	PackerForce             *bool                        `mapstructure:"packer_force" cty:"packer_force" hcl:"packer_force"`
	PackerOnError           *string                      `mapstructure:"packer_on_error" cty:"packer_on_error" hcl:"packer_on_error"`
	PackerUserVars          map[string]string            `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"`
	PackerSensitiveVars     []string                     `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"`
	OMIMappings             []common.FlatBlockDevice     `mapstructure:"omi_block_device_mappings" cty:"omi_block_device_mappings" hcl:"omi_block_device_mappings"`
	OMIName                 *string                      `mapstructure:"omi_name" cty:"omi_name" hcl:"omi_name"`
	OMIDescription          *string                      `mapstructure:"omi_description" cty:"omi_description" hcl:"omi_description"`
	OMIVirtType             *string                      `mapstructure:"omi_virtualization_type" cty:"omi_virtualization_type" hcl:"omi_virtualization_type"`
	OMIAccountIDs           []string                     `mapstructure:"omi_account_ids" cty:"omi_account_ids" hcl:"omi_account_ids"`
	OMIGroups               []string                     `mapstructure:"omi_groups" cty:"omi_groups" hcl:"omi_groups"`
	OMIProductCodes         []string                     `mapstructure:"omi_product_codes" cty:"omi_product_codes" hcl:"omi_product_codes"`
	OMIRegions              []string                     `mapstructure:"omi_regions" cty:"omi_regions" hcl:"omi_regions"`
	OMISkipRegionValidation *bool                        `mapstructure:"skip_region_validation" cty:"skip_region_validation" hcl:"skip_region_validation"`
	OMITags                 common.TagMap                `mapstructure:"tags" cty:"tags" hcl:"tags"`
	OMIForceDeregister      *bool                        `mapstructure:"force_deregister" cty:"force_deregister" hcl:"force_deregister"`
	OMIForceDeleteSnapshot  *bool                        `mapstructure:"force_delete_snapshot" cty:"force_delete_snapshot" hcl:"force_delete_snapshot"`
	SnapshotTags            common.TagMap                `mapstructure:"snapshot_tags" cty:"snapshot_tags" hcl:"snapshot_tags"`
	SnapshotAccountIDs      []string                     `mapstructure:"snapshot_account_ids" cty:"snapshot_account_ids" hcl:"snapshot_account_ids"`
	SnapshotGroups          []string                     `mapstructure:"snapshot_groups" cty:"snapshot_groups" hcl:"snapshot_groups"`
	AccessKey               *string                      `mapstructure:"access_key" cty:"access_key" hcl:"access_key"`
	CustomEndpointOAPI      *string                      `mapstructure:"custom_endpoint_oapi" cty:"custom_endpoint_oapi" hcl:"custom_endpoint_oapi"`
	InsecureSkipTLSVerify   *bool                        `mapstructure:"insecure_skip_tls_verify" cty:"insecure_skip_tls_verify" hcl:"insecure_skip_tls_verify"`
	MFACode                 *string                      `mapstructure:"mfa_code" cty:"mfa_code" hcl:"mfa_code"`
	ProfileName             *string                      `mapstructure:"profile" cty:"profile" hcl:"profile"`
	RawRegion               *string                      `mapstructure:"region" cty:"region" hcl:"region"`
	SecretKey               *string                      `mapstructure:"secret_key" cty:"secret_key" hcl:"secret_key"`
	SkipMetadataApiCheck    *bool                        `mapstructure:"skip_metadata_api_check" cty:"skip_metadata_api_check" hcl:"skip_metadata_api_check"`
	Token                   *string                      `mapstructure:"token" cty:"token" hcl:"token"`
	X509certPath            *string                      `mapstructure:"x509_cert_path" cty:"x509_cert_path" hcl:"x509_cert_path"`
	X509keyPath             *string                      `mapstructure:"x509_key_path" cty:"x509_key_path" hcl:"x509_key_path"`
	ChrootMounts            [][]string                   `mapstructure:"chroot_mounts" cty:"chroot_mounts" hcl:"chroot_mounts"`
	CommandWrapper          *string                      `mapstructure:"command_wrapper" cty:"command_wrapper" hcl:"command_wrapper"`
	CopyFiles               []string                     `mapstructure:"copy_files" cty:"copy_files" hcl:"copy_files"`
	DevicePath              *string                      `mapstructure:"device_path" cty:"device_path" hcl:"device_path"`
	NVMEDevicePath          *string                      `mapstructure:"nvme_device_path" cty:"nvme_device_path" hcl:"nvme_device_path"`
	FromScratch             *bool                        `mapstructure:"from_scratch" cty:"from_scratch" hcl:"from_scratch"`
	MountOptions            []string                     `mapstructure:"mount_options" cty:"mount_options" hcl:"mount_options"`
	MountPartition          *string                      `mapstructure:"mount_partition" cty:"mount_partition" hcl:"mount_partition"`
	MountPath               *string                      `mapstructure:"mount_path" cty:"mount_path" hcl:"mount_path"`
	PostMountCommands       []string                     `mapstructure:"post_mount_commands" cty:"post_mount_commands" hcl:"post_mount_commands"`
	PreMountCommands        []string                     `mapstructure:"pre_mount_commands" cty:"pre_mount_commands" hcl:"pre_mount_commands"`
	RootDeviceName          *string                      `mapstructure:"root_device_name" cty:"root_device_name" hcl:"root_device_name"`
	RootVolumeSize          *int64                       `mapstructure:"root_volume_size" cty:"root_volume_size" hcl:"root_volume_size"`
	RootVolumeType          *string                      `mapstructure:"root_volume_type" cty:"root_volume_type" hcl:"root_volume_type"`
	SourceOMI               *string                      `mapstructure:"source_omi" cty:"source_omi" hcl:"source_omi"`
	SourceOMIFilter         *common.FlatOmiFilterOptions `mapstructure:"source_omi_filter" cty:"source_omi_filter" hcl:"source_omi_filter"`
	RootVolumeTags          common.TagMap                `mapstructure:"root_volume_tags" cty:"root_volume_tags" hcl:"root_volume_tags"`
}

FlatConfig is an auto-generated flat version of Config. Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.

func (*FlatConfig) HCL2Spec added in v1.4.5

func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec

HCL2Spec returns the hcl spec of a Config. This spec is used by HCL to read the fields of Config. The decoded values from this spec will then be applied to a FlatConfig.

type StepCheckRootDevice

type StepCheckRootDevice struct{}

StepCheckRootDevice makes sure the root device on the OMI is BSU-backed.

func (*StepCheckRootDevice) Cleanup

func (*StepCheckRootDevice) Run

type StepChrootProvision

type StepChrootProvision struct {
}

StepChrootProvision provisions the instance within a chroot.

func (*StepChrootProvision) Cleanup

func (s *StepChrootProvision) Cleanup(state multistep.StateBag)

func (*StepChrootProvision) Run

type StepCopyFiles

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

StepCopyFiles copies some files from the host into the chroot environment.

Produces:

copy_files_cleanup CleanupFunc - A function to clean up the copied files
early.

func (*StepCopyFiles) Cleanup

func (s *StepCopyFiles) Cleanup(state multistep.StateBag)

func (*StepCopyFiles) CleanupFunc

func (s *StepCopyFiles) CleanupFunc(state multistep.StateBag) error

func (*StepCopyFiles) Run

type StepCreateOMI

type StepCreateOMI struct {
	RootVolumeSize int64
	RawRegion      string
}

StepCreateOMI creates the OMI.

func (*StepCreateOMI) Cleanup

func (s *StepCreateOMI) Cleanup(state multistep.StateBag)

func (*StepCreateOMI) Run

type StepCreateVolume

type StepCreateVolume struct {
	RootVolumeSize int64
	RootVolumeType string
	RootVolumeTags osccommon.TagMap
	RawRegion      string
	Ctx            interpolate.Context
	// contains filtered or unexported fields
}

StepCreateVolume creates a new volume from the snapshot of the root device of the OMI.

Produces:

volume_id string - The ID of the created volume

func (*StepCreateVolume) Cleanup

func (s *StepCreateVolume) Cleanup(state multistep.StateBag)

func (*StepCreateVolume) Run

type StepEarlyCleanup

type StepEarlyCleanup struct{}

StepEarlyCleanup performs some of the cleanup steps early in order to prepare for snapshotting and creating an AMI.

func (*StepEarlyCleanup) Cleanup

func (s *StepEarlyCleanup) Cleanup(state multistep.StateBag)

func (*StepEarlyCleanup) Run

type StepEarlyUnflock

type StepEarlyUnflock struct{}

StepEarlyUnflock unlocks the flock.

func (*StepEarlyUnflock) Cleanup

func (s *StepEarlyUnflock) Cleanup(state multistep.StateBag)

func (*StepEarlyUnflock) Run

type StepFlock

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

StepFlock provisions the instance within a chroot.

Produces:

flock_cleanup Cleanup - To perform early cleanup

func (*StepFlock) Cleanup

func (s *StepFlock) Cleanup(state multistep.StateBag)

func (*StepFlock) CleanupFunc

func (s *StepFlock) CleanupFunc(state multistep.StateBag) error

func (*StepFlock) Run

type StepLinkVolume

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

StepLinkVolume attaches the previously created volume to an available device location.

Produces:

device string - The location where the volume was attached.
attach_cleanup CleanupFunc

func (*StepLinkVolume) Cleanup

func (s *StepLinkVolume) Cleanup(state multistep.StateBag)

func (*StepLinkVolume) CleanupFunc

func (s *StepLinkVolume) CleanupFunc(state multistep.StateBag) error

func (*StepLinkVolume) Run

type StepMountDevice

type StepMountDevice struct {
	MountOptions   []string
	MountPartition string
	// contains filtered or unexported fields
}

StepMountDevice mounts the attached device.

Produces:

mount_path string - The location where the volume was mounted.
mount_device_cleanup CleanupFunc - To perform early cleanup

func (*StepMountDevice) Cleanup

func (s *StepMountDevice) Cleanup(state multistep.StateBag)

func (*StepMountDevice) CleanupFunc

func (s *StepMountDevice) CleanupFunc(state multistep.StateBag) error

func (*StepMountDevice) Run

type StepMountExtra

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

StepMountExtra mounts the attached device.

Produces:

mount_extra_cleanup CleanupFunc - To perform early cleanup

func (*StepMountExtra) Cleanup

func (s *StepMountExtra) Cleanup(state multistep.StateBag)

func (*StepMountExtra) CleanupFunc

func (s *StepMountExtra) CleanupFunc(state multistep.StateBag) error

func (*StepMountExtra) Run

type StepPostMountCommands

type StepPostMountCommands struct {
	Commands []string
}

StepPostMountCommands allows running arbitrary commands after mounting the device, but prior to the bind mount and copy steps.

func (*StepPostMountCommands) Cleanup

func (s *StepPostMountCommands) Cleanup(state multistep.StateBag)

func (*StepPostMountCommands) Run

type StepPreMountCommands

type StepPreMountCommands struct {
	Commands []string
}

StepPreMountCommands sets up the a new block device when building from scratch

func (*StepPreMountCommands) Cleanup

func (s *StepPreMountCommands) Cleanup(state multistep.StateBag)

func (*StepPreMountCommands) Run

type StepPrepareDevice

type StepPrepareDevice struct {
}

StepPrepareDevice finds an available device and sets it.

func (*StepPrepareDevice) Cleanup

func (s *StepPrepareDevice) Cleanup(state multistep.StateBag)

func (*StepPrepareDevice) Run

type StepSnapshot

type StepSnapshot struct {
	RawRegion string
	// contains filtered or unexported fields
}

StepSnapshot creates a snapshot of the created volume.

Produces:

snapshot_id string - ID of the created snapshot

func (*StepSnapshot) Cleanup

func (s *StepSnapshot) Cleanup(state multistep.StateBag)

func (*StepSnapshot) Run

type StepVmInfo

type StepVmInfo struct{}

StepVmInfo verifies that this builder is running on an Outscale vm.

func (*StepVmInfo) Cleanup

func (s *StepVmInfo) Cleanup(multistep.StateBag)

func (*StepVmInfo) Run

Jump to

Keyboard shortcuts

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