2014-10-27 23:21:13 -04:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2019-03-22 09:53:28 -04:00
|
|
|
"context"
|
2014-10-27 23:21:13 -04:00
|
|
|
"fmt"
|
|
|
|
"log"
|
2019-04-13 08:24:35 -04:00
|
|
|
"math"
|
2014-10-27 23:21:13 -04:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
2020-08-11 14:22:40 -04:00
|
|
|
"time"
|
2015-05-23 19:30:45 -04:00
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
|
|
"github.com/hashicorp/hcl/v2/hclparse"
|
|
|
|
"github.com/hashicorp/packer/hcl2template"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/hashicorp/packer/template"
|
2019-04-13 08:24:35 -04:00
|
|
|
"golang.org/x/sync/semaphore"
|
2017-10-13 14:42:22 -04:00
|
|
|
|
2020-08-11 14:22:40 -04:00
|
|
|
"github.com/hako/durafmt"
|
2017-10-13 14:42:22 -04:00
|
|
|
"github.com/posener/complete"
|
2014-10-27 23:21:13 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type BuildCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
2017-10-13 14:41:42 -04:00
|
|
|
func (c *BuildCommand) Run(args []string) int {
|
2020-05-12 05:24:22 -04:00
|
|
|
ctx, cleanup := handleTermInterrupt(c.Ui)
|
2020-05-08 06:05:14 -04:00
|
|
|
defer cleanup()
|
2019-05-06 06:19:59 -04:00
|
|
|
|
2020-05-08 06:05:14 -04:00
|
|
|
cfg, ret := c.ParseArgs(args)
|
|
|
|
if ret != 0 {
|
|
|
|
return ret
|
|
|
|
}
|
2019-05-06 06:19:59 -04:00
|
|
|
|
2020-05-12 05:24:22 -04:00
|
|
|
return c.RunContext(ctx, cfg)
|
2019-05-07 05:43:18 -04:00
|
|
|
}
|
|
|
|
|
2020-05-08 10:41:47 -04:00
|
|
|
func (c *BuildCommand) ParseArgs(args []string) (*BuildArgs, int) {
|
2020-05-08 11:46:33 -04:00
|
|
|
var cfg BuildArgs
|
2015-05-23 19:30:45 -04:00
|
|
|
flags := c.Meta.FlagSet("build", FlagSetBuildFilter|FlagSetVars)
|
|
|
|
flags.Usage = func() { c.Ui.Say(c.Help()) }
|
2020-05-08 10:41:47 -04:00
|
|
|
cfg.AddFlagSets(flags)
|
2015-05-23 19:30:45 -04:00
|
|
|
if err := flags.Parse(args); err != nil {
|
2020-05-08 11:46:33 -04:00
|
|
|
return &cfg, 1
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
|
2019-05-07 05:43:18 -04:00
|
|
|
if cfg.ParallelBuilds < 1 {
|
|
|
|
cfg.ParallelBuilds = math.MaxInt64
|
|
|
|
}
|
|
|
|
|
2019-05-07 05:51:21 -04:00
|
|
|
args = flags.Args()
|
|
|
|
if len(args) != 1 {
|
2015-05-23 19:30:45 -04:00
|
|
|
flags.Usage()
|
2020-05-08 11:46:33 -04:00
|
|
|
return &cfg, 1
|
2019-05-07 05:43:18 -04:00
|
|
|
}
|
2019-05-07 05:51:21 -04:00
|
|
|
cfg.Path = args[0]
|
2020-05-08 11:46:33 -04:00
|
|
|
return &cfg, 0
|
2019-05-07 05:43:18 -04:00
|
|
|
}
|
|
|
|
|
2020-06-05 11:23:54 -04:00
|
|
|
func (m *Meta) GetConfigFromHCL(cla *MetaArgs) (*hcl2template.PackerConfig, int) {
|
2019-12-17 05:25:56 -05:00
|
|
|
parser := &hcl2template.Parser{
|
|
|
|
Parser: hclparse.NewParser(),
|
2020-04-30 10:36:01 -04:00
|
|
|
BuilderSchemas: m.CoreConfig.Components.BuilderStore,
|
|
|
|
ProvisionersSchemas: m.CoreConfig.Components.ProvisionerStore,
|
|
|
|
PostProcessorsSchemas: m.CoreConfig.Components.PostProcessorStore,
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
2020-05-11 11:56:14 -04:00
|
|
|
cfg, diags := parser.Parse(cla.Path, cla.VarFiles, cla.Vars)
|
2020-05-08 10:41:47 -04:00
|
|
|
return cfg, writeDiags(m.Ui, parser.Files(), diags)
|
|
|
|
}
|
2019-12-17 05:25:56 -05:00
|
|
|
|
2020-05-08 10:41:47 -04:00
|
|
|
func writeDiags(ui packer.Ui, files map[string]*hcl.File, diags hcl.Diagnostics) int {
|
|
|
|
// write HCL errors/diagnostics if any.
|
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
err := hcl.NewDiagnosticTextWriter(b, files, 80, false).WriteDiagnostics(diags)
|
|
|
|
if err != nil {
|
|
|
|
ui.Error("could not write diagnostic: " + err.Error())
|
|
|
|
return 1
|
2019-12-17 05:25:56 -05:00
|
|
|
}
|
2020-05-08 10:41:47 -04:00
|
|
|
if b.Len() != 0 {
|
2020-04-30 10:36:01 -04:00
|
|
|
if diags.HasErrors() {
|
2020-05-08 10:41:47 -04:00
|
|
|
ui.Error(b.String())
|
|
|
|
return 1
|
2020-04-29 10:36:40 -04:00
|
|
|
}
|
2020-05-08 10:41:47 -04:00
|
|
|
ui.Say(b.String())
|
2019-12-17 05:25:56 -05:00
|
|
|
}
|
2020-05-08 10:41:47 -04:00
|
|
|
return 0
|
2019-12-17 05:25:56 -05:00
|
|
|
}
|
|
|
|
|
2020-06-05 11:23:54 -04:00
|
|
|
func (m *Meta) GetConfig(cla *MetaArgs) (packer.Handler, int) {
|
|
|
|
cfgType, err := cla.GetConfigType()
|
2020-05-08 10:41:47 -04:00
|
|
|
if err != nil {
|
2020-06-05 11:23:54 -04:00
|
|
|
m.Ui.Error(fmt.Sprintf("%q: %s", cla.Path, err))
|
2019-12-17 05:25:56 -05:00
|
|
|
return nil, 1
|
|
|
|
}
|
|
|
|
|
2020-05-08 10:41:47 -04:00
|
|
|
switch cfgType {
|
2020-06-05 11:23:54 -04:00
|
|
|
case ConfigTypeHCL2:
|
2020-05-08 10:41:47 -04:00
|
|
|
// TODO(azr): allow to pass a slice of files here.
|
2020-05-11 11:56:14 -04:00
|
|
|
return m.GetConfigFromHCL(cla)
|
2020-05-08 10:41:47 -04:00
|
|
|
default:
|
|
|
|
// TODO: uncomment once we've polished HCL a bit more.
|
|
|
|
// c.Ui.Say(`Legacy JSON Configuration Will Be Used.
|
|
|
|
// The template will be parsed in the legacy configuration style. This style
|
|
|
|
// will continue to work but users are encouraged to move to the new style.
|
|
|
|
// See: https://packer.io/guides/hcl
|
|
|
|
// `)
|
2020-05-12 05:24:22 -04:00
|
|
|
return m.GetConfigFromJSON(cla)
|
2020-05-08 10:41:47 -04:00
|
|
|
}
|
2020-04-30 10:36:01 -04:00
|
|
|
}
|
2019-12-17 05:25:56 -05:00
|
|
|
|
2020-07-24 04:58:03 -04:00
|
|
|
func (m *Meta) GetConfigFromJSON(cla *MetaArgs) (packer.Handler, int) {
|
2015-05-23 19:30:45 -04:00
|
|
|
// Parse the template
|
2020-06-05 11:23:54 -04:00
|
|
|
var tpl *template.Template
|
|
|
|
var err error
|
|
|
|
if cla.Path == "" {
|
|
|
|
// here cla validation passed so this means we want a default builder
|
|
|
|
// and we probably are in the console command
|
|
|
|
tpl, err = template.Parse(TiniestBuilder)
|
|
|
|
} else {
|
|
|
|
tpl, err = template.ParseFile(cla.Path)
|
|
|
|
}
|
|
|
|
|
2014-10-27 23:21:13 -04:00
|
|
|
if err != nil {
|
2020-04-30 10:36:01 -04:00
|
|
|
m.Ui.Error(fmt.Sprintf("Failed to parse template: %s", err))
|
2019-12-17 05:25:56 -05:00
|
|
|
return nil, 1
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
|
2015-05-23 19:30:45 -04:00
|
|
|
// Get the core
|
2020-05-12 05:24:22 -04:00
|
|
|
core, err := m.Core(tpl, cla)
|
2019-12-17 05:25:56 -05:00
|
|
|
ret := 0
|
2014-10-27 23:21:13 -04:00
|
|
|
if err != nil {
|
2020-04-30 10:36:01 -04:00
|
|
|
m.Ui.Error(err.Error())
|
2020-04-30 10:40:16 -04:00
|
|
|
ret = 1
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
2020-07-24 04:58:03 -04:00
|
|
|
return &CoreWrapper{core}, ret
|
2019-12-17 05:25:56 -05:00
|
|
|
}
|
|
|
|
|
2020-05-11 11:56:14 -04:00
|
|
|
func (c *BuildCommand) RunContext(buildCtx context.Context, cla *BuildArgs) int {
|
|
|
|
packerStarter, ret := c.GetConfig(&cla.MetaArgs)
|
2019-12-17 05:25:56 -05:00
|
|
|
if ret != 0 {
|
|
|
|
return ret
|
|
|
|
}
|
2020-07-24 04:58:03 -04:00
|
|
|
diags := packerStarter.Initialize()
|
|
|
|
ret = writeDiags(c.Ui, nil, diags)
|
|
|
|
if ret != 0 {
|
|
|
|
return ret
|
|
|
|
}
|
2019-12-17 05:25:56 -05:00
|
|
|
|
2020-05-08 10:41:47 -04:00
|
|
|
builds, diags := packerStarter.GetBuilds(packer.GetBuildsOptions{
|
2020-05-14 19:22:51 -04:00
|
|
|
Only: cla.Only,
|
|
|
|
Except: cla.Except,
|
|
|
|
Debug: cla.Debug,
|
|
|
|
Force: cla.Force,
|
|
|
|
OnError: cla.OnError,
|
2020-04-30 10:36:01 -04:00
|
|
|
})
|
2014-10-27 23:21:13 -04:00
|
|
|
|
2020-05-08 12:01:34 -04:00
|
|
|
// here, something could have gone wrong but we still want to run valid
|
|
|
|
// builds.
|
|
|
|
ret = writeDiags(c.Ui, nil, diags)
|
2014-10-27 23:21:13 -04:00
|
|
|
|
2020-05-11 11:56:14 -04:00
|
|
|
if cla.Debug {
|
2015-05-23 19:30:45 -04:00
|
|
|
c.Ui.Say("Debug mode enabled. Builds will not be parallelized.")
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compile all the UIs for the builds
|
|
|
|
colors := [5]packer.UiColor{
|
|
|
|
packer.UiColorGreen,
|
|
|
|
packer.UiColorCyan,
|
|
|
|
packer.UiColorMagenta,
|
|
|
|
packer.UiColorYellow,
|
|
|
|
packer.UiColorBlue,
|
|
|
|
}
|
2019-12-17 05:25:56 -05:00
|
|
|
buildUis := make(map[packer.Build]packer.Ui)
|
|
|
|
for i := range builds {
|
|
|
|
ui := c.Ui
|
2020-05-11 11:56:14 -04:00
|
|
|
if cla.Color {
|
2020-06-17 14:57:12 -04:00
|
|
|
// Only set up UI colors if -machine-readable isn't set.
|
2017-02-09 20:41:42 -05:00
|
|
|
if _, ok := c.Ui.(*packer.MachineReadableUi); !ok {
|
2020-06-17 14:57:12 -04:00
|
|
|
ui = &packer.ColoredUi{
|
|
|
|
Color: colors[i%len(colors)],
|
|
|
|
Ui: ui,
|
|
|
|
}
|
2019-12-17 05:25:56 -05:00
|
|
|
ui.Say(fmt.Sprintf("%s: output will be in this color.", builds[i].Name()))
|
|
|
|
if i+1 == len(builds) {
|
2017-02-09 20:45:42 -05:00
|
|
|
// Add a newline between the color output and the actual output
|
|
|
|
c.Ui.Say("")
|
|
|
|
}
|
2019-06-19 09:04:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now add timestamps if requested
|
2020-05-11 11:56:14 -04:00
|
|
|
if cla.TimestampUi {
|
2019-06-19 09:04:13 -04:00
|
|
|
ui = &packer.TimestampedUi{
|
|
|
|
Ui: ui,
|
2017-02-09 20:41:42 -05:00
|
|
|
}
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
buildUis[builds[i]] = ui
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
|
2020-05-11 11:56:14 -04:00
|
|
|
log.Printf("Build debug mode: %v", cla.Debug)
|
|
|
|
log.Printf("Force build: %v", cla.Force)
|
|
|
|
log.Printf("On error: %v", cla.OnError)
|
2014-10-27 23:21:13 -04:00
|
|
|
|
2020-08-11 14:22:40 -04:00
|
|
|
// Get the start of the build command
|
|
|
|
buildCommandStart := time.Now()
|
|
|
|
|
2014-10-27 23:21:13 -04:00
|
|
|
// Run all the builds in parallel and wait for them to complete
|
2019-05-06 06:19:59 -04:00
|
|
|
var wg sync.WaitGroup
|
2015-10-14 11:25:13 -04:00
|
|
|
var artifacts = struct {
|
|
|
|
sync.RWMutex
|
|
|
|
m map[string][]packer.Artifact
|
|
|
|
}{m: make(map[string][]packer.Artifact)}
|
2019-12-17 05:25:56 -05:00
|
|
|
// Get the builds we care about
|
|
|
|
var errors = struct {
|
|
|
|
sync.RWMutex
|
|
|
|
m map[string]error
|
|
|
|
}{m: make(map[string]error)}
|
2020-05-11 11:56:14 -04:00
|
|
|
limitParallel := semaphore.NewWeighted(cla.ParallelBuilds)
|
2019-05-02 10:34:48 -04:00
|
|
|
for i := range builds {
|
2019-05-06 06:19:59 -04:00
|
|
|
if err := buildCtx.Err(); err != nil {
|
|
|
|
log.Println("Interrupted, not going to start any more builds.")
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2019-05-02 10:34:48 -04:00
|
|
|
b := builds[i]
|
|
|
|
name := b.Name()
|
2019-12-17 05:25:56 -05:00
|
|
|
ui := buildUis[b]
|
2019-05-02 10:34:48 -04:00
|
|
|
if err := limitParallel.Acquire(buildCtx, 1); err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Build '%s' failed to acquire semaphore: %s", name, err))
|
2019-05-06 09:42:23 -04:00
|
|
|
errors.Lock()
|
|
|
|
errors.m[name] = err
|
|
|
|
errors.Unlock()
|
2019-05-02 10:34:48 -04:00
|
|
|
break
|
|
|
|
}
|
2019-05-03 01:46:26 -04:00
|
|
|
// Increment the waitgroup so we wait for this item to finish properly
|
|
|
|
wg.Add(1)
|
2014-10-27 23:21:13 -04:00
|
|
|
|
|
|
|
// Run the build in a goroutine
|
2019-05-02 10:34:48 -04:00
|
|
|
go func() {
|
2020-08-11 14:22:40 -04:00
|
|
|
// Get the start of the build
|
|
|
|
buildStart := time.Now()
|
|
|
|
|
2014-10-27 23:21:13 -04:00
|
|
|
defer wg.Done()
|
|
|
|
|
2019-04-19 03:10:36 -04:00
|
|
|
defer limitParallel.Release(1)
|
|
|
|
|
|
|
|
log.Printf("Starting build run: %s", name)
|
2019-03-22 09:53:28 -04:00
|
|
|
runArtifacts, err := b.Run(buildCtx, ui)
|
2014-10-27 23:21:13 -04:00
|
|
|
|
2020-08-11 14:22:40 -04:00
|
|
|
// Get the duration of the build and parse it
|
|
|
|
buildEnd := time.Now()
|
|
|
|
buildDuration := buildEnd.Sub(buildStart)
|
|
|
|
fmtBuildDuration := durafmt.Parse(buildDuration).LimitFirstN(2)
|
|
|
|
|
2014-10-27 23:21:13 -04:00
|
|
|
if err != nil {
|
2020-08-11 14:22:40 -04:00
|
|
|
ui.Error(fmt.Sprintf("Build '%s' errored after %s: %s", name, fmtBuildDuration, err))
|
2019-05-06 09:42:23 -04:00
|
|
|
errors.Lock()
|
|
|
|
errors.m[name] = err
|
|
|
|
errors.Unlock()
|
2014-10-27 23:21:13 -04:00
|
|
|
} else {
|
2020-08-11 14:22:40 -04:00
|
|
|
ui.Say(fmt.Sprintf("Build '%s' finished after %s.", name, fmtBuildDuration))
|
2019-03-10 10:38:38 -04:00
|
|
|
if nil != runArtifacts {
|
|
|
|
artifacts.Lock()
|
|
|
|
artifacts.m[name] = runArtifacts
|
|
|
|
artifacts.Unlock()
|
|
|
|
}
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
2019-05-02 10:34:48 -04:00
|
|
|
}()
|
2014-10-27 23:21:13 -04:00
|
|
|
|
2020-05-11 11:56:14 -04:00
|
|
|
if cla.Debug {
|
2014-10-27 23:21:13 -04:00
|
|
|
log.Printf("Debug enabled, so waiting for build to finish: %s", b.Name())
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
2020-05-11 11:56:14 -04:00
|
|
|
if cla.ParallelBuilds == 1 {
|
2014-10-27 23:21:13 -04:00
|
|
|
log.Printf("Parallelization disabled, waiting for build to finish: %s", b.Name())
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for both the builds to complete and the interrupt handler,
|
|
|
|
// if it is interrupted.
|
|
|
|
log.Printf("Waiting on builds to complete...")
|
|
|
|
wg.Wait()
|
|
|
|
|
2020-08-11 14:22:40 -04:00
|
|
|
// Get the duration of the buildCommand command and parse it
|
|
|
|
buildCommandEnd := time.Now()
|
|
|
|
buildCommandDuration := buildCommandEnd.Sub(buildCommandStart)
|
|
|
|
fmtBuildCommandDuration := durafmt.Parse(buildCommandDuration).LimitFirstN(2)
|
|
|
|
c.Ui.Say(fmt.Sprintf("\n==> Wait completed after %s", fmtBuildCommandDuration))
|
|
|
|
|
2019-05-06 06:19:59 -04:00
|
|
|
if err := buildCtx.Err(); err != nil {
|
2015-05-23 19:30:45 -04:00
|
|
|
c.Ui.Say("Cleanly cancelled builds after being interrupted.")
|
2014-10-27 23:21:13 -04:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2019-05-06 09:42:23 -04:00
|
|
|
if len(errors.m) > 0 {
|
|
|
|
c.Ui.Machine("error-count", strconv.FormatInt(int64(len(errors.m)), 10))
|
2014-10-27 23:21:13 -04:00
|
|
|
|
2015-05-23 19:30:45 -04:00
|
|
|
c.Ui.Error("\n==> Some builds didn't complete successfully and had errors:")
|
2019-05-06 09:42:23 -04:00
|
|
|
for name, err := range errors.m {
|
2017-03-28 20:45:01 -04:00
|
|
|
// Create a UI for the machine readable stuff to be targeted
|
2017-03-29 15:44:42 -04:00
|
|
|
ui := &packer.TargetedUI{
|
2014-10-27 23:21:13 -04:00
|
|
|
Target: name,
|
2015-05-23 19:30:45 -04:00
|
|
|
Ui: c.Ui,
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ui.Machine("error", err.Error())
|
|
|
|
|
2015-05-23 19:30:45 -04:00
|
|
|
c.Ui.Error(fmt.Sprintf("--> %s: %s", name, err))
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-14 11:25:13 -04:00
|
|
|
if len(artifacts.m) > 0 {
|
2015-05-23 19:30:45 -04:00
|
|
|
c.Ui.Say("\n==> Builds finished. The artifacts of successful builds are:")
|
2015-10-14 11:25:13 -04:00
|
|
|
for name, buildArtifacts := range artifacts.m {
|
2017-03-28 20:45:01 -04:00
|
|
|
// Create a UI for the machine readable stuff to be targeted
|
2017-03-29 15:44:42 -04:00
|
|
|
ui := &packer.TargetedUI{
|
2014-10-27 23:21:13 -04:00
|
|
|
Target: name,
|
2015-05-23 19:30:45 -04:00
|
|
|
Ui: c.Ui,
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Machine-readable helpful
|
|
|
|
ui.Machine("artifact-count", strconv.FormatInt(int64(len(buildArtifacts)), 10))
|
|
|
|
|
|
|
|
for i, artifact := range buildArtifacts {
|
|
|
|
var message bytes.Buffer
|
|
|
|
fmt.Fprintf(&message, "--> %s: ", name)
|
|
|
|
|
|
|
|
if artifact != nil {
|
2016-04-06 01:41:26 -04:00
|
|
|
fmt.Fprint(&message, artifact.String())
|
2014-10-27 23:21:13 -04:00
|
|
|
} else {
|
|
|
|
fmt.Fprint(&message, "<nothing>")
|
|
|
|
}
|
|
|
|
|
|
|
|
iStr := strconv.FormatInt(int64(i), 10)
|
|
|
|
if artifact != nil {
|
|
|
|
ui.Machine("artifact", iStr, "builder-id", artifact.BuilderId())
|
|
|
|
ui.Machine("artifact", iStr, "id", artifact.Id())
|
|
|
|
ui.Machine("artifact", iStr, "string", artifact.String())
|
|
|
|
|
|
|
|
files := artifact.Files()
|
|
|
|
ui.Machine("artifact",
|
|
|
|
iStr,
|
|
|
|
"files-count", strconv.FormatInt(int64(len(files)), 10))
|
|
|
|
for fi, file := range files {
|
|
|
|
fiStr := strconv.FormatInt(int64(fi), 10)
|
|
|
|
ui.Machine("artifact", iStr, "file", fiStr, file)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ui.Machine("artifact", iStr, "nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Machine("artifact", iStr, "end")
|
2015-05-23 19:30:45 -04:00
|
|
|
c.Ui.Say(message.String())
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-23 19:30:45 -04:00
|
|
|
c.Ui.Say("\n==> Builds finished but no artifacts were created.")
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
|
2019-05-06 09:42:23 -04:00
|
|
|
if len(errors.m) > 0 {
|
2014-10-27 23:21:13 -04:00
|
|
|
// If any errors occurred, exit with a non-zero exit status
|
2019-12-17 05:25:56 -05:00
|
|
|
ret = 1
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
return ret
|
2014-10-27 23:21:13 -04:00
|
|
|
}
|
|
|
|
|
2017-10-13 14:41:42 -04:00
|
|
|
func (*BuildCommand) Help() string {
|
2014-10-27 23:21:13 -04:00
|
|
|
helpText := `
|
|
|
|
Usage: packer build [options] TEMPLATE
|
|
|
|
|
|
|
|
Will execute multiple builds in parallel as defined in the template.
|
|
|
|
The various artifacts created by the template will be outputted.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
2018-10-10 21:34:35 -04:00
|
|
|
-color=false Disable color output. (Default: color)
|
|
|
|
-debug Debug mode enabled for builds.
|
2019-03-05 10:54:35 -05:00
|
|
|
-except=foo,bar,baz Run all builds and post-procesors other than these.
|
2018-10-10 21:34:35 -04:00
|
|
|
-only=foo,bar,baz Build only the specified builds.
|
|
|
|
-force Force a build to continue if artifacts exist, deletes existing artifacts.
|
|
|
|
-machine-readable Produce machine-readable output.
|
2020-06-16 09:29:56 -04:00
|
|
|
-on-error=[cleanup|abort|ask|run-cleanup-provisioner] If the build fails do: clean up (default), abort, ask, or run-cleanup-provisioner.
|
2020-05-12 07:03:43 -04:00
|
|
|
-parallel-builds=1 Number of builds to run in parallel. 1 disables parallelization. 0 means no limit (Default: 0)
|
2018-10-03 08:40:13 -04:00
|
|
|
-timestamp-ui Enable prefixing of each ui output with an RFC3339 timestamp.
|
2018-09-01 03:32:23 -04:00
|
|
|
-var 'key=value' Variable for templates, can be used multiple times.
|
2020-05-01 05:18:47 -04:00
|
|
|
-var-file=path JSON file containing user variables.
|
2014-10-27 23:21:13 -04:00
|
|
|
`
|
|
|
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
2017-10-13 14:41:42 -04:00
|
|
|
func (*BuildCommand) Synopsis() string {
|
2014-10-27 23:21:13 -04:00
|
|
|
return "build image(s) from template"
|
|
|
|
}
|
2017-10-13 14:42:22 -04:00
|
|
|
|
|
|
|
func (*BuildCommand) AutocompleteArgs() complete.Predictor {
|
|
|
|
return complete.PredictNothing
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*BuildCommand) AutocompleteFlags() complete.Flags {
|
|
|
|
return complete.Flags{
|
|
|
|
"-color": complete.PredictNothing,
|
|
|
|
"-debug": complete.PredictNothing,
|
|
|
|
"-except": complete.PredictNothing,
|
|
|
|
"-only": complete.PredictNothing,
|
|
|
|
"-force": complete.PredictNothing,
|
|
|
|
"-machine-readable": complete.PredictNothing,
|
|
|
|
"-on-error": complete.PredictNothing,
|
|
|
|
"-parallel": complete.PredictNothing,
|
2018-10-03 08:40:13 -04:00
|
|
|
"-timestamp-ui": complete.PredictNothing,
|
2017-10-13 14:42:22 -04:00
|
|
|
"-var": complete.PredictNothing,
|
|
|
|
"-var-file": complete.PredictNothing,
|
|
|
|
}
|
|
|
|
}
|