Commit d500bda9 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

website: update docs for new builder interface

parent 8217e64a
...@@ -29,16 +29,21 @@ supposed to do. ...@@ -29,16 +29,21 @@ supposed to do.
<pre class="prettyprint"> <pre class="prettyprint">
type Builder interface { type Builder interface {
// Prepare is responsible for reading in some configuration, in the raw form // Prepare is responsible for configuring the builder and validating
// of map[string]interface{}, and storing that state for use later. Any setup // that configuration. Any setup should be done in this method. Note that
// should be done in this method. Note that NO side effects should really take // NO side effects should take place in prepare, it is meant as a state
// place in prepare. It is meant as a state setup step only. // setup only. Calling Prepare is not necessarilly followed by a Run.
Prepare(config interface{}) error //
// The parameters to Prepare are a set of interface{} values of the
// Run is where the actual build should take place. It takes a Ui to // configuration. These are almost always `map[string]interface{}`
// send messages to the user, Hook to execute hooks, and Cache in order // parsed from a template, but no guarantee is made.
// to save files across runs. //
Run(Ui, Hook, Cache) (Artifact, error) // Each of the configuration values should merge into the final
// configuration.
Prepare(...interface{}) error
// Run is where the actual build should take place. It takes a Build and a Ui.
Run(ui Ui, hook Hook, cache Cache) (Artifact, error)
// Cancel cancels a possibly running Builder. This should block until // Cancel cancels a possibly running Builder. This should block until
// the builder actually cancels and cleans up after itself. // the builder actually cancels and cleans up after itself.
...@@ -50,10 +55,14 @@ type Builder interface { ...@@ -50,10 +55,14 @@ type Builder interface {
The `Prepare` method for each builder is called prior to any runs with The `Prepare` method for each builder is called prior to any runs with
the configuration that was given in the template. This is passed in as the configuration that was given in the template. This is passed in as
an `interface{}` type, but is generally `map[string]interface{}`. The prepare an array of `interface{}` types, but is generally `map[string]interface{}`. The prepare
method is responsible for translating this configuration into an internal method is responsible for translating this configuration into an internal
structure, validating it, and returning any errors. structure, validating it, and returning any errors.
For multiple parameters, they should be merged together into the final
configuration, with later parameters overwriting any previous configuration.
The exact semantics of the merge are left to the builder author.
For decoding the `interface{}` into a meaningful structure, the For decoding the `interface{}` into a meaningful structure, the
[mapstructure](https://github.com/mitchellh/mapstructure) library is recommended. [mapstructure](https://github.com/mitchellh/mapstructure) library is recommended.
Mapstructure will take an `interface{}` and decode it into an arbitrarily Mapstructure will take an `interface{}` and decode it into an arbitrarily
...@@ -65,6 +74,14 @@ running the `Prepare` method. Specifically, don't create files, don't launch ...@@ -65,6 +74,14 @@ running the `Prepare` method. Specifically, don't create files, don't launch
virtual machines, etc. Prepare's purpose is solely to configure the builder virtual machines, etc. Prepare's purpose is solely to configure the builder
and validate the configuration. and validate the configuration.
In addition to normal configuration, Packer will inject a `map[string]interface{}`
with a key of `packer.DebugConfigKey` set to boolean `true` if debug mode
is enabled for the build. If this is set to true, then the builder
should enable a debug mode which assists 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.
### The "Run" Method ### The "Run" Method
`Run` is where all the interesting stuff happens. Run is executed, often `Run` is where all the interesting stuff happens. Run is executed, often
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment