chroot

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: MPL-2.0, MIT Imports: 28 Imported by: 0

Documentation

Overview

Package chroot is able to create an Azure managed image without requiring the launch of a new virtual machine for every build. It does this by attaching and mounting the root disk and chrooting into that directory. It then creates a managed image from that attached disk.

Code generated by "mapstructure-to-hcl2 -type Config"; DO NOT EDIT.

Code generated by "mapstructure-to-hcl2 -type SharedImageGalleryDestination,TargetRegion"; DO NOT EDIT.

Index

Constants

View Source
const BuilderID = "azure.chroot"

BuilderID is the unique ID for this builder

Variables

View Source
var DiskNotFoundError = errors.New("Disk not found")
View Source
var NewDiskAttacher = func(azureClient client.AzureClientSet) DiskAttacher {
	return &diskAttacher{
		azcli: azureClient,
	}
}

Functions

func CreateVMMetadataTemplateFunc

func CreateVMMetadataTemplateFunc() func(string) (string, error)

CreateVMMetadataTemplateFunc returns a template function that retrieves VM metadata. VM metadata is retrieved only once and reused for all executions of the function.

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

func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error)

type Config

type Config struct {
	common.PackerConfig `mapstructure:",squash"`

	ClientConfig client.Config `mapstructure:",squash"`

	// When set to `true`, starts with an empty, unpartitioned disk. Defaults to `false`.
	FromScratch bool `mapstructure:"from_scratch"`
	// One of the following can be used as a source for an image:
	// - a shared image version resource ID
	// - a managed disk resource ID
	// - a publisher:offer:sku:version specifier for plaform image sources.
	Source string `mapstructure:"source" required:"true"`

	// How to run shell commands. This may be useful to set environment variables or perhaps run
	// a command with sudo or so on. This is a configuration template where the `.Command` variable
	// is replaced with the command to be run. Defaults to `{{.Command}}`.
	CommandWrapper string `mapstructure:"command_wrapper"`
	// A series of commands to execute after attaching the root volume and before mounting the chroot.
	// This is not required unless using `from_scratch`. If so, this should include any partitioning
	// and filesystem creation commands. The path to the device is provided by `{{.Device}}`.
	PreMountCommands []string `mapstructure:"pre_mount_commands"`
	// Options to supply the `mount` command when mounting devices. Each option will be prefixed with
	// `-o` and supplied to the `mount` command ran by Packer. Because this command is ran in a shell,
	// user discretion is advised. See this manual page for the `mount` command for valid file system specific options.
	MountOptions []string `mapstructure:"mount_options"`
	// The partition number containing the / partition. By default this is the first partition of the volume.
	MountPartition string `mapstructure:"mount_partition"`
	// The path where the volume will be mounted. This is where the chroot environment will be. This defaults
	// to `/mnt/packer-amazon-chroot-volumes/{{.Device}}`. This is a configuration template where the `.Device`
	// variable is replaced with the name of the device where the volume is attached.
	MountPath string `mapstructure:"mount_path"`
	// As `pre_mount_commands`, but the commands are executed after mounting the root device and before the
	// extra mount and copy steps. The device and mount path are provided by `{{.Device}}` and `{{.MountPath}}`.
	PostMountCommands []string `mapstructure:"post_mount_commands"`
	// This is a list of devices to mount into the chroot environment. This configuration parameter requires
	// some additional documentation which is in the "Chroot Mounts" section below. Please read that section
	// for more information on how to use this.
	ChrootMounts [][]string `mapstructure:"chroot_mounts"`
	// Paths to files on the running Azure instance that will be copied into the chroot environment prior to
	// provisioning. Defaults to `/etc/resolv.conf` so that DNS lookups work. Pass an empty list to skip copying
	// `/etc/resolv.conf`. You may need to do this if you're building an image that uses systemd.
	CopyFiles []string `mapstructure:"copy_files"`

	// Try to resize the OS disk to this size on the first copy. Disks can only be englarged. If not specified,
	// the disk will keep its original size. Required when using `from_scratch`
	OSDiskSizeGB int32 `mapstructure:"os_disk_size_gb"`
	// The [storage SKU](https://docs.microsoft.com/en-us/rest/api/compute/disks/createorupdate#diskstorageaccounttypes)
	// to use for the OS Disk. Defaults to `Standard_LRS`.
	OSDiskStorageAccountType string `mapstructure:"os_disk_storage_account_type"`
	// The [cache type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#cachingtypes)
	// specified in the resulting image and for attaching it to the Packer VM. Defaults to `ReadOnly`
	OSDiskCacheType string `mapstructure:"os_disk_cache_type"`

	// The [storage SKU](https://docs.microsoft.com/en-us/rest/api/compute/disks/createorupdate#diskstorageaccounttypes)
	// to use for datadisks. Defaults to `Standard_LRS`.
	DataDiskStorageAccountType string `mapstructure:"data_disk_storage_account_type"`
	// The [cache type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#cachingtypes)
	// specified in the resulting image and for attaching it to the Packer VM. Defaults to `ReadOnly`
	DataDiskCacheType string `mapstructure:"data_disk_cache_type"`

	// The [Hyper-V generation type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#hypervgenerationtypes) for Managed Image output.
	// Defaults to `V1`.
	ImageHyperVGeneration string `mapstructure:"image_hyperv_generation"`

	// The id of the temporary OS disk that will be created. Will be generated if not set.
	TemporaryOSDiskID string `mapstructure:"temporary_os_disk_id"`

	// The id of the temporary OS disk snapshot that will be created. Will be generated if not set.
	TemporaryOSDiskSnapshotID string `mapstructure:"temporary_os_disk_snapshot_id"`

	// The prefix for the resource ids of the temporary data disks that will be created. The disks will be suffixed with a number. Will be generated if not set.
	TemporaryDataDiskIDPrefix string `mapstructure:"temporary_data_disk_id_prefix"`

	// The prefix for the resource ids of the temporary data disk snapshots that will be created. The snapshots will be suffixed with a number. Will be generated if not set.
	TemporaryDataDiskSnapshotIDPrefix string `mapstructure:"temporary_data_disk_snapshot_id"`

	// If set to `true`, leaves the temporary disks and snapshots behind in the Packer VM resource group. Defaults to `false`
	SkipCleanup bool `mapstructure:"skip_cleanup"`

	// The managed image to create using this build.
	ImageResourceID string `mapstructure:"image_resource_id"`

	// The shared image to create using this build.
	SharedImageGalleryDestination SharedImageGalleryDestination `mapstructure:"shared_image_destination"`
	// 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.5.0

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.

func (*Config) GetContext

func (c *Config) GetContext() interpolate.Context

GetContext implements ContextProvider to allow steps to use the config context for template interpolation

type DiskAttacher

type DiskAttacher interface {
	AttachDisk(ctx context.Context, disk string) (lun int32, err error)
	WaitForDevice(ctx context.Context, i int32) (device string, err error)
	DetachDisk(ctx context.Context, disk string) (err error)
	WaitForDetach(ctx context.Context, diskID string) error
}

type Diskset added in v1.6.0

type Diskset map[int32]client.Resource

Diskset represents all of the disks or snapshots associated with an image. It maps lun to resource ids. The OS disk is stored with lun=-1.

func (Diskset) Data added in v1.6.0

func (ds Diskset) Data(lun int32) *client.Resource

Data return the data disk resource ID or nil if it is not assigned

func (Diskset) OS added in v1.6.0

func (ds Diskset) OS() *client.Resource

OS return the OS disk resource ID or nil if it is not assigned

type FlatConfig added in v1.5.0

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"`
	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"`
	CloudEnvironmentName              *string                            `mapstructure:"cloud_environment_name" required:"false" cty:"cloud_environment_name" hcl:"cloud_environment_name"`
	ClientID                          *string                            `mapstructure:"client_id" cty:"client_id" hcl:"client_id"`
	ClientSecret                      *string                            `mapstructure:"client_secret" cty:"client_secret" hcl:"client_secret"`
	ClientCertPath                    *string                            `mapstructure:"client_cert_path" cty:"client_cert_path" hcl:"client_cert_path"`
	ClientJWT                         *string                            `mapstructure:"client_jwt" cty:"client_jwt" hcl:"client_jwt"`
	ObjectID                          *string                            `mapstructure:"object_id" cty:"object_id" hcl:"object_id"`
	TenantID                          *string                            `mapstructure:"tenant_id" required:"false" cty:"tenant_id" hcl:"tenant_id"`
	SubscriptionID                    *string                            `mapstructure:"subscription_id" cty:"subscription_id" hcl:"subscription_id"`
	FromScratch                       *bool                              `mapstructure:"from_scratch" cty:"from_scratch" hcl:"from_scratch"`
	Source                            *string                            `mapstructure:"source" required:"true" cty:"source" hcl:"source"`
	CommandWrapper                    *string                            `mapstructure:"command_wrapper" cty:"command_wrapper" hcl:"command_wrapper"`
	PreMountCommands                  []string                           `mapstructure:"pre_mount_commands" cty:"pre_mount_commands" hcl:"pre_mount_commands"`
	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"`
	ChrootMounts                      [][]string                         `mapstructure:"chroot_mounts" cty:"chroot_mounts" hcl:"chroot_mounts"`
	CopyFiles                         []string                           `mapstructure:"copy_files" cty:"copy_files" hcl:"copy_files"`
	OSDiskSizeGB                      *int32                             `mapstructure:"os_disk_size_gb" cty:"os_disk_size_gb" hcl:"os_disk_size_gb"`
	OSDiskStorageAccountType          *string                            `mapstructure:"os_disk_storage_account_type" cty:"os_disk_storage_account_type" hcl:"os_disk_storage_account_type"`
	OSDiskCacheType                   *string                            `mapstructure:"os_disk_cache_type" cty:"os_disk_cache_type" hcl:"os_disk_cache_type"`
	DataDiskStorageAccountType        *string                            `mapstructure:"data_disk_storage_account_type" cty:"data_disk_storage_account_type" hcl:"data_disk_storage_account_type"`
	DataDiskCacheType                 *string                            `mapstructure:"data_disk_cache_type" cty:"data_disk_cache_type" hcl:"data_disk_cache_type"`
	ImageHyperVGeneration             *string                            `mapstructure:"image_hyperv_generation" cty:"image_hyperv_generation" hcl:"image_hyperv_generation"`
	TemporaryOSDiskID                 *string                            `mapstructure:"temporary_os_disk_id" cty:"temporary_os_disk_id" hcl:"temporary_os_disk_id"`
	TemporaryOSDiskSnapshotID         *string                            `mapstructure:"temporary_os_disk_snapshot_id" cty:"temporary_os_disk_snapshot_id" hcl:"temporary_os_disk_snapshot_id"`
	TemporaryDataDiskIDPrefix         *string                            `mapstructure:"temporary_data_disk_id_prefix" cty:"temporary_data_disk_id_prefix" hcl:"temporary_data_disk_id_prefix"`
	TemporaryDataDiskSnapshotIDPrefix *string                            `mapstructure:"temporary_data_disk_snapshot_id" cty:"temporary_data_disk_snapshot_id" hcl:"temporary_data_disk_snapshot_id"`
	SkipCleanup                       *bool                              `mapstructure:"skip_cleanup" cty:"skip_cleanup" hcl:"skip_cleanup"`
	ImageResourceID                   *string                            `mapstructure:"image_resource_id" cty:"image_resource_id" hcl:"image_resource_id"`
	SharedImageGalleryDestination     *FlatSharedImageGalleryDestination `mapstructure:"shared_image_destination" cty:"shared_image_destination" hcl:"shared_image_destination"`
}

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

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 FlatSharedImageGalleryDestination added in v1.5.6

type FlatSharedImageGalleryDestination struct {
	ResourceGroup         *string            `mapstructure:"resource_group" required:"true" cty:"resource_group" hcl:"resource_group"`
	GalleryName           *string            `mapstructure:"gallery_name" required:"true" cty:"gallery_name" hcl:"gallery_name"`
	ImageName             *string            `mapstructure:"image_name" required:"true" cty:"image_name" hcl:"image_name"`
	ImageVersion          *string            `mapstructure:"image_version" required:"true" cty:"image_version" hcl:"image_version"`
	TargetRegions         []FlatTargetRegion `mapstructure:"target_regions" cty:"target_regions" hcl:"target_regions"`
	ExcludeFromLatest     *bool              `mapstructure:"exclude_from_latest" cty:"exclude_from_latest" hcl:"exclude_from_latest"`
	ExcludeFromLatestTypo *bool              `mapstructure:"exlude_from_latest" undocumented:"true" cty:"exlude_from_latest" hcl:"exlude_from_latest"`
}

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

func (*FlatSharedImageGalleryDestination) HCL2Spec added in v1.5.6

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

type FlatTargetRegion added in v1.5.6

type FlatTargetRegion struct {
	Name               *string `mapstructure:"name" required:"true" cty:"name" hcl:"name"`
	ReplicaCount       *int32  `mapstructure:"replicas" cty:"replicas" hcl:"replicas"`
	StorageAccountType *string `mapstructure:"storage_account_type" cty:"storage_account_type" hcl:"storage_account_type"`
}

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

func (*FlatTargetRegion) HCL2Spec added in v1.5.6

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

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

type SharedImageGalleryDestination added in v1.5.6

type SharedImageGalleryDestination struct {
	ResourceGroup string `mapstructure:"resource_group" required:"true"`
	GalleryName   string `mapstructure:"gallery_name" required:"true"`
	ImageName     string `mapstructure:"image_name" required:"true"`
	ImageVersion  string `mapstructure:"image_version" required:"true"`

	TargetRegions         []TargetRegion `mapstructure:"target_regions"`
	ExcludeFromLatest     bool           `mapstructure:"exclude_from_latest"`
	ExcludeFromLatestTypo bool           `mapstructure:"exlude_from_latest" undocumented:"true"`
}

SharedImageGalleryDestination models an image version in a Shared Image Gallery that can be used as a destination.

func (*SharedImageGalleryDestination) FlatMapstructure added in v1.5.6

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

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

func (SharedImageGalleryDestination) ResourceID added in v1.5.6

func (sigd SharedImageGalleryDestination) ResourceID(subscriptionID string) string

ResourceID returns the resource ID string

func (*SharedImageGalleryDestination) Validate added in v1.5.6

func (sigd *SharedImageGalleryDestination) Validate(prefix string) (errs []error, warns []string)

Validate validates that the values in the shared image are valid (without checking them on the network)

type StepAttachDisk

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

func (*StepAttachDisk) Cleanup

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

func (*StepAttachDisk) CleanupFunc

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

func (*StepAttachDisk) Run

type StepCreateImage

type StepCreateImage struct {
	ImageResourceID            string
	ImageOSState               string
	OSDiskStorageAccountType   string
	OSDiskCacheType            string
	DataDiskStorageAccountType string
	DataDiskCacheType          string
	Location                   string
}

func (*StepCreateImage) Cleanup

func (*StepCreateImage) Cleanup(bag multistep.StateBag)

func (*StepCreateImage) Run

type StepCreateNewDiskset added in v1.6.0

type StepCreateNewDiskset struct {
	OSDiskID                   string // Disk ID
	OSDiskSizeGB               int32  // optional, ignored if 0
	OSDiskStorageAccountType   string // from compute.DiskStorageAccountTypes
	DataDiskStorageAccountType string // from compute.DiskStorageAccountTypes

	DataDiskIDPrefix string

	HyperVGeneration string // For OS disk

	// Copy another disk
	SourceOSDiskResourceID string

	// Extract from platform image
	SourcePlatformImage *client.PlatformImage
	// Extract from shared image
	SourceImageResourceID string
	// Location is needed for platform and shared images
	Location string

	SkipCleanup bool
	// contains filtered or unexported fields
}

func (*StepCreateNewDiskset) Cleanup added in v1.6.0

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

func (*StepCreateNewDiskset) Run added in v1.6.0

type StepCreateSharedImageVersion added in v1.5.6

type StepCreateSharedImageVersion struct {
	Destination       SharedImageGalleryDestination
	OSDiskCacheType   string
	DataDiskCacheType string
	Location          string
}

func (*StepCreateSharedImageVersion) Cleanup added in v1.5.6

func (*StepCreateSharedImageVersion) Run added in v1.5.6

type StepCreateSnapshotset added in v1.6.0

type StepCreateSnapshotset struct {
	OSDiskSnapshotID         string
	DataDiskSnapshotIDPrefix string
	Location                 string

	SkipCleanup bool
	// contains filtered or unexported fields
}

func (*StepCreateSnapshotset) Cleanup added in v1.6.0

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

func (*StepCreateSnapshotset) Run added in v1.6.0

type StepMountDevice

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

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 StepResolvePlatformImageVersion added in v1.5.6

type StepResolvePlatformImageVersion struct {
	*client.PlatformImage
	Location string
}

StepResolvePlatformImageVersion resolves the exact PIR version when the version is 'latest'

func (*StepResolvePlatformImageVersion) Cleanup added in v1.5.6

func (*StepResolvePlatformImageVersion) Run added in v1.5.6

Run retrieves all available versions of a PIR image and stores the latest in the PlatformImage

type StepVerifySharedImageDestination added in v1.5.6

type StepVerifySharedImageDestination struct {
	Image    SharedImageGalleryDestination
	Location string
}

StepVerifySharedImageDestination verifies that the shared image location matches the Location field in the step. Also verifies that the OS Type is Linux.

func (*StepVerifySharedImageDestination) Cleanup added in v1.5.6

func (*StepVerifySharedImageDestination) Run added in v1.5.6

Run retrieves the image metadata from Azure and compares the location to Location. Verifies the OS Type.

type StepVerifySharedImageSource added in v1.5.6

type StepVerifySharedImageSource struct {
	SharedImageID  string
	SubscriptionID string
	Location       string
}

StepVerifySharedImageSource verifies that the shared image location matches the Location field in the step. Also verifies that the OS Type is Linux.

func (*StepVerifySharedImageSource) Cleanup added in v1.5.6

func (*StepVerifySharedImageSource) Run added in v1.5.6

Run retrieves the image metadata from Azure and compares the location to Location. Verifies the OS Type.

type StepVerifySourceDisk

type StepVerifySourceDisk struct {
	SourceDiskResourceID string
	Location             string
}

func (StepVerifySourceDisk) Cleanup

func (s StepVerifySourceDisk) Cleanup(state multistep.StateBag)

func (StepVerifySourceDisk) Run

type TargetRegion added in v1.5.6

type TargetRegion struct {
	// Name of the Azure region
	Name string `mapstructure:"name" required:"true"`
	// Number of replicas in this region. Default: 1
	ReplicaCount int32 `mapstructure:"replicas"`
	// Storage account type: Standard_LRS or Standard_ZRS. Default: Standard_ZRS
	StorageAccountType string `mapstructure:"storage_account_type"`
}

TargetRegion describes a region where the shared image should be replicated

func (*TargetRegion) FlatMapstructure added in v1.5.6

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

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

Jump to

Keyboard shortcuts

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