packer

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: MPL-2.0 Imports: 32 Imported by: 1,727

Documentation

Overview

Code generated by "mapstructure-to-hcl2 -type MockBuilder,MockCommunicator,RemoteCmd,MockProvisioner,MockPostProcessor"; DO NOT EDIT.

Index

Constants

View Source
const (
	// This is the key in configurations that is set to the name of the
	// build.
	BuildNameConfigKey = "packer_build_name"

	// This is the key in the configuration that is set to the type
	// of the builder that is run. This is useful for provisioners and
	// such who want to make use of this.
	BuilderTypeConfigKey = "packer_builder_type"

	// This is the key in configurations that is set to "true" when Packer
	// debugging is enabled.
	DebugConfigKey = "packer_debug"

	// This is the key in configurations that is set to "true" when Packer
	// force build is enabled.
	ForceConfigKey = "packer_force"

	// This key determines what to do when a normal multistep step fails
	// - "cleanup" - run cleanup steps
	// - "abort" - exit without cleanup
	// - "ask" - ask the user
	OnErrorConfigKey = "packer_on_error"

	// TemplatePathKey is the path to the template that configured this build
	TemplatePathKey = "packer_template_path"

	// This key contains a map[string]string of the user variables for
	// template processing.
	UserVariablesConfigKey = "packer_user_variables"
)
View Source
const (
	UiColorRed     UiColor = 31
	UiColorGreen           = 32
	UiColorYellow          = 33
	UiColorBlue            = 34
	UiColorMagenta         = 35
	UiColorCyan            = 36
)
View Source
const CmdDisconnect int = 2300218

CmdDisconnect is a sentinel value to indicate a RemoteCmd exited because the remote side disconnected us.

View Source
const HookCleanupProvision = "packer_cleanup_provision"
View Source
const HookProvision = "packer_provision"

This is the hook that should be fired for provisioners to run.

View Source
const TelemetryPanicVersion string = "beta/packer_panic/4"
View Source
const TelemetryVersion string = "beta/packer/5"

Variables

View Source
var DefaultCacheDir = "packer_cache"
View Source
var ErrInterrupted = errors.New("interrupted")
View Source
var LogSecretFilter secretFilter
View Source
var ScriptUploadErrorMockCommunicatorError = errors.New("ScriptUploadErrorMockCommunicator Upload error")

Functions

func BasicPlaceholderData added in v1.5.0

func BasicPlaceholderData() map[string]string

Provisioners interpolate most of their fields in the prepare stage; this placeholder map helps keep fields that are only generated at build time from accidentally being interpolated into empty strings at prepare time. This helper function generates the most basic placeholder data which should be accessible to the provisioners. It is used to initialize provisioners, to force validation using the `generated` template function. In the future, custom generated data could be passed into provisioners from builders to enable specialized builder-specific (but still validated!!) access to builder data.

func CachePath added in v1.4.0

func CachePath(paths ...string) (path string, err error)

CachePath returns an absolute path to a cache file or directory

When the directory is not absolute, CachePath will try to get current working directory to be able to return a full path. CachePath tries to create the resulting path if it doesn't exist.

CachePath can error in case it cannot find the cwd.

ex:

PACKER_CACHE_DIR=""            CacheDir() => "./packer_cache/
PACKER_CACHE_DIR=""            CacheDir("foo") => "./packer_cache/foo
PACKER_CACHE_DIR="bar"         CacheDir("foo") => "./bar/foo
PACKER_CACHE_DIR="/home/there" CacheDir("foo", "bar") => "/home/there/foo/bar

func CastDataToMap added in v1.5.0

func CastDataToMap(data interface{}) map[string]interface{}

func ConfigDir added in v0.9.0

func ConfigDir() (string, error)

ConfigDir returns the configuration directory for Packer.

func ConfigFile added in v0.9.0

func ConfigFile() (string, error)

ConfigFile returns the default path to the configuration file. On Unix-like systems this is the ".packerconfig" file in the home directory. On Windows, this is the "packer.config" file in the application data directory.

func ExpandUser added in v1.3.4

func ExpandUser(path string) (string, error)

Given a path, check to see if it's using ~ to reference a user directory. If so, then replace that component with the requested user directory. In "~/", "~" gets replaced by current user's home dir. In "~root/", "~user" gets replaced by root's home dir. ~ has to be the first character of path for ExpandUser change it.

func ProgressBarConfig added in v1.4.0

func ProgressBarConfig(bar *pb.ProgressBar, prefix string)

Types

type Artifact

type Artifact interface {
	// Returns the ID of the builder that was used to create this artifact.
	// This is the internal ID of the builder and should be unique to every
	// builder. This can be used to identify what the contents of the
	// artifact actually are.
	BuilderId() string

	// Returns the set of files that comprise this artifact. If an
	// artifact is not made up of files, then this will be empty.
	Files() []string

	// The ID for the artifact, if it has one. This is not guaranteed to
	// be unique every run (like a GUID), but simply provide an identifier
	// for the artifact that may be meaningful in some way. For example,
	// for Amazon EC2, this value might be the AMI ID.
	Id() string

	// Returns human-readable output that describes the artifact created.
	// This is used for UI output. It can be multiple lines.
	String() string

	// State allows the caller to ask for builder specific state information
	// relating to the artifact instance.
	State(name string) interface{}

	// Destroy deletes the artifact. Packer calls this for various reasons,
	// such as if a post-processor has processed this artifact and it is
	// no longer needed.
	Destroy() error
}

An Artifact is the result of a build, and is the metadata that documents what a builder actually created. The exact meaning of the contents is specific to each builder, but this interface is used to communicate back to the user the result of a build.

type BasicStore added in v1.5.0

type BasicStore interface {
	Has(name string) bool
	List() (names []string)
}

type BasicUi added in v0.3.0

type BasicUi struct {
	Reader      io.Reader
	Writer      io.Writer
	ErrorWriter io.Writer

	TTY TTY
	// contains filtered or unexported fields
}

The BasicUI is a UI that reads and writes from a standard Go reader and writer. It is safe to be called from multiple goroutines. Machine readable output is simply logged for this UI.

func (*BasicUi) Ask added in v0.3.0

func (rw *BasicUi) Ask(query string) (string, error)

func (*BasicUi) Error added in v0.3.0

func (rw *BasicUi) Error(message string)

func (*BasicUi) Machine added in v0.3.0

func (rw *BasicUi) Machine(t string, args ...string)

func (*BasicUi) Message added in v0.3.0

func (rw *BasicUi) Message(message string)

func (*BasicUi) Say added in v0.3.0

func (rw *BasicUi) Say(message string)

func (BasicUi) TrackProgress added in v1.4.0

func (p BasicUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser

type Build

type Build interface {
	// Name is the name of the build. This is unique across a single template,
	// but not absolutely unique. This is meant more to describe to the user
	// what is being built rather than being a unique identifier.
	Name() string

	// Prepare configures the various components of this build and reports
	// any errors in doing so (such as syntax errors, validation errors, etc.).
	// It also reports any warnings.
	Prepare() ([]string, error)

	// Run runs the actual builder, returning an artifact implementation
	// of what is built. If anything goes wrong, an error is returned.
	// Run can be context cancelled.
	Run(context.Context, Ui) ([]Artifact, error)

	// SetDebug will enable/disable debug mode. Debug mode is always
	// enabled by adding the additional key "packer_debug" to boolean
	// true in the configuration of the various components. This must
	// be called prior to Prepare.
	//
	// When SetDebug is set to true, parallelism between builds is
	// strictly prohibited.
	SetDebug(bool)

	// SetForce will enable/disable forcing a build when artifacts exist.
	//
	// When SetForce is set to true, existing artifacts from the build are
	// deleted prior to the build.
	SetForce(bool)

	// SetOnError will determine what to do when a normal multistep step fails
	// - "cleanup" - run cleanup steps
	// - "abort" - exit without cleanup
	// - "ask" - ask the user
	SetOnError(string)
}

A Build represents a single job within Packer that is responsible for building some machine image artifact. Builds are meant to be parallelized.

type Builder

type Builder interface {
	HCL2Speccer

	// Prepare is responsible for configuring the builder and validating
	// that configuration. Any setup should be done in this method. Note that
	// NO side effects should take place in prepare, it is meant as a state
	// setup only. Calling Prepare is not necessarily followed by a Run.
	//
	// The parameters to Prepare are a set of interface{} values of the
	// configuration. These are almost always `map[string]interface{}`
	// parsed from a template, but no guarantee is made.
	//
	// Each of the configuration values should merge into the final
	// configuration.
	//
	// Prepare should return a list of variables that will be made accessible to
	// users during the provison methods, a list of warnings along with any
	// errors that occurred while preparing.
	Prepare(...interface{}) ([]string, []string, error)

	// Run is where the actual build should take place. It takes a Build and a Ui.
	Run(context.Context, Ui, Hook) (Artifact, error)
}

Implementers of Builder are responsible for actually building images on some platform given some configuration.

In addition to the documentation on Prepare above: Prepare is sometimes configured with a `map[string]interface{}` that has a key "packer_debug". This is a boolean value. If it is set to true, then the builder should enable a debug mode which allows builder developers and advanced users to introspect what is going on during a build. During debug builds, parallelism is strictly disabled, so it is safe to request input from stdin and so on.

type BuilderFunc

type BuilderFunc func(name string) (Builder, error)

The function type used to lookup Builder implementations.

type BuilderStore added in v1.5.0

type BuilderStore interface {
	BasicStore
	Start(name string) (Builder, error)
}

type CheckpointTelemetry added in v1.0.1

type CheckpointTelemetry struct {
	// contains filtered or unexported fields
}
var CheckpointReporter *CheckpointTelemetry

func NewCheckpointReporter added in v1.1.1

func NewCheckpointReporter(disableSignature bool) *CheckpointTelemetry

func (*CheckpointTelemetry) AddSpan added in v1.0.1

func (c *CheckpointTelemetry) AddSpan(name, pluginType string, options interface{}) *TelemetrySpan

func (*CheckpointTelemetry) Finalize added in v1.0.1

func (c *CheckpointTelemetry) Finalize(command string, errCode int, err error) error

func (*CheckpointTelemetry) ReportPanic added in v1.0.1

func (c *CheckpointTelemetry) ReportPanic(m string) error

type ColoredUi

type ColoredUi struct {
	Color      UiColor
	ErrorColor UiColor
	Ui         Ui
	// contains filtered or unexported fields
}

ColoredUi is a UI that is colored using terminal colors.

func (*ColoredUi) Ask

func (u *ColoredUi) Ask(query string) (string, error)

func (*ColoredUi) Error

func (u *ColoredUi) Error(message string)

func (*ColoredUi) Machine added in v0.3.0

func (u *ColoredUi) Machine(t string, args ...string)

func (*ColoredUi) Message

func (u *ColoredUi) Message(message string)

func (*ColoredUi) Say

func (u *ColoredUi) Say(message string)

func (ColoredUi) TrackProgress added in v1.4.0

func (p ColoredUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser

type Communicator

type Communicator interface {
	// Start takes a RemoteCmd and starts it. The RemoteCmd must not be
	// modified after being used with Start, and it must not be used with
	// Start again. The Start method returns immediately once the command
	// is started. It does not wait for the command to complete. The
	// RemoteCmd.Exited field should be used for this.
	Start(context.Context, *RemoteCmd) error

	// Upload uploads a file to the machine to the given path with the
	// contents coming from the given reader. This method will block until
	// it completes.
	Upload(string, io.Reader, *os.FileInfo) error

	// UploadDir uploads the contents of a directory recursively to
	// the remote path. It also takes an optional slice of paths to
	// ignore when uploading.
	//
	// The folder name of the source folder should be created unless there
	// is a trailing slash on the source "/". For example: "/tmp/src" as
	// the source will create a "src" directory in the destination unless
	// a trailing slash is added. This is identical behavior to rsync(1).
	UploadDir(dst string, src string, exclude []string) error

	// Download downloads a file from the machine from the given remote path
	// with the contents writing to the given writer. This method will
	// block until it completes.
	Download(string, io.Writer) error

	DownloadDir(src string, dst string, exclude []string) error
}

A Communicator is the interface used to communicate with the machine that exists that will eventually be packaged into an image. Communicators allow you to execute remote commands, upload files, etc.

Communicators must be safe for concurrency, meaning multiple calls to Start or any other method may be called at the same time.

type ComponentFinder

type ComponentFinder struct {
	Hook HookFunc

	// For HCL2
	BuilderStore       BuilderStore
	ProvisionerStore   ProvisionerStore
	PostProcessorStore PostProcessorStore
}

ComponentFinder is a struct that contains the various function pointers necessary to look up components of Packer such as builders, commands, etc.

type ConfigurableCommunicator added in v1.5.0

type ConfigurableCommunicator interface {
	HCL2Speccer
	Configure(...interface{}) ([]string, error)
}

type Core added in v0.8.0

type Core struct {
	Template *template.Template
	// contains filtered or unexported fields
}

Core is the main executor of Packer. If Packer is being used as a library, this is the struct you'll want to instantiate to get anything done.

func NewCore added in v0.8.0

func NewCore(c *CoreConfig) (*Core, error)

NewCore creates a new Core.

func TestCore added in v0.8.0

func TestCore(t *testing.T, c *CoreConfig) *Core

func (*Core) Build added in v0.8.0

func (c *Core) Build(n string) (Build, error)

Build returns the Build object for the given name.

func (*Core) BuildNames added in v0.8.0

func (c *Core) BuildNames() []string

BuildNames returns the builds that are available in this configured core.

func (*Core) Context added in v0.8.0

func (c *Core) Context() *interpolate.Context

Context returns an interpolation context.

type CoreBuild added in v1.5.0

type CoreBuild struct {
	Type          string
	Builder       Builder
	BuilderConfig interface{}
	BuilderType   string

	Provisioners       []CoreBuildProvisioner
	PostProcessors     [][]CoreBuildPostProcessor
	CleanupProvisioner CoreBuildProvisioner
	TemplatePath       string
	Variables          map[string]string
	// contains filtered or unexported fields
}

A CoreBuild struct represents a single build job, the result of which should be a single machine image artifact. This artifact may be comprised of multiple files, of course, but it should be for only a single provider (such as VirtualBox, EC2, etc.).

func (*CoreBuild) Name added in v1.5.0

func (b *CoreBuild) Name() string

Returns the name of the build.

func (*CoreBuild) Prepare added in v1.5.0

func (b *CoreBuild) Prepare() (warn []string, err error)

Prepare prepares the build by doing some initialization for the builder and any hooks. This _must_ be called prior to Run. The parameter is the overrides for the variables within the template (if any).

func (*CoreBuild) Run added in v1.5.0

func (b *CoreBuild) Run(ctx context.Context, originalUi Ui) ([]Artifact, error)

Runs the actual build. Prepare must be called prior to running this.

func (*CoreBuild) SetDebug added in v1.5.0

func (b *CoreBuild) SetDebug(val bool)

func (*CoreBuild) SetForce added in v1.5.0

func (b *CoreBuild) SetForce(val bool)

func (*CoreBuild) SetOnError added in v1.5.0

func (b *CoreBuild) SetOnError(val string)

type CoreBuildPostProcessor added in v1.5.0

type CoreBuildPostProcessor struct {
	PostProcessor PostProcessor
	PType         string
	// contains filtered or unexported fields
}

CoreBuildPostProcessor Keeps track of the post-processor and the configuration of the post-processor used within a build.

type CoreBuildProvisioner added in v1.5.0

type CoreBuildProvisioner struct {
	PType       string
	Provisioner Provisioner
	// contains filtered or unexported fields
}

CoreBuildProvisioner keeps track of the provisioner and the configuration of the provisioner within the build.

type CoreConfig added in v0.8.0

type CoreConfig struct {
	Components         ComponentFinder
	Template           *template.Template
	Variables          map[string]string
	SensitiveVariables []string
	Version            string

	// These are set by command-line flags
	Except []string
	Only   []string
}

CoreConfig is the structure for initializing a new Core. Once a CoreConfig is used to initialize a Core, it shouldn't be re-used or modified again.

func TestCoreConfig added in v0.8.0

func TestCoreConfig(t *testing.T) *CoreConfig

type DebuggedProvisioner added in v1.2.5

type DebuggedProvisioner struct {
	Provisioner Provisioner
	// contains filtered or unexported fields
}

DebuggedProvisioner is a Provisioner implementation that waits until a key press before the provisioner is actually run.

func (*DebuggedProvisioner) ConfigSpec added in v1.5.0

func (p *DebuggedProvisioner) ConfigSpec() hcldec.ObjectSpec

func (*DebuggedProvisioner) FlatConfig added in v1.5.0

func (p *DebuggedProvisioner) FlatConfig() interface{}

func (*DebuggedProvisioner) Prepare added in v1.2.5

func (p *DebuggedProvisioner) Prepare(raws ...interface{}) error

func (*DebuggedProvisioner) Provision added in v1.2.5

func (p *DebuggedProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) error

type DispatchHook

type DispatchHook struct {
	Mapping map[string][]Hook
}

A Hook implementation that dispatches based on an internal mapping.

func (*DispatchHook) Run

func (h *DispatchHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data interface{}) error

Runs the hook with the given name by dispatching it to the proper hooks if a mapping exists. If a mapping doesn't exist, then nothing happens.

type FlatMockBuilder added in v1.5.0

type FlatMockBuilder struct {
	ArtifactId      *string       `cty:"artifact_id"`
	PrepareWarnings []string      `cty:"prepare_warnings"`
	RunErrResult    *bool         `cty:"run_err_result"`
	RunNilResult    *bool         `cty:"run_nil_result"`
	PrepareCalled   *bool         `cty:"prepare_called"`
	PrepareConfig   []interface{} `cty:"prepare_config"`
	RunCalled       *bool         `cty:"run_called"`
	RunHook         Hook          `cty:"run_hook"`
	RunUi           Ui            `cty:"run_ui"`
	CancelCalled    *bool         `cty:"cancel_called"`
	GeneratedVars   []string      `cty:"generated_vars"`
}

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

func (*FlatMockBuilder) HCL2Spec added in v1.5.0

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

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

type FlatMockCommunicator added in v1.5.0

type FlatMockCommunicator struct {
	StartCalled        *bool          `cty:"start_called"`
	StartCmd           *FlatRemoteCmd `cty:"start_cmd"`
	StartStderr        *string        `cty:"start_stderr"`
	StartStdout        *string        `cty:"start_stdout"`
	StartStdin         *string        `cty:"start_stdin"`
	StartExitStatus    *int           `cty:"start_exit_status"`
	UploadCalled       *bool          `cty:"upload_called"`
	UploadPath         *string        `cty:"upload_path"`
	UploadData         *string        `cty:"upload_data"`
	UploadDirDst       *string        `cty:"upload_dir_dst"`
	UploadDirSrc       *string        `cty:"upload_dir_src"`
	UploadDirExclude   []string       `cty:"upload_dir_exclude"`
	DownloadDirDst     *string        `cty:"download_dir_dst"`
	DownloadDirSrc     *string        `cty:"download_dir_src"`
	DownloadDirExclude []string       `cty:"download_dir_exclude"`
	DownloadCalled     *bool          `cty:"download_called"`
	DownloadPath       *string        `cty:"download_path"`
	DownloadData       *string        `cty:"download_data"`
}

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

func (*FlatMockCommunicator) HCL2Spec added in v1.5.0

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

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

type FlatMockPostProcessor added in v1.5.0

type FlatMockPostProcessor struct {
	ArtifactId          *string       `cty:"artifact_id"`
	Keep                *bool         `cty:"keep"`
	ForceOverride       *bool         `cty:"force_override"`
	Error               error         `cty:"error"`
	ConfigureCalled     *bool         `cty:"configure_called"`
	ConfigureConfigs    []interface{} `cty:"configure_configs"`
	ConfigureError      error         `cty:"configure_error"`
	PostProcessCalled   *bool         `cty:"post_process_called"`
	PostProcessArtifact Artifact      `cty:"post_process_artifact"`
	PostProcessUi       Ui            `cty:"post_process_ui"`
}

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

func (*FlatMockPostProcessor) HCL2Spec added in v1.5.0

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

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

type FlatMockProvisioner added in v1.5.0

type FlatMockProvisioner struct {
	PrepCalled       *bool         `cty:"prep_called"`
	PrepConfigs      []interface{} `cty:"prep_configs"`
	ProvCalled       *bool         `cty:"prov_called"`
	ProvCommunicator Communicator  `cty:"prov_communicator"`
	ProvUi           Ui            `cty:"prov_ui"`
}

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

func (*FlatMockProvisioner) HCL2Spec added in v1.5.0

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

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

type FlatRemoteCmd added in v1.5.0

type FlatRemoteCmd struct {
	Command *string   `cty:"command"`
	Stdin   io.Reader `cty:"stdin"`
	Stdout  io.Writer `cty:"stdout"`
	Stderr  io.Writer `cty:"stderr"`
}

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

func (*FlatRemoteCmd) HCL2Spec added in v1.5.0

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

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

type HCL2Speccer added in v1.5.0

type HCL2Speccer interface {
	// ConfigSpec should return the hcl object spec used to configure the
	// builder. It will be used to tell the HCL parsing library how to
	// validate/configure a configuration.
	ConfigSpec() hcldec.ObjectSpec
}

a struct (or type) implementing HCL2Speccer is a type that can tell it's own hcl2 conf/layout.

type Hook

type Hook interface {
	Run(context.Context, string, Ui, Communicator, interface{}) error
}

A Hook is used to hook into an arbitrarily named location in a build, allowing custom behavior to run at certain points along a build.

Run is called when the hook is called, with the name of the hook and arbitrary data associated with it. To know what format the data is in, you must reference the documentation for the specific hook you're interested in. In addition to that, the Hook is given access to a UI so that it can output things to the user.

The first context argument controls cancellation, the context will usually be called when Run is still in progress so the mechanism that handles this must be race-free. Cancel should attempt to cancel the hook in the quickest, safest way possible.

type HookFunc

type HookFunc func(name string) (Hook, error)

The function type used to lookup Hook implementations.

type HookedProvisioner added in v1.1.2

type HookedProvisioner struct {
	Provisioner Provisioner
	Config      interface{}
	TypeName    string
}

A HookedProvisioner represents a provisioner and information describing it

type MachineReadableUi added in v0.3.0

type MachineReadableUi struct {
	Writer io.Writer
	NoopProgressTracker
}

MachineReadableUi is a UI that only outputs machine-readable output to the given Writer.

func (*MachineReadableUi) Ask added in v0.3.0

func (u *MachineReadableUi) Ask(query string) (string, error)

func (*MachineReadableUi) Error added in v0.3.0

func (u *MachineReadableUi) Error(message string)

func (*MachineReadableUi) Machine added in v0.3.0

func (u *MachineReadableUi) Machine(category string, args ...string)

func (*MachineReadableUi) Message added in v0.3.0

func (u *MachineReadableUi) Message(message string)

func (*MachineReadableUi) Say added in v0.3.0

func (u *MachineReadableUi) Say(message string)

type MapOfBuilder added in v1.5.0

type MapOfBuilder map[string]func() (Builder, error)

func (MapOfBuilder) Has added in v1.5.0

func (mob MapOfBuilder) Has(builder string) bool

func (MapOfBuilder) List added in v1.5.0

func (mob MapOfBuilder) List() []string

func (MapOfBuilder) Start added in v1.5.0

func (mob MapOfBuilder) Start(builder string) (Builder, error)

type MapOfPostProcessor added in v1.5.0

type MapOfPostProcessor map[string]func() (PostProcessor, error)

func (MapOfPostProcessor) Has added in v1.5.0

func (mopp MapOfPostProcessor) Has(postProcessor string) bool

func (MapOfPostProcessor) List added in v1.5.0

func (mopp MapOfPostProcessor) List() []string

func (MapOfPostProcessor) Start added in v1.5.0

func (mopp MapOfPostProcessor) Start(postProcessor string) (PostProcessor, error)

type MapOfProvisioner added in v1.5.0

type MapOfProvisioner map[string]func() (Provisioner, error)

func (MapOfProvisioner) Has added in v1.5.0

func (mop MapOfProvisioner) Has(provisioner string) bool

func (MapOfProvisioner) List added in v1.5.0

func (mop MapOfProvisioner) List() []string

func (MapOfProvisioner) Start added in v1.5.0

func (mop MapOfProvisioner) Start(provisioner string) (Provisioner, error)

type MockArtifact added in v0.3.5

type MockArtifact struct {
	BuilderIdValue string
	FilesValue     []string
	IdValue        string
	StateValues    map[string]interface{}
	DestroyCalled  bool
	StringValue    string
}

MockArtifact is an implementation of Artifact that can be used for tests.

func (*MockArtifact) BuilderId added in v0.3.5

func (a *MockArtifact) BuilderId() string

func (*MockArtifact) Destroy added in v0.3.5

func (a *MockArtifact) Destroy() error

func (*MockArtifact) Files added in v0.3.5

func (a *MockArtifact) Files() []string

func (*MockArtifact) Id added in v0.3.5

func (a *MockArtifact) Id() string

func (*MockArtifact) State added in v0.7.2

func (a *MockArtifact) State(name string) interface{}

func (*MockArtifact) String added in v0.3.5

func (a *MockArtifact) String() string

type MockBuilder added in v0.3.5

type MockBuilder struct {
	ArtifactId      string
	PrepareWarnings []string
	RunErrResult    bool
	RunNilResult    bool

	PrepareCalled bool
	PrepareConfig []interface{}
	RunCalled     bool
	RunHook       Hook
	RunUi         Ui
	CancelCalled  bool
	RunFn         func(ctx context.Context)

	GeneratedVars []string
}

MockBuilder is an implementation of Builder that can be used for tests. You can set some fake return values and you can keep track of what methods were called on the builder. It is fairly basic.

func TestBuilder added in v0.8.0

func TestBuilder(t *testing.T, c *CoreConfig, n string) *MockBuilder

TestBuilder sets the builder with the name n to the component finder and returns the mock.

func (*MockBuilder) ConfigSpec added in v1.5.0

func (tb *MockBuilder) ConfigSpec() hcldec.ObjectSpec

func (*MockBuilder) FlatConfig added in v1.5.0

func (tb *MockBuilder) FlatConfig() interface{}

func (*MockBuilder) FlatMapstructure added in v1.5.0

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

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

func (*MockBuilder) Prepare added in v0.3.5

func (tb *MockBuilder) Prepare(config ...interface{}) ([]string, []string, error)

func (*MockBuilder) Run added in v0.3.5

func (tb *MockBuilder) Run(ctx context.Context, ui Ui, h Hook) (Artifact, error)

type MockCommunicator added in v0.3.5

type MockCommunicator struct {
	StartCalled     bool
	StartCmd        *RemoteCmd
	StartStderr     string
	StartStdout     string
	StartStdin      string
	StartExitStatus int

	UploadCalled bool
	UploadPath   string
	UploadData   string

	UploadDirDst     string
	UploadDirSrc     string
	UploadDirExclude []string

	DownloadDirDst     string
	DownloadDirSrc     string
	DownloadDirExclude []string

	DownloadCalled bool
	DownloadPath   string
	DownloadData   string
}

MockCommunicator is a valid Communicator implementation that can be used for tests.

func (*MockCommunicator) Download added in v0.3.5

func (c *MockCommunicator) Download(path string, w io.Writer) error

func (*MockCommunicator) DownloadDir added in v0.9.0

func (c *MockCommunicator) DownloadDir(src string, dst string, excl []string) error

func (*MockCommunicator) FlatMapstructure added in v1.5.0

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

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

func (*MockCommunicator) Start added in v0.3.5

func (c *MockCommunicator) Start(ctx context.Context, rc *RemoteCmd) error

func (*MockCommunicator) Upload added in v0.3.5

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

func (*MockCommunicator) UploadDir added in v0.3.5

func (c *MockCommunicator) UploadDir(dst string, src string, excl []string) error

type MockHook added in v0.3.6

type MockHook struct {
	RunFunc func(context.Context) error

	RunCalled bool
	RunComm   Communicator
	RunData   interface{}
	RunName   string
	RunUi     Ui
}

MockHook is an implementation of Hook that can be used for tests.

func (*MockHook) Run added in v0.3.6

func (t *MockHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data interface{}) error

type MockPostProcessor added in v0.8.0

type MockPostProcessor struct {
	ArtifactId    string
	Keep          bool
	ForceOverride bool
	Error         error

	ConfigureCalled  bool
	ConfigureConfigs []interface{}
	ConfigureError   error

	PostProcessCalled   bool
	PostProcessArtifact Artifact
	PostProcessUi       Ui
}

MockPostProcessor is an implementation of PostProcessor that can be used for tests.

func TestPostProcessor added in v0.8.0

func TestPostProcessor(t *testing.T, c *CoreConfig, n string) *MockPostProcessor

TestPostProcessor sets the prov. with the name n to the component finder and returns the mock.

func (*MockPostProcessor) ConfigSpec added in v1.5.0

func (t *MockPostProcessor) ConfigSpec() hcldec.ObjectSpec

func (*MockPostProcessor) Configure added in v0.8.0

func (t *MockPostProcessor) Configure(configs ...interface{}) error

func (*MockPostProcessor) FlatMapstructure added in v1.5.0

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

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

func (*MockPostProcessor) PostProcess added in v0.8.0

func (t *MockPostProcessor) PostProcess(ctx context.Context, ui Ui, a Artifact) (Artifact, bool, bool, error)

type MockProvisioner added in v0.3.6

type MockProvisioner struct {
	ProvFunc func(context.Context) error

	PrepCalled       bool
	PrepConfigs      []interface{}
	ProvCalled       bool
	ProvCommunicator Communicator
	ProvUi           Ui
}

MockProvisioner is an implementation of Provisioner that can be used for tests.

func TestProvisioner added in v0.8.0

func TestProvisioner(t *testing.T, c *CoreConfig, n string) *MockProvisioner

TestProvisioner sets the prov. with the name n to the component finder and returns the mock.

func (*MockProvisioner) Communicator added in v1.3.4

func (t *MockProvisioner) Communicator() Communicator

func (*MockProvisioner) ConfigSpec added in v1.5.0

func (tp *MockProvisioner) ConfigSpec() hcldec.ObjectSpec

func (*MockProvisioner) ElevatedPassword added in v1.3.4

func (t *MockProvisioner) ElevatedPassword() string

func (*MockProvisioner) ElevatedUser added in v1.3.4

func (t *MockProvisioner) ElevatedUser() string

func (*MockProvisioner) FlatConfig added in v1.5.0

func (tp *MockProvisioner) FlatConfig() interface{}

func (*MockProvisioner) FlatMapstructure added in v1.5.0

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

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

func (*MockProvisioner) Prepare added in v0.3.6

func (t *MockProvisioner) Prepare(configs ...interface{}) error

func (*MockProvisioner) Provision added in v0.3.6

func (t *MockProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) error

type MultiError

type MultiError struct {
	Errors []error
}

MultiError is an error type to track multiple errors. This is used to accumulate errors in cases such as configuration parsing, and returning them as a single error.

func MultiErrorAppend added in v0.2.1

func MultiErrorAppend(err error, errs ...error) *MultiError

MultiErrorAppend is a helper function that will append more errors onto a MultiError in order to create a larger multi-error. If the original error is not a MultiError, it will be turned into one.

func (*MultiError) Error

func (e *MultiError) Error() string

type NoopProgressTracker added in v1.4.0

type NoopProgressTracker struct{}

NoopProgressTracker is a progress tracker that displays nothing.

func (*NoopProgressTracker) TrackProgress added in v1.4.0

func (*NoopProgressTracker) TrackProgress(_ string, _, _ int64, stream io.ReadCloser) io.ReadCloser

TrackProgress returns stream

type NoopUi added in v1.3.0

type NoopUi struct {
	NoopProgressTracker
}

func (*NoopUi) Ask added in v1.3.0

func (*NoopUi) Ask(string) (string, error)

func (*NoopUi) Error added in v1.3.0

func (*NoopUi) Error(string)

func (*NoopUi) Machine added in v1.3.0

func (*NoopUi) Machine(string, ...string)

func (*NoopUi) Message added in v1.3.0

func (*NoopUi) Message(string)

func (*NoopUi) Say added in v1.3.0

func (*NoopUi) Say(string)

type PackerReport added in v1.0.1

type PackerReport struct {
	Spans    []*TelemetrySpan `json:"spans"`
	ExitCode int              `json:"exit_code"`
	Error    string           `json:"error"`
	Command  string           `json:"command"`
}

type PausedProvisioner added in v0.5.0

type PausedProvisioner struct {
	PauseBefore time.Duration
	Provisioner Provisioner
}

PausedProvisioner is a Provisioner implementation that pauses before the provisioner is actually run.

func (*PausedProvisioner) ConfigSpec added in v1.5.0

func (p *PausedProvisioner) ConfigSpec() hcldec.ObjectSpec

func (*PausedProvisioner) FlatConfig added in v1.5.0

func (p *PausedProvisioner) FlatConfig() interface{}

func (*PausedProvisioner) Prepare added in v0.5.0

func (p *PausedProvisioner) Prepare(raws ...interface{}) error

func (*PausedProvisioner) Provision added in v0.5.0

func (p *PausedProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) error

type PostProcessor

type PostProcessor interface {
	HCL2Speccer

	// Configure is responsible for setting up configuration, storing
	// the state for later, and returning and errors, such as validation
	// errors.
	Configure(...interface{}) error

	// PostProcess takes a previously created Artifact and produces another
	// Artifact. If an error occurs, it should return that error. If `keep` is
	// true, then the previous artifact defaults to being kept if user has not
	// given a value to keep_input_artifact. If forceOverride is true, then any
	// user input for keep_input_artifact is ignored and the artifact is either
	// kept or discarded according to the value set in `keep`.
	// PostProcess is cancellable using context
	PostProcess(context.Context, Ui, Artifact) (a Artifact, keep bool, forceOverride bool, err error)
}

A PostProcessor is responsible for taking an artifact of a build and doing some sort of post-processing to turn this into another artifact. An example of a post-processor would be something that takes the result of a build, compresses it, and returns a new artifact containing a single file of the prior artifact compressed.

type PostProcessorFunc

type PostProcessorFunc func(name string) (PostProcessor, error)

The function type used to lookup PostProcessor implementations.

type PostProcessorStore added in v1.5.0

type PostProcessorStore interface {
	BasicStore
	Start(name string) (PostProcessor, error)
}

type ProvisionHook

type ProvisionHook struct {
	// The provisioners to run as part of the hook. These should already
	// be prepared (by calling Prepare) at some earlier stage.
	Provisioners []*HookedProvisioner
}

A Hook implementation that runs the given provisioners.

func (*ProvisionHook) Run

func (h *ProvisionHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data interface{}) error

Runs the provisioners in order.

type Provisioner

type Provisioner interface {
	HCL2Speccer

	// Prepare is called with a set of configurations to setup the
	// internal state of the provisioner. The multiple configurations
	// should be merged in some sane way.
	Prepare(...interface{}) error

	// Provision is called to actually provision the machine. A context is
	// given for cancellation, a UI is given to communicate with the user, and
	// a communicator is given that is guaranteed to be connected to some
	// machine so that provisioning can be done.
	Provision(context.Context, Ui, Communicator, map[string]interface{}) error
}

A provisioner is responsible for installing and configuring software on a machine prior to building the actual image.

type ProvisionerFunc

type ProvisionerFunc func(name string) (Provisioner, error)

The function type used to lookup Provisioner implementations.

type ProvisionerStore added in v1.5.0

type ProvisionerStore interface {
	BasicStore
	Start(name string) (Provisioner, error)
}

type RemoteCmd

type RemoteCmd struct {
	// Command is the command to run remotely. This is executed as if
	// it were a shell command, so you are expected to do any shell escaping
	// necessary.
	Command string

	// Stdin specifies the process's standard input. If Stdin is
	// nil, the process reads from an empty bytes.Buffer.
	Stdin io.Reader

	// Stdout and Stderr represent the process's standard output and
	// error.
	//
	// If either is nil, it will be set to ioutil.Discard.
	Stdout io.Writer
	Stderr io.Writer
	// contains filtered or unexported fields
}

RemoteCmd represents a remote command being prepared or run.

func (*RemoteCmd) ExitStatus

func (r *RemoteCmd) ExitStatus() int

func (*RemoteCmd) FlatMapstructure added in v1.5.0

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

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

func (*RemoteCmd) RunWithUi added in v1.4.0

func (r *RemoteCmd) RunWithUi(ctx context.Context, c Communicator, ui Ui) error

RunWithUi runs the remote command and streams the output to any configured Writers for stdout/stderr, while also writing each line as it comes to a Ui. RunWithUi will not return until the command finishes or is cancelled.

func (*RemoteCmd) SetExited added in v0.2.2

func (r *RemoteCmd) SetExited(status int)

SetExited is a helper for setting that this process is exited. This should be called by communicators who are running a remote command in order to set that the command is done.

func (*RemoteCmd) Wait

func (r *RemoteCmd) Wait() int

Wait for command exit and return exit status

type SafeUi added in v1.3.5

type SafeUi struct {
	Sem chan int
	Ui  Ui
	// contains filtered or unexported fields
}

Safe is a UI that wraps another UI implementation and provides concurrency-safe access

func (*SafeUi) Ask added in v1.3.5

func (u *SafeUi) Ask(s string) (string, error)

func (*SafeUi) Error added in v1.3.5

func (u *SafeUi) Error(s string)

func (*SafeUi) Machine added in v1.3.5

func (u *SafeUi) Machine(t string, args ...string)

func (*SafeUi) Message added in v1.3.5

func (u *SafeUi) Message(s string)

func (*SafeUi) Say added in v1.3.5

func (u *SafeUi) Say(s string)

func (SafeUi) TrackProgress added in v1.4.0

func (p SafeUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser

type ScriptUploadErrorMockCommunicator added in v1.4.2

type ScriptUploadErrorMockCommunicator struct {
	MockCommunicator
}

ScriptUploadErrorMockCommunicator returns an error from it's Upload() method when a script is uploaded to test the case where this upload fails.

func (*ScriptUploadErrorMockCommunicator) Upload added in v1.4.2

type TTY added in v1.4.0

type TTY interface {
	ReadString() (string, error)
	Close() error
}

type TargetedUI added in v1.0.0

type TargetedUI struct {
	Target string
	Ui     Ui
	// contains filtered or unexported fields
}

TargetedUI is a UI that wraps another UI implementation and modifies the output to indicate a specific target. Specifically, all Say output is prefixed with the target name. Message output is not prefixed but is offset by the length of the target so that output is lined up properly with Say output. Machine-readable output has the proper target set.

func (*TargetedUI) Ask added in v1.0.0

func (u *TargetedUI) Ask(query string) (string, error)

func (*TargetedUI) Error added in v1.0.0

func (u *TargetedUI) Error(message string)

func (*TargetedUI) Machine added in v1.0.0

func (u *TargetedUI) Machine(t string, args ...string)

func (*TargetedUI) Message added in v1.0.0

func (u *TargetedUI) Message(message string)

func (*TargetedUI) Say added in v1.0.0

func (u *TargetedUI) Say(message string)

func (TargetedUI) TrackProgress added in v1.4.0

func (p TargetedUI) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser

type TelemetrySpan added in v1.0.1

type TelemetrySpan struct {
	EndTime   time.Time `json:"end_time"`
	Error     string    `json:"error"`
	Name      string    `json:"name"`
	Options   []string  `json:"options"`
	StartTime time.Time `json:"start_time"`
	Type      string    `json:"type"`
}

func (*TelemetrySpan) End added in v1.0.1

func (s *TelemetrySpan) End(err error)

type TimeoutProvisioner added in v1.4.0

type TimeoutProvisioner struct {
	Provisioner
	Timeout time.Duration
}

TimeoutProvisioner is a Provisioner implementation that can timeout after a duration

func (*TimeoutProvisioner) Provision added in v1.4.0

func (p *TimeoutProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) error

type TimestampedUi added in v1.3.2

type TimestampedUi struct {
	Ui Ui
	// contains filtered or unexported fields
}

TimestampedUi is a UI that wraps another UI implementation and prefixes each message with an RFC3339 timestamp

func (*TimestampedUi) Ask added in v1.3.2

func (u *TimestampedUi) Ask(query string) (string, error)

func (*TimestampedUi) Error added in v1.3.2

func (u *TimestampedUi) Error(message string)

func (*TimestampedUi) Machine added in v1.3.2

func (u *TimestampedUi) Machine(message string, args ...string)

func (*TimestampedUi) Message added in v1.3.2

func (u *TimestampedUi) Message(message string)

func (*TimestampedUi) Say added in v1.3.2

func (u *TimestampedUi) Say(message string)

func (TimestampedUi) TrackProgress added in v1.4.0

func (p TimestampedUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser

type Ui

type Ui interface {
	Ask(string) (string, error)
	Say(string)
	Message(string)
	Error(string)
	Machine(string, ...string)
	getter.ProgressTracker
}

The Ui interface handles all communication for Packer with the outside world. This sort of control allows us to strictly control how output is formatted and various levels of output.

func TestUi added in v0.8.0

func TestUi(t *testing.T) Ui

type UiColor

type UiColor uint

Directories

Path Synopsis
The plugin package provides the functionality to both expose a Packer plugin binary and to connect to an existing Packer plugin binary.
The plugin package provides the functionality to both expose a Packer plugin binary and to connect to an existing Packer plugin binary.
Package tmp provides temporary directory helpers.
Package tmp provides temporary directory helpers.

Jump to

Keyboard shortcuts

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