packer

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: MPL-2.0 Imports: 48 Imported by: 1,723

Documentation

Index

Constants

View Source
const (
	UiColorRed     UiColor = 31
	UiColorGreen           = 32
	UiColorYellow          = 33
	UiColorBlue            = 34
	UiColorMagenta         = 35
	UiColorCyan            = 36
)
View Source
const BuilderId = "packer.post-processor.packer-registry"
View Source
const PACKERSPACE = "-PACKERSPACE-"

PACKERSPACE is used to represent the spaces that separate args for a command without being confused with spaces in the path to the command itself.

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

Variables

View Source
var BuilderDataCommonKeys = []string{
	"ID",

	"Host",
	"Port",
	"User",
	"Password",
	"ConnType",
	"PackerRunUUID",
	"PackerHTTPPort",
	"PackerHTTPIP",
	"PackerHTTPAddr",
	"SSHPublicKey",
	"SSHPrivateKey",
	"WinRMPassword",
}

BuilderDataCommonKeys is the list of common keys that all builder will return

View Source
var ConsoleHelp = strings.TrimSpace(`
Packer console JSON Mode.
The Packer console allows you to experiment with Packer interpolations.
You may access variables in the Packer config you called the console with.

Type in the interpolation to test and hit <enter> to see the result.

"variables" will dump all available variables and their values.

"{{timestamp}}" will output the timestamp, for example "1559855090".

To exit the console, type "exit" and hit <enter>, or use Control-C.

/!\ If you would like to start console in hcl2 mode without a config you can
use the --config-type=hcl2 option.
`)
View Source
var ErrInterrupted = errors.New("interrupted")
View Source
var Killed = false

If this is true, then the "unexpected EOF" panic will not be raised throughout the clients.

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 CastDataToMap added in v1.5.0

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

func CleanupClients added in v1.7.0

func CleanupClients()

This makes sure all the managed subprocesses are killed and properly logged. This should be called before the parent process running the plugins exits.

This must only be called _once_.

func PluginFolders added in v1.7.0

func PluginFolders(dirs ...string) []string

PluginFolders returns the list of known plugin folders based on system.

func ProgressBarConfig added in v1.4.0

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

func TestBuilder added in v0.8.0

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

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

func TestProvisioner added in v0.8.0

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

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

func TestUi added in v0.8.0

func TestUi(t *testing.T) packersdk.Ui

Types

type BasicStore added in v1.5.0

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

type BuildGetter added in v1.6.0

type BuildGetter interface {
	// GetBuilds return all possible builds for a config. It also starts all
	// builders.
	// TODO(azr): rename to builder starter ?
	GetBuilds(GetBuildsOptions) ([]packersdk.Build, hcl.Diagnostics)
}

type BuilderFunc

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

The function type used to lookup Builder implementations.

type BuilderSet added in v1.7.0

type BuilderSet interface {
	BuilderStore
	Set(name string, starter func() (packersdk.Builder, error))
}

type BuilderStore added in v1.5.0

type BuilderStore interface {
	BasicStore
	Start(name string) (packersdk.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         packersdk.Ui
	PB         getter.ProgressTracker
}

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 (u *ColoredUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser

type ComponentFinder

type ComponentFinder struct {
	Hook         HookFunc
	PluginConfig *PluginConfig
}

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

type ConfigFixer added in v1.6.0

type ConfigFixer interface {
	// FixConfig will output the config in a fixed manner.
	FixConfig(FixConfigOptions) hcl.Diagnostics
}

type ConfigInspector added in v1.6.1

type ConfigInspector interface {
	// Inspect will output self inspection for a configuration
	InspectConfig(InspectConfigOptions) (ret int)
}

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

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) (packersdk.Build, error)

Build returns the Build object for the given name.

func (*Core) BuildNames added in v0.8.0

func (c *Core) BuildNames(only, except []string) []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.

func (*Core) EvaluateExpression added in v1.6.0

func (c *Core) EvaluateExpression(line string) (string, bool, hcl.Diagnostics)

func (*Core) FixConfig added in v1.6.0

func (c *Core) FixConfig(opts FixConfigOptions) hcl.Diagnostics

func (*Core) GetBuilds added in v1.6.0

func (c *Core) GetBuilds(opts GetBuildsOptions) ([]packersdk.Build, hcl.Diagnostics)

This is used for json templates to launch the build plugins. They will be prepared via b.Prepare() later.

func (*Core) GetRegistryBucket added in v1.7.5

func (c *Core) GetRegistryBucket() *packerregistry.Bucket

/ GetRegistryBucket returns a configured bucket that can be used for publishing build image artifacts to some HCP Packer Registry.

func (*Core) Initialize added in v1.6.1

func (core *Core) Initialize() error

func (*Core) InspectConfig added in v1.6.1

func (c *Core) InspectConfig(opts InspectConfigOptions) int

type CoreBuild added in v1.5.0

type CoreBuild struct {
	BuildName     string
	Type          string
	Builder       packersdk.Builder
	BuilderConfig interface{}
	BuilderType   string

	Provisioners       []CoreBuildProvisioner
	PostProcessors     [][]CoreBuildPostProcessor
	CleanupProvisioner CoreBuildProvisioner
	TemplatePath       string
	Variables          map[string]string

	// Indicates whether the build is already initialized before calling Prepare(..)
	Prepared bool
	// 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 packersdk.Ui) ([]packersdk.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 packersdk.PostProcessor
	PType         string
	PName         string

	KeepInputArtifact *bool
	// 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
	PName       string
	Provisioner packersdk.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 DatasourceSet added in v1.7.0

type DatasourceSet interface {
	DatasourceStore
	Set(name string, starter func() (packersdk.Datasource, error))
}

type DatasourceStore added in v1.7.0

type DatasourceStore interface {
	BasicStore
	Start(name string) (packersdk.Datasource, error)
}

type DebuggedProvisioner added in v1.2.5

type DebuggedProvisioner struct {
	Provisioner packersdk.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 packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error

type Evaluator added in v1.6.0

type Evaluator interface {
	// EvaluateExpression is meant to be used in the `packer console` command.
	// It parses the input string and returns what needs to be displayed. In
	// case of an error the error should be displayed.
	EvaluateExpression(expr string) (output string, exit bool, diags hcl.Diagnostics)
}

type FixConfigMode added in v1.6.0

type FixConfigMode int
const (
	// Stdout will make FixConfig simply print what the config should be; it
	// will only work when a single file is passed.
	Stdout FixConfigMode = iota
	// Inplace fixes your files on the spot.
	Inplace
	// Diff shows a full diff.
	Diff
)

func FixConfigModeString added in v1.6.0

func FixConfigModeString(s string) (FixConfigMode, error)

FixConfigModeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func FixConfigModeValues added in v1.6.0

func FixConfigModeValues() []FixConfigMode

FixConfigModeValues returns all values of the enum

func (FixConfigMode) IsAFixConfigMode added in v1.6.0

func (i FixConfigMode) IsAFixConfigMode() bool

IsAFixConfigMode returns "true" if the value is listed in the enum definition. "false" otherwise

func (FixConfigMode) String added in v1.6.0

func (i FixConfigMode) String() string

type FixConfigOptions added in v1.6.0

type FixConfigOptions struct {
	Mode FixConfigMode
}

type FlatMockPostProcessor added in v1.5.0

type FlatMockPostProcessor struct {
	ArtifactId          *string         `cty:"artifact_id" hcl:"artifact_id"`
	Keep                *bool           `cty:"keep" hcl:"keep"`
	ForceOverride       *bool           `cty:"force_override" hcl:"force_override"`
	Error               error           `cty:"error" hcl:"error"`
	ConfigureCalled     *bool           `cty:"configure_called" hcl:"configure_called"`
	ConfigureConfigs    []interface{}   `cty:"configure_configs" hcl:"configure_configs"`
	ConfigureError      error           `cty:"configure_error" hcl:"configure_error"`
	PostProcessCalled   *bool           `cty:"post_process_called" hcl:"post_process_called"`
	PostProcessArtifact packer.Artifact `cty:"post_process_artifact" hcl:"post_process_artifact"`
	PostProcessUi       packer.Ui       `cty:"post_process_ui" hcl:"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 GetBuildsOptions added in v1.6.0

type GetBuildsOptions struct {
	// Get builds except the ones that match with except and with only the ones
	// that match with Only. When those are empty everything matches.
	Except, Only []string
	Debug, Force bool
	OnError      string

	// count only/except match count; so say something when nothing matched.
	ExceptMatches, OnlyMatches int
}

type HCPHandler added in v1.7.5

type HCPHandler interface {
	// ConfiguredArtifactMetadataPublisher returns a configured Bucket that can be used to publish
	// build artifacts to the said image bucket.
	ConfiguredArtifactMetadataPublisher() (*packerregistry.Bucket, hcl.Diagnostics)
}

The HCPHandler handles Packer things needed for communicating with a HCP Packer Registry.

type Handler added in v1.6.0

type Handler interface {
	Initialize(InitializeOptions) hcl.Diagnostics
	// PluginRequirements returns the list of plugin Requirements from the
	// config file.
	PluginRequirements() (plugingetter.Requirements, hcl.Diagnostics)
	Evaluator
	BuildGetter
	ConfigFixer
	ConfigInspector
	HCPHandler
}

The Handler handles all Packer things. This interface reflects the Packer commands, ex: init, console ( evaluate ), fix config, inspect config, etc. To run a build we will start the builds and then the core of Packer handles execution.

type HookFunc

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

The function type used to lookup Hook implementations.

type HookedProvisioner added in v1.1.2

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

A HookedProvisioner represents a provisioner and information describing it

type InitializeOptions added in v1.7.0

type InitializeOptions struct {
	// When set, the execution of datasources will be skipped and the datasource will provide
	// an output spec that will be used for validation only.
	SkipDatasourcesExecution bool
}

type InspectConfigOptions added in v1.6.1

type InspectConfigOptions struct {
	packersdk.Ui
}

type MachineReadableUi added in v0.3.0

type MachineReadableUi struct {
	Writer io.Writer
	PB     packersdk.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)

func (*MachineReadableUi) TrackProgress added in v1.6.3

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

type MapOfBuilder added in v1.5.0

type MapOfBuilder map[string]func() (packersdk.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) Set added in v1.7.0

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

func (MapOfBuilder) Start added in v1.5.0

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

type MapOfDatasource added in v1.7.0

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

func (MapOfDatasource) Has added in v1.7.0

func (mod MapOfDatasource) Has(dataSource string) bool

func (MapOfDatasource) List added in v1.7.0

func (mod MapOfDatasource) List() []string

func (MapOfDatasource) Set added in v1.7.0

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

func (MapOfDatasource) Start added in v1.7.0

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

type MapOfPostProcessor added in v1.5.0

type MapOfPostProcessor map[string]func() (packersdk.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) Set added in v1.7.0

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

func (MapOfPostProcessor) Start added in v1.5.0

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

type MapOfProvisioner added in v1.5.0

type MapOfProvisioner map[string]func() (packersdk.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) Set added in v1.7.0

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

func (MapOfProvisioner) Start added in v1.5.0

func (mop MapOfProvisioner) Start(provisioner string) (packersdk.Provisioner, 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 packersdk.Artifact
	PostProcessUi       packersdk.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

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 packersdk.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 packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error

type PluginClient added in v1.7.0

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

Client handles the lifecycle of a plugin application, determining its RPC address, and returning various types of packer interface implementations across the multi-process communication layer.

func NewClient added in v1.7.0

func NewClient(config *PluginClientConfig) (c *PluginClient)

Creates a new plugin client which manages the lifecycle of an external plugin and gets the address for the RPC connection.

The client must be cleaned up at some point by calling Kill(). If the client is a managed client (created with NewManagedClient) you can just call CleanupClients at the end of your program and they will be properly cleaned.

func (*PluginClient) Builder added in v1.7.0

func (c *PluginClient) Builder() (packersdk.Builder, error)

Returns a builder implementation that is communicating over this client. If the client hasn't been started, this will start it.

func (*PluginClient) Client added in v1.7.0

func (c *PluginClient) Client() (*packerrpc.Client, error)

func (*PluginClient) Datasource added in v1.7.0

func (c *PluginClient) Datasource() (packersdk.Datasource, error)

Returns a data source implementation that is communicating over this client. If the client hasn't been started, this will start it.

func (*PluginClient) Exited added in v1.7.0

func (c *PluginClient) Exited() bool

Tells whether or not the underlying process has exited.

func (*PluginClient) Hook added in v1.7.0

func (c *PluginClient) Hook() (packersdk.Hook, error)

Returns a hook implementation that is communicating over this client. If the client hasn't been started, this will start it.

func (*PluginClient) Kill added in v1.7.0

func (c *PluginClient) Kill()

End the executing subprocess (if it is running) and perform any cleanup tasks necessary such as capturing any remaining logs and so on.

This method blocks until the process successfully exits.

This method can safely be called multiple times.

func (*PluginClient) PostProcessor added in v1.7.0

func (c *PluginClient) PostProcessor() (packersdk.PostProcessor, error)

Returns a post-processor implementation that is communicating over this client. If the client hasn't been started, this will start it.

func (*PluginClient) Provisioner added in v1.7.0

func (c *PluginClient) Provisioner() (packersdk.Provisioner, error)

Returns a provisioner implementation that is communicating over this client. If the client hasn't been started, this will start it.

func (*PluginClient) Start added in v1.7.0

func (c *PluginClient) Start() (net.Addr, error)

Starts the underlying subprocess, communicating with it to negotiate a port for RPC connections, and returning the address to connect via RPC.

This method is safe to call multiple times. Subsequent calls have no effect. Once a client has been started once, it cannot be started again, even if it was killed.

type PluginClientConfig added in v1.7.0

type PluginClientConfig struct {
	// The unstarted subprocess for starting the plugin.
	Cmd *exec.Cmd

	// Managed represents if the client should be managed by the
	// plugin package or not. If true, then by calling CleanupClients,
	// it will automatically be cleaned up. Otherwise, the client
	// user is fully responsible for making sure to Kill all plugin
	// clients. By default the client is _not_ managed.
	Managed bool

	// The minimum and maximum port to use for communicating with
	// the subprocess. If not set, this defaults to 10,000 and 25,000
	// respectively.
	MinPort, MaxPort int

	// StartTimeout is the timeout to wait for the plugin to say it
	// has started successfully.
	StartTimeout time.Duration

	// If non-nil, then the stderr of the client will be written to here
	// (as well as the log).
	Stderr io.Writer
}

PluginClientConfig is the configuration used to initialize a new plugin client. After being used to initialize a plugin client, that configuration must not be modified again.

type PluginConfig added in v1.7.0

type PluginConfig struct {
	KnownPluginFolders []string
	PluginMinPort      int
	PluginMaxPort      int
	Builders           BuilderSet
	Provisioners       ProvisionerSet
	PostProcessors     PostProcessorSet
	DataSources        DatasourceSet

	// Redirects are only set when a plugin was completely moved out; they allow
	// telling where a plugin has moved by checking if a known component of this
	// plugin is used. For example implicitly require the
	// github.com/hashicorp/amazon plugin if it was moved out and the
	// "amazon-ebs" plugin is used, but not found.
	//
	// Redirects will be bypassed if the redirected components are already found
	// in their corresponding sets (Builders, Provisioners, PostProcessors,
	// DataSources). That is, for example, if you manually put a single
	// component plugin in the plugins folder.
	//
	// Example BuilderRedirects: "amazon-ebs" => "github.com/hashicorp/amazon"
	BuilderRedirects       map[string]string
	DatasourceRedirects    map[string]string
	ProvisionerRedirects   map[string]string
	PostProcessorRedirects map[string]string
}

PluginConfig helps load and use packer plugins

func (*PluginConfig) Client added in v1.7.0

func (c *PluginConfig) Client(path string, args ...string) *PluginClient

func (*PluginConfig) Discover added in v1.7.0

func (c *PluginConfig) Discover() error

Discover discovers plugins.

Search the directory of the executable, then the plugins directory, and finally the CWD, in that order. Any conflicts will overwrite previously found plugins, in that order. Hence, the priority order is the reverse of the search order - i.e., the CWD has the highest priority.

func (*PluginConfig) DiscoverMultiPlugin added in v1.7.0

func (c *PluginConfig) DiscoverMultiPlugin(pluginName, pluginPath string) error

DiscoverMultiPlugin takes the description from a multi-component plugin binary and makes the plugins available to use in Packer. Each plugin found in the binary will be addressable using `${pluginName}-${builderName}` for example. pluginName could be manually set. It usually is a cloud name like amazon. pluginName can be extrapolated from the filename of the binary; so if the "packer-plugin-amazon" binary had an "ebs" builder one could use the "amazon-ebs" builder.

type PostProcessorFunc

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

The function type used to lookup PostProcessor implementations.

type PostProcessorSet added in v1.7.0

type PostProcessorSet interface {
	PostProcessorStore
	Set(name string, starter func() (packersdk.PostProcessor, error))
}

type PostProcessorStore added in v1.5.0

type PostProcessorStore interface {
	BasicStore
	Start(name string) (packersdk.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 packersdk.Ui, comm packersdk.Communicator, data interface{}) error

Runs the provisioners in order.

type ProvisionerFunc

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

The function type used to lookup Provisioner implementations.

type ProvisionerSet added in v1.7.0

type ProvisionerSet interface {
	ProvisionerStore
	Set(name string, starter func() (packersdk.Provisioner, error))
}

type ProvisionerStore added in v1.5.0

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

type RegistryArtifact added in v1.7.5

type RegistryArtifact struct {
	BucketSlug  string
	IterationID string
	BuildName   string
}

func (*RegistryArtifact) BuilderId added in v1.7.5

func (a *RegistryArtifact) BuilderId() string

func (*RegistryArtifact) Destroy added in v1.7.5

func (a *RegistryArtifact) Destroy() error

func (*RegistryArtifact) Files added in v1.7.5

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

func (*RegistryArtifact) Id added in v1.7.5

func (*RegistryArtifact) Id() string

func (*RegistryArtifact) State added in v1.7.5

func (*RegistryArtifact) State(name string) interface{}

func (*RegistryArtifact) String added in v1.7.5

func (a *RegistryArtifact) String() string

type RegistryBuilder added in v1.7.5

type RegistryBuilder struct {
	Name                      string
	ArtifactMetadataPublisher *packerregistry.Bucket
	packersdk.Builder
}

func (*RegistryBuilder) Prepare added in v1.7.5

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

func (*RegistryBuilder) Run added in v1.7.5

Run is where the actual build should take place. It takes a Build and a Ui.

type RegistryPostProcessor added in v1.7.5

type RegistryPostProcessor struct {
	BuilderType               string
	ArtifactMetadataPublisher *packerregistry.Bucket
	packersdk.PostProcessor
}

func (*RegistryPostProcessor) ConfigSpec added in v1.7.5

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

func (*RegistryPostProcessor) Configure added in v1.7.5

func (p *RegistryPostProcessor) Configure(raws ...interface{}) error

func (*RegistryPostProcessor) PostProcess added in v1.7.5

type RetriedProvisioner added in v1.5.6

type RetriedProvisioner struct {
	MaxRetries  int
	Provisioner packersdk.Provisioner
}

RetriedProvisioner is a Provisioner implementation that retries the provisioner whenever there's an error.

func (*RetriedProvisioner) ConfigSpec added in v1.5.6

func (r *RetriedProvisioner) ConfigSpec() hcldec.ObjectSpec

func (*RetriedProvisioner) FlatConfig added in v1.5.6

func (r *RetriedProvisioner) FlatConfig() interface{}

func (*RetriedProvisioner) Prepare added in v1.5.6

func (r *RetriedProvisioner) Prepare(raws ...interface{}) error

func (*RetriedProvisioner) Provision added in v1.5.6

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

type TargetedUI added in v1.0.0

type TargetedUI struct {
	Target string
	Ui     packersdk.Ui
}

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 (u *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 {
	packersdk.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 packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error

type TimestampedUi added in v1.3.2

type TimestampedUi struct {
	Ui packersdk.Ui
	PB getter.ProgressTracker
}

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 (u *TimestampedUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser)

type UiColor

type UiColor uint

type UiProgressBar added in v1.6.3

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

UiProgressBar is a progress bar compatible with go-getter used in our UI structs.

func (*UiProgressBar) TrackProgress added in v1.6.3

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

Directories

Path Synopsis
Package plugingetter defines means to download and install plugins.
Package plugingetter defines means to download and install plugins.

Jump to

Keyboard shortcuts

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