common

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: MPL-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const PackerKeyDefault = 100 * time.Millisecond

PackerKeyDefault 100ms is appropriate for shared build infrastructure while a shorter delay (e.g. 10ms) can be used on a workstation. See PackerKeyEnv.

View Source
const PackerKeyEnv = "PACKER_KEY_INTERVAL"

PackerKeyEnv is used to specify the key interval (delay) between keystrokes sent to the VM, typically in boot commands. This is to prevent host CPU utilization from causing key presses to be skipped or repeated incorrectly.

Variables

View Source
var RetryExhaustedError error = fmt.Errorf("Function never succeeded in Retry")

Functions

func GetHTTPAddr added in v0.12.2

func GetHTTPAddr() string

func GetHTTPIP added in v1.3.4

func GetHTTPIP() string

func GetHTTPPort added in v1.3.4

func GetHTTPPort() string

func GetTerminalDimensions added in v1.3.0

func GetTerminalDimensions() (width, height int, err error)

call into one of the platform-specific implementations to get the current terminal dimensions

func MultistepDebugFn

func MultistepDebugFn(ui packer.Ui) multistep.DebugPauseFn

MultistepDebugFn will return a proper multistep.DebugPauseFn to use for debugging if you're using multistep in your builder.

func NewRunner added in v0.11.0

func NewRunner(steps []multistep.Step, config PackerConfig, ui packer.Ui) multistep.Runner

NewRunner returns a multistep.Runner that runs steps augmented with support for -debug and -on-error command line arguments.

func NewRunnerWithPauseFn added in v0.11.0

func NewRunnerWithPauseFn(steps []multistep.Step, config PackerConfig, ui packer.Ui, state multistep.StateBag) multistep.Runner

NewRunnerWithPauseFn returns a multistep.Runner that runs steps augmented with support for -debug and -on-error command line arguments. With -debug it puts the multistep.DebugPauseFn that will pause execution between steps into the state under the key "pauseFn".

func Retry added in v0.11.0

func Retry(initialInterval float64, maxInterval float64, numTries uint, function RetryableFunc) error

Retry retries a function up to numTries times with exponential backoff. If numTries == 0, retry indefinitely. If interval == 0, Retry will not delay retrying and there will be no exponential backoff. If maxInterval == 0, maxInterval is set to +Infinity. Intervals are in seconds. Returns an error if initial > max intervals, if retries are exhausted, or if the passed function returns an error.

func SetHTTPIP added in v0.12.2

func SetHTTPIP(ip string) error

func SetHTTPPort added in v0.12.2

func SetHTTPPort(port string) error

func ShellCommand added in v1.4.5

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 CommandWrapper added in v1.4.5

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 FloppyConfig added in v0.11.0

type FloppyConfig struct {
	// A list of files to place onto a floppy disk that is attached when the VM
	// is booted. Currently, no support exists for creating sub-directories on
	// the floppy. Wildcard characters (\*, ?, and \[\]) are allowed. Directory
	// names are also allowed, which will add all the files found in the
	// directory to the floppy.
	FloppyFiles []string `mapstructure:"floppy_files"`
	// A list of directories to place onto the floppy disk recursively. This is
	// similar to the `floppy_files` option except that the directory structure
	// is preserved. This is useful for when your floppy disk includes drivers
	// or if you just want to organize it's contents as a hierarchy. Wildcard
	// characters (\*, ?, and \[\]) are allowed. The maximum summary size of
	// all files in the listed directories are the same as in `floppy_files`.
	FloppyDirectories []string `mapstructure:"floppy_dirs"`
	FloppyLabel       string   `mapstructure:"floppy_label"`
}

A floppy can be made available for your build. This is most useful for unattended Windows installs, which look for an Autounattend.xml file on removable media. By default, no floppy will be attached. All files listed in this setting get placed into the root directory of the floppy and the floppy is attached as the first floppy device. The summary size of the listed files must not exceed 1.44 MB. The supported ways to move large files into the OS are using `http_directory` or [the file provisioner](https://www.packer.io/docs/provisioners/file.html).

func (*FloppyConfig) Prepare added in v0.11.0

func (c *FloppyConfig) Prepare(ctx *interpolate.Context) []error

type HTTPConfig added in v0.9.0

type HTTPConfig struct {
	// Path to a directory to serve using an HTTP server. The files in this
	// directory will be available over HTTP that will be requestable from the
	// virtual machine. This is useful for hosting kickstart files and so on.
	// By default this is an empty string, which means no HTTP server will be
	// started. The address and port of the HTTP server will be available as
	// variables in `boot_command`. This is covered in more detail below.
	HTTPDir string `mapstructure:"http_directory"`
	// These are the minimum and maximum port to use for the HTTP server
	// started to serve the `http_directory`. Because Packer often runs in
	// parallel, Packer will choose a randomly available port in this range to
	// run the HTTP server. If you want to force the HTTP server to be on one
	// port, make this minimum and maximum port the same. By default the values
	// are `8000` and `9000`, respectively.
	HTTPPortMin int `mapstructure:"http_port_min"`
	HTTPPortMax int `mapstructure:"http_port_max"`
}

Packer will create an http server serving `http_directory` when it is set, a random free port will be selected and the architecture of the directory referenced will be available in your builder.

Example usage from a builder:

`wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/foo/bar/preseed.cfg`

func (*HTTPConfig) Prepare added in v0.9.0

func (c *HTTPConfig) Prepare(ctx *interpolate.Context) []error

type ISOConfig added in v0.9.0

type ISOConfig struct {
	// The checksum for the ISO file or virtual hard drive file. The algorithm
	// to use when computing the checksum can be optionally specified with
	// `iso_checksum_type`. When `iso_checksum_type` is not set packer will
	// guess the checksumming type based on `iso_checksum` length.
	// `iso_checksum` can be also be a file or an URL, in which case
	// `iso_checksum_type` must be set to `file`; the go-getter will download
	// it and use the first hash found.
	ISOChecksum string `mapstructure:"iso_checksum" required:"true"`
	// An URL to a checksum file containing a checksum for the ISO file. At
	// least one of `iso_checksum` and `iso_checksum_url` must be defined.
	// `iso_checksum_url` will be ignored if `iso_checksum` is non empty.
	ISOChecksumURL string `mapstructure:"iso_checksum_url"`
	// The algorithm to be used when computing the checksum of the file
	// specified in `iso_checksum`. Currently, valid values are "", "none",
	// "md5", "sha1", "sha256", "sha512" or "file". Since the validity of ISO
	// and virtual disk files are typically crucial to a successful build,
	// Packer performs a check of any supplied media by default. While setting
	// "none" will cause Packer to skip this check, corruption of large files
	// such as ISOs and virtual hard drives can occur from time to time. As
	// such, skipping this check is not recommended. `iso_checksum_type` must
	// be set to `file` when `iso_checksum` is an url.
	ISOChecksumType string `mapstructure:"iso_checksum_type"`
	// A URL to the ISO containing the installation image or virtual hard drive
	// (VHD or VHDX) file to clone.
	RawSingleISOUrl string `mapstructure:"iso_url" required:"true"`
	// Multiple URLs for the ISO to download. Packer will try these in order.
	// If anything goes wrong attempting to download or while downloading a
	// single URL, it will move on to the next. All URLs must point to the same
	// file (same checksum). By default this is empty and `iso_url` is used.
	// Only one of `iso_url` or `iso_urls` can be specified.
	ISOUrls []string `mapstructure:"iso_urls"`
	// The path where the iso should be saved after download. By default will
	// go in the packer cache, with a hash of the original filename and
	// checksum as its name.
	TargetPath string `mapstructure:"iso_target_path"`
	// The extension of the iso file after download. This defaults to `iso`.
	TargetExtension string `mapstructure:"iso_target_extension"`
}

By default, Packer will symlink, download or copy image files to the Packer cache into a "`hash($iso_url+$iso_checksum).$iso_target_extension`" file. Packer uses hashicorp/go-getter(https://github.com/hashicorp/go-getter) in file mode in order to perform a download.

go-getter supports the following protocols:

* Local files * Git * Mercurial * HTTP * Amazon S3

\~> On windows - when referencing a local iso - if packer is running without symlinking rights, the iso will be copied to the cache folder. Read [Symlinks in Windows 10 !](https://blogs.windows.com/buildingapps/2016/12/02/symlinks-windows-10/) for more info.

Examples: go-getter can guess the checksum type based on `iso_checksum` len.

``` json

{
  "iso_checksum": "946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2",
  "iso_url": "ubuntu.org/.../ubuntu-14.04.1-server-amd64.iso"
}

```

``` json

{
  "iso_checksum_type": "file",
  "iso_checksum": "ubuntu.org/..../ubuntu-14.04.1-server-amd64.iso.sum",
  "iso_url": "ubuntu.org/.../ubuntu-14.04.1-server-amd64.iso"
}

```

``` json

{
  "iso_checksum_url": "./shasums.txt",
  "iso_url": "ubuntu.org/.../ubuntu-14.04.1-server-amd64.iso"
}

```

``` json

{
  "iso_checksum_type": "sha256",
  "iso_checksum_url": "./shasums.txt",
  "iso_url": "ubuntu.org/.../ubuntu-14.04.1-server-amd64.iso"
}

```

func (*ISOConfig) Prepare added in v0.9.0

func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs []error)

type PackerConfig

type PackerConfig struct {
	PackerBuildName     string            `mapstructure:"packer_build_name"`
	PackerBuilderType   string            `mapstructure:"packer_builder_type"`
	PackerDebug         bool              `mapstructure:"packer_debug"`
	PackerForce         bool              `mapstructure:"packer_force"`
	PackerOnError       string            `mapstructure:"packer_on_error"`
	PackerUserVars      map[string]string `mapstructure:"packer_user_variables"`
	PackerSensitiveVars []string          `mapstructure:"packer_sensitive_variables"`
}

PackerConfig is a struct that contains the configuration keys that are sent by packer, properly tagged already so mapstructure can load them. Embed this structure into your configuration class to get it.

type RetryableFunc added in v1.0.0

type RetryableFunc func(uint) (bool, error)

RetryableFunc performs an action and returns a bool indicating whether the function is done, or if it should keep retrying, and an error which will abort the retry and be returned by the Retry function. The 0-indexed attempt is passed with each call.

type StepCleanupTempKeys added in v1.3.1

type StepCleanupTempKeys struct {
	Comm *communicator.Config
}

func (*StepCleanupTempKeys) Cleanup added in v1.3.1

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

func (*StepCleanupTempKeys) Run added in v1.3.1

type StepCreateFloppy

type StepCreateFloppy struct {
	Files       []string
	Directories []string
	Label       string

	FilesAdded map[string]bool
	// contains filtered or unexported fields
}

StepCreateFloppy will create a floppy disk with the given files.

func (*StepCreateFloppy) Add added in v0.11.0

func (s *StepCreateFloppy) Add(dircache directoryCache, src string) error

func (*StepCreateFloppy) Cleanup

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

func (*StepCreateFloppy) Run

type StepDownload added in v0.3.2

type StepDownload struct {
	// The checksum and the type of the checksum for the download
	Checksum     string
	ChecksumType string

	// A short description of the type of download being done. Example:
	// "ISO" or "Guest Additions"
	Description string

	// The name of the key where the final path of the ISO will be put
	// into the state.
	ResultKey string

	// The path where the result should go, otherwise it goes to the
	// cache directory.
	TargetPath string

	// A list of URLs to attempt to download this thing.
	Url []string

	// Extension is the extension to force for the file that is downloaded.
	// Some systems require a certain extension. If this isn't set, the
	// extension on the URL is used. Otherwise, this will be forced
	// on the downloaded file for every URL.
	Extension string
}

StepDownload downloads a remote file using the download client within this package. This step handles setting up the download configuration, progress reporting, interrupt handling, etc.

Uses:

cache packer.Cache
ui    packer.Ui

func (*StepDownload) Cleanup added in v0.3.2

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

func (*StepDownload) Run added in v0.3.2

type StepHTTPServer added in v0.9.0

type StepHTTPServer struct {
	HTTPDir     string
	HTTPPortMin int
	HTTPPortMax int
	// contains filtered or unexported fields
}

This step creates and runs the HTTP server that is serving files from the directory specified by the 'http_directory` configuration parameter in the template.

Uses:

ui     packer.Ui

Produces:

http_port int - The port the HTTP server started on.

func (*StepHTTPServer) Cleanup added in v0.9.0

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

func (*StepHTTPServer) Run added in v0.9.0

type StepOutputDir added in v1.3.4

type StepOutputDir struct {
	Force bool
	Path  string
	// contains filtered or unexported fields
}

StepOutputDir sets up the output directory by creating it if it does not exist, deleting it if it does exist and we're forcing, and cleaning it up when we're done with it.

func (*StepOutputDir) Cleanup added in v1.3.4

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

func (*StepOutputDir) Run added in v1.3.4

type StepProvision

type StepProvision struct {
	Comm packer.Communicator
}

StepProvision runs the provisioners.

Uses:

communicator packer.Communicator
hook         packer.Hook
ui           packer.Ui

Produces:

<nothing>

func (*StepProvision) Cleanup

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

func (*StepProvision) Run

Directories

Path Synopsis
Package shell defines code that is common in shells
Package shell defines code that is common in shells
Code generated by "mapstructure-to-hcl2 -type Config"; DO NOT EDIT.
Code generated by "mapstructure-to-hcl2 -type Config"; DO NOT EDIT.

Jump to

Keyboard shortcuts

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