packer

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: MPL-2.0 Imports: 20 Imported by: 237

Documentation

Overview

Package packer contains all of the interfaces for key Packer objects.

This module will need to be imported by all but the very simplest plugins. It represents the foundation of the API that the Core and Plugins use to communicate with each other.

Changes to any of the interfaces in this package likely represent a backwards-incompatibility and should therefore only be made rarely and when absolutely necessary.

Plugins will need to implement either the Builder, Provisioner, or Post-Processor interfaces, and will likely create an Artifact. The Communicator must be implemented in the Builder and then passed into the Provisioners so they can use it communicate with the instance without needing to know the connection details.

The UI is created by the Packer core for use by the plugins, and is how the plugins stream information back to the terminal.

Index

Constants

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.

Variables

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

Functions

func CachePath

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 make a a cache depending on the operating system.

NOTE: cache directory will change depending on operating system dependent For Windows:

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

For Unix: NOTE: PACKER_CACHE_DIR will be used over XDG_CACHE_HOME environment variable

PACKER_CACHE_DIR="",            XDG_CACHE_HOME="",						 CacheDir() => "$HOME/cache/packer"
PACKER_CACHE_DIR="",            XDG_CACHE_HOME="", 					 CacheDir("foo") => "$HOME/cache/packer/foo"
PACKER_CACHE_DIR="bar",         XDG_CACHE_HOME="", 					 CacheDir("foo") => "./bar/foo"
PACKER_CACHE_DIR="/home/there", XDG_CACHE_HOME="", 					 CacheDir("foo", "bar") => "/home/there/foo/bar"
PACKER_CACHE_DIR="",            XDG_CACHE_HOME="/home/there", CacheDir("foo", "bar") => "/home/there/foo/bar"
PACKER_CACHE_DIR="/foo",        XDG_CACHE_HOME="/bar",        CacheDir("a", "b") => "/foo/a/b"

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 BasicUi

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

	TTY TTY
	PB  getter.ProgressTracker
	// contains filtered or unexported fields
}

BasicUI is an implementation of 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

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

func (*BasicUi) Error

func (rw *BasicUi) Error(message string)

func (*BasicUi) Machine

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

func (*BasicUi) Message

func (rw *BasicUi) Message(message string)

func (*BasicUi) Say

func (rw *BasicUi) Say(message string)

func (*BasicUi) TrackProgress

func (rw *BasicUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body 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 provision 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 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 ConfigurableCommunicator

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

type Datasource added in v0.0.7

type Datasource interface {
	// HCL2Speccer is a type that can tell it's own hcl2 conf/layout.
	HCL2Speccer

	// Configure takes values from HCL2 and applies them to the struct
	Configure(...interface{}) error

	// OutputSpec is the HCL2 layout of the variable output, it will allow
	// Packer to validate whether someone is using the output of the data
	// source correctly without having to execute the data source call.
	OutputSpec() hcldec.ObjectSpec

	// Execute the func call and return the values
	Execute() (cty.Value, error)
}

Datasources make data available for use in any source block of a Packer configuration.

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

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

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 FlatMockDatasource added in v0.0.7

type FlatMockDatasource struct {
	Foo *string `cty:"foo" hcl:"foo"`
}

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

func (*FlatMockDatasource) HCL2Spec added in v0.0.7

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

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

type FlatMockDatasourceResponse added in v0.0.7

type FlatMockDatasourceResponse struct {
	Foo *string `cty:"foo" hcl:"foo"`
}

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

func (*FlatMockDatasourceResponse) HCL2Spec added in v0.0.7

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

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

type FlatMockProvisioner

type FlatMockProvisioner struct {
	PrepCalled       *bool         `cty:"prep_called" hcl:"prep_called"`
	PrepConfigs      []interface{} `cty:"prep_configs" hcl:"prep_configs"`
	ProvCalled       *bool         `cty:"prov_called" hcl:"prov_called"`
	ProvRetried      *bool         `cty:"prov_retried" hcl:"prov_retried"`
	ProvCommunicator Communicator  `cty:"prov_communicator" hcl:"prov_communicator"`
	ProvUi           Ui            `cty:"prov_ui" hcl:"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

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 HCL2Speccer

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 MapOfBuilder

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

func (MapOfBuilder) Has

func (mob MapOfBuilder) Has(builder string) bool

func (MapOfBuilder) List

func (mob MapOfBuilder) List() []string

func (MapOfBuilder) Set added in v0.0.11

func (mob MapOfBuilder) Set(builder string, starter func() (Builder, error))

func (MapOfBuilder) Start

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

type MapOfDatasource added in v0.0.7

type MapOfDatasource map[string]func() (Datasource, error)

func (MapOfDatasource) Has added in v0.0.7

func (mod MapOfDatasource) Has(dataSource string) bool

func (MapOfDatasource) List added in v0.0.7

func (mod MapOfDatasource) List() []string

func (MapOfDatasource) Set added in v0.0.11

func (mod MapOfDatasource) Set(dataSource string, starter func() (Datasource, error))

func (MapOfDatasource) Start added in v0.0.7

func (mod MapOfDatasource) Start(dataSource string) (Datasource, error)

type MapOfPostProcessor

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

func (MapOfPostProcessor) Has

func (mopp MapOfPostProcessor) Has(postProcessor string) bool

func (MapOfPostProcessor) List

func (mopp MapOfPostProcessor) List() []string

func (MapOfPostProcessor) Set added in v0.0.11

func (mopp MapOfPostProcessor) Set(postProcessor string, starter func() (PostProcessor, error))

func (MapOfPostProcessor) Start

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

type MapOfProvisioner

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

func (MapOfProvisioner) Has

func (mop MapOfProvisioner) Has(provisioner string) bool

func (MapOfProvisioner) List

func (mop MapOfProvisioner) List() []string

func (MapOfProvisioner) Set added in v0.0.11

func (mop MapOfProvisioner) Set(provisioner string, starter func() (Provisioner, error))

func (MapOfProvisioner) Start

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

type MockArtifact

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

func (a *MockArtifact) BuilderId() string

func (*MockArtifact) Destroy

func (a *MockArtifact) Destroy() error

func (*MockArtifact) Files

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

func (*MockArtifact) Id

func (a *MockArtifact) Id() string

func (*MockArtifact) State

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

func (*MockArtifact) String

func (a *MockArtifact) String() string

type MockBuilder

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 (*MockBuilder) ConfigSpec

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

func (*MockBuilder) FlatConfig

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

func (*MockBuilder) FlatMapstructure

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

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

func (*MockBuilder) Run

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

type MockCommunicator

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

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

func (*MockCommunicator) DownloadDir

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

func (*MockCommunicator) Start

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

func (*MockCommunicator) Upload

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

func (*MockCommunicator) UploadDir

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

type MockDatasource added in v0.0.7

type MockDatasource struct {
	Foo string

	OutputSpecCalled bool          `mapstructure-to-hcl2:",skip"`
	ConfigureCalled  bool          `mapstructure-to-hcl2:",skip"`
	ConfigureConfigs []interface{} `mapstructure-to-hcl2:",skip"`
	ExecuteCalled    bool          `mapstructure-to-hcl2:",skip"`
}

func (*MockDatasource) ConfigSpec added in v0.0.7

func (d *MockDatasource) ConfigSpec() hcldec.ObjectSpec

func (*MockDatasource) Configure added in v0.0.7

func (d *MockDatasource) Configure(configs ...interface{}) error

func (*MockDatasource) Execute added in v0.0.7

func (d *MockDatasource) Execute() (cty.Value, error)

func (*MockDatasource) FlatMapstructure added in v0.0.7

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

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

func (*MockDatasource) OutputSpec added in v0.0.7

func (d *MockDatasource) OutputSpec() hcldec.ObjectSpec

type MockDatasourceResponse added in v0.0.7

type MockDatasourceResponse struct {
	Foo string
}

func (*MockDatasourceResponse) FlatMapstructure added in v0.0.7

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

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

type MockHook

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

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

type MockProvisioner

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

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

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

func (*MockProvisioner) Communicator

func (t *MockProvisioner) Communicator() Communicator

func (*MockProvisioner) ConfigSpec

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

func (*MockProvisioner) ElevatedPassword

func (t *MockProvisioner) ElevatedPassword() string

func (*MockProvisioner) ElevatedUser

func (t *MockProvisioner) ElevatedUser() string

func (*MockProvisioner) FlatConfig

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

func (*MockProvisioner) FlatMapstructure

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

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

func (*MockProvisioner) Provision

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

type MockUi

type MockUi struct {
	AskCalled      bool
	AskQuery       string
	ErrorCalled    bool
	ErrorMessage   string
	MachineCalled  bool
	MachineType    string
	MachineArgs    []string
	MessageCalled  bool
	MessageMessage string
	SayCalled      bool
	SayMessages    []SayMessage

	TrackProgressCalled    bool
	ProgressBarAddCalled   bool
	ProgressBarCloseCalled bool
}

func (*MockUi) Ask

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

func (*MockUi) Error

func (u *MockUi) Error(message string)

func (*MockUi) Machine

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

func (*MockUi) Message

func (u *MockUi) Message(message string)

func (*MockUi) Say

func (u *MockUi) Say(message string)

func (*MockUi) TrackProgress

func (u *MockUi) TrackProgress(_ string, _, _ int64, stream io.ReadCloser) (body io.ReadCloser)

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

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

type NoopProgressTracker struct{}

NoopProgressTracker is a progress tracker that displays nothing.

func (*NoopProgressTracker) TrackProgress

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

TrackProgress returns stream

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 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 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) RunWithUi

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

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

type SafeUi struct {
	Sem chan int
	Ui  Ui
	PB  getter.ProgressTracker
}

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

func (*SafeUi) Ask

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

func (*SafeUi) Error

func (u *SafeUi) Error(s string)

func (*SafeUi) Machine

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

func (*SafeUi) Message

func (u *SafeUi) Message(s string)

func (*SafeUi) Say

func (u *SafeUi) Say(s string)

func (*SafeUi) TrackProgress

func (u *SafeUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser)

type SayMessage added in v0.0.10

type SayMessage struct {
	Message string
	SayTime time.Time
}

type ScriptUploadErrorMockCommunicator

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

type TTY

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

type Ui

type Ui interface {
	Ask(string) (string, error)
	Say(string)
	Message(string)
	Error(string)
	Machine(string, ...string)
	// TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser)
	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

func TestUi(t *testing.T) Ui

TestUi creates a simple UI for use in testing. It's not meant for "real" use.

Directories

Path Synopsis
registry
image
Package image allows for the management of image metadata that can be stored in a HCP Packer registry.
Package image allows for the management of image metadata that can be stored in a HCP Packer registry.

Jump to

Keyboard shortcuts

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