[lxc] update to new conventions, improve docs
This commit is contained in:
parent
34b6c97c21
commit
cd2a783382
|
@ -2,14 +2,13 @@ package lxc
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/hashicorp/packer/common"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/template/interpolate"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/common"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"github.com/mitchellh/packer/template/interpolate"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// The unique ID for this builder
|
||||
|
@ -35,10 +34,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||
}
|
||||
|
||||
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
||||
if runtime.GOOS != "linux" {
|
||||
return nil, errors.New("The lxc builder only works on linux environments.")
|
||||
}
|
||||
|
||||
wrappedCommand := func(command string) (string, error) {
|
||||
b.config.ctx.Data = &wrappedCommandTemplate{Command: command}
|
||||
return interpolate.Render(b.config.CommandWrapper, &b.config.ctx)
|
||||
|
@ -63,15 +58,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
state.Put("wrappedCommand", CommandWrapper(wrappedCommand))
|
||||
|
||||
// Run
|
||||
if b.config.PackerDebug {
|
||||
b.runner = &multistep.DebugRunner{
|
||||
Steps: steps,
|
||||
PauseFn: common.MultistepDebugFn(ui),
|
||||
}
|
||||
} else {
|
||||
b.runner = &multistep.BasicRunner{Steps: steps}
|
||||
}
|
||||
|
||||
b.runner = common.NewRunnerWithPauseFn(steps, b.config.PackerConfig, ui, state)
|
||||
b.runner.Run(state)
|
||||
|
||||
// If there was an error, return that
|
||||
|
@ -79,15 +66,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
return nil, rawErr.(error)
|
||||
}
|
||||
|
||||
// If we were interrupted or cancelled, then just exit.
|
||||
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
||||
return nil, errors.New("Build was cancelled.")
|
||||
}
|
||||
|
||||
if _, ok := state.GetOk(multistep.StateHalted); ok {
|
||||
return nil, errors.New("Build was halted.")
|
||||
}
|
||||
|
||||
// Compile the artifact list
|
||||
files := make([]string, 0, 5)
|
||||
visit := func(path string, info os.FileInfo, err error) error {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/packer/builder/lxc"
|
||||
"github.com/mitchellh/packer/packer/plugin"
|
||||
"github.com/hashicorp/packer/builder/lxc"
|
||||
"github.com/hashicorp/packer/packer/plugin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
package main
|
|
@ -85,13 +85,13 @@ Below is a fully functioning example.
|
|||
|
||||
- `target_runlevel` (int) - The minimum run level to wait for the container to reach. Note some distributions (Ubuntu) simulate run levels and may report 5 rather than 3.
|
||||
|
||||
- `output_directory` (string) - The directory in which to save the exported tar.gz.
|
||||
- `output_directory` (string) - The directory in which to save the exported tar.gz. Defaults to `output-<BuildName>` in the current directory.
|
||||
|
||||
- `container_name` (string) - The name of the LXC container. Usually `/var/lib/lxc/containers/<container_name>`.
|
||||
- `container_name` (string) - The name of the LXC container. Usually stored in `/var/lib/lxc/containers/<container_name>`. Defaults to `packer-<BuildName>`.
|
||||
|
||||
- `command_wrapper` (string) - Allows you to specify a wrapper command, such as `ssh` so you can execute packer builds on a remote host.
|
||||
- `command_wrapper` (string) - Allows you to specify a wrapper command, such as `ssh` so you can execute packer builds on a remote host. Defaults to Empty.
|
||||
|
||||
- `init_timeout` (string) - The timeout in seconds to wait for the the container to start.
|
||||
- `init_timeout` (string) - The timeout in seconds to wait for the the container to start. Defaults to 20 seconds.
|
||||
|
||||
- `template_parameters` (array of strings) - Options to pass to the given `lxc-template` command, usually located in `/usr/share/lxc/templates/lxc-<template_name>``. Note: This gets passed as ARGV to the template command. Ensure you have an array of strings, as a single string with spaces probably won't work.
|
||||
- `template_parameters` (array of strings) - Options to pass to the given `lxc-template` command, usually located in `/usr/share/lxc/templates/lxc-<template_name>``. Note: This gets passed as ARGV to the template command. Ensure you have an array of strings, as a single string with spaces probably won't work. Defaults to `[]`.
|
||||
|
||||
|
|
Loading…
Reference in New Issue