Commit Graph

939 Commits

Author SHA1 Message Date
Megan Marsh 721cbac645
Merge pull request #9996 from hashicorp/fix_9995
Make shell-local post-processor return copy of previous artifact
2020-10-05 13:00:51 -07:00
Adrien Delorme 9f97173371 PostProcessorServer.PostProcess: don't close the artifact we are serving
Sometimes, the artifact returned by PostProcess is the artifact from client.Artifact() and in that case we don't want to close client; otherwise the outcome is sort of undetermined. See #9995 for a good test file.

fix #9995
2020-10-05 14:27:55 +02:00
Adrien Delorme a9107a8fe9 noop progress bar is nil progress bar 2020-09-24 12:26:09 +02:00
Megan Marsh 15ee44e857 review comments 2020-09-23 11:33:51 -07:00
Megan Marsh ae8d359bf1 Switch to explicitly declaring TrackProgress on UI, using an underlying progress bar specifically stored on the struct. Export UiProgressTracker. These changes allow us to optionaly switch to the NoopProgressTracker when no TTY is set. 2020-09-21 16:05:14 -07:00
Rui Lopes 281af9a03d
prefer $APPDATA over $HOME in Windows (#9830) 2020-08-31 14:35:15 +02:00
Megan Marsh c88ff4ec45
add colored prefix to progress tracker bar so it's clearer what build an uploading file belongs to (#9780) 2020-08-17 14:32:13 -04:00
Sathyajith Bhat 9c8daed65e
Fix typo in error message (#9775)
If a variable has not been passed, the error message shown has a tiny typo (varaibles instead of variables)
2020-08-16 21:39:08 -04:00
sylviamoss 6d0b5a6957 skip post-processors when build is cancelled 2020-08-06 14:40:02 +02:00
Sylvia Moss 9181a435aa
Make max_retries a string to allow variable interpolation (#9673) 2020-08-05 17:41:20 +02:00
Adrien Delorme 44616d3bff
refactor initialization out from packer configs + tests (#9627)
The initialization of packer core in JSON also validates that `null` variables were set, except in the case of `packer validate --syntax-only` , but after the refactor to allow to have all commands work with HCL2 and JSON this subtlety was lost.

This refactors the initialisation of the core in order to allow to have `packer validate --syntax-only` not error in case a variable is not set. Since these calls are refactored this works for HCL2 too.

fix #9478
2020-07-24 10:58:03 +02:00
Gennady Lipenkov 4cd1950cd0 fix typo 2020-07-09 16:21:21 +03:00
Adrien Delorme 3fb7ddf509 Update provisioner.go 2020-07-07 11:52:08 +02:00
Adrien Delorme ab54f48247 add BuilderDataCommonKeys var to see what common keys a builder can return 2020-07-07 11:28:07 +02:00
Adrien Delorme 1b669ff2ab woops 2020-07-06 11:18:02 +02:00
Adrien Delorme db6c3adbba add hcl2 provisioner type that reprepares itself 2020-07-02 18:02:19 +02:00
Adrien Delorme 7969b690de Revert "Share build info with Provisioner and Post-Processor via HCL2 variables (#9444)"
This reverts commit 99046c9178.
2020-07-02 15:07:29 +02:00
Sylvia Moss 99046c9178
Share build info with Provisioner and Post-Processor via HCL2 variables (#9444) 2020-06-29 13:44:57 +02:00
Adrien Delorme c2975140cf
HCL2: allow to use keep_input_artifact in post processors (#9477)
* HCL2: allow to use keep_input_artifact in post processors
* add basic test
* add docs
2020-06-25 09:36:48 +02:00
Adrien Delorme 51d02f8c2d hcl2: inspect command 2020-06-23 11:58:57 +02:00
Megan Marsh 42e98f15ae make sure the no-op progress bar gets used for machine readable uis 2020-06-17 11:57:12 -07:00
Moss daaeccd8b0 Skip consecutives post-processors 2020-06-09 17:35:53 +02:00
Moss bfb9df0039 fix except flag for JSON and HCL2 2020-06-09 15:26:45 +02:00
Wilken Rivera f672f5bd9b command/validate: Add support for HCL2 configuration files
* Update validate command to use FixConfig for checking against known
fixers
* Update validation command flag docs
* Add ConfigFixer method to PackerHandler Interface
* Implement ConfigFixer interface in PackerConfig
* Remove all stdout messaging (i.e calls to c.Ui.Say) in the validate
command. The command will only display hcl.Diagnotic messaging when there is an error or warning.

HCL2 Configs
```
⇶  packer validate docker_centos_shell_provisioner.pkr.hcl

```

JSON Configs
```
⇶  packer validate vmware-iso_ubuntu_minimal/vmware-iso_ubuntu_minimal.json
Error: Failed to prepare build: "vmware-iso"

1 error occurred:
        * Deprecated configuration key: 'iso_checksum_type'. Please call `packer fix`
against your template to update your template to be compatable with the current
version of Packer. Visit https://www.packer.io/docs/commands/fix/ for more
detail.

Warning: Fixable configuration found.
You may need to run `packer fix` to get your build to run correctly.
See debug log for more information.

  map[string]interface{}{
        "builders": []interface{}{
                map[string]interface{}{
                        ... // 3 identical entries
                        "guest_os_type":     string("ubuntu-64"),
                        "http_directory":    string("http"),
-                       "iso_checksum":
string("946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2"),
+                       "iso_checksum":
string("sha256:946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2"),
-                       "iso_checksum_type": string("sha256"),
                        "iso_url":
string("http://old-releases.ubuntu.com/releases/14.04.1/ubuntu-14.04.1-server-amd64.iso"),
                        "shutdown_command":  string("echo 'vagrant' | sudo -S shutdown -P now"),
                        ... // 4 identical entries
                },
        },
  }
```
2020-06-05 14:24:39 -04:00
Adrien Delorme bac9c74447
packer console for HCL2 (#9359) 2020-06-05 17:23:54 +02:00
Adrien Delorme 3c5a1e5878 show build block name and source name if possible 2020-06-02 11:43:27 +02:00
Adrien Delorme b4aa71aef2 Merge remote-tracking branch 'origin/master' into pr/AdrienneCohea/9245 2020-06-02 11:36:32 +02:00
Megan Marsh 45be673c0f move this to after the prepare() is successful so that we don't try to run builds that didn't prepare successfully. 2020-05-28 11:34:00 -07:00
Adrien Delorme 40947c2bf6
HCL2: generate hcl tags with go-cty tags too (#9306)
This will allow to generate the config files:

```go
package main

import (
	"fmt"

	"github.com/hashicorp/hcl/v2/gohcl"
	"github.com/hashicorp/hcl/v2/hclwrite"
	"github.com/hashicorp/packer/builder/alicloud/ecs"
)

func main() {
	name := "name"
	app := ecs.FlatConfig{
		AlicloudImageName: &name,
		ECSSystemDiskMapping: &ecs.FlatAlicloudDiskDevice{
			DiskName: &name,
		},
	}

	f := hclwrite.NewEmptyFile()
	block := gohcl.EncodeAsBlock(&app, `source "something" "something"`)
	f.Body().AppendBlock(block)
	fmt.Printf("%s", f.Bytes())
}

```

Will output:

```
source "something" "something" {
  packer_user_variables      = null
  packer_sensitive_variables = null
  image_name                 = "name"
  image_share_account        = null
  image_unshare_account      = null
  image_copy_regions         = null
  image_copy_names           = null
  tags                       = null
  tag                        = null
  system_disk_mapping        = { disk_category = null, disk_delete_with_instance = null, disk_descri
ption = null, disk_device = null, disk_encrypted = null, disk_name = "name", disk_size = null, disk_
snapshot_id = null }
  image_disk_mappings        = null
  ssh_remote_tunnels         = null
  ssh_local_tunnels          = null
  ssh_public_key             = null
  ssh_private_key            = null
}
```

This is a good first step for #9015 and #9282 

fix #9304
2020-05-28 11:19:00 +02:00
Megan Marsh 3dc4ba2d68
Json vs HCL2 parity refactor (#9301)
* refactor so that json and hcl2 templates are both prepared in the same place in the build call, to make code easier to reason about. Remove overly verbose error output which isn't useful in vast majority of cases

* fix tests

* check err msg

* hcl2template.PackerConfig.GetBuilds: raise a diagnostic in case the packer core build perpare call errors

Co-authored-by: Adrien Delorme <adrien.delorme@icloud.com>
2020-05-28 10:43:58 +02:00
Megan Marsh 1c214628ed
Merge pull request #9234 from hashicorp/hcl_force_and_debug
enable force, debug, and on-error for hcl2 builds
2020-05-19 16:02:06 -07:00
Sylvia Moss 1c30a71d09
Replace file shared state by statebag (#9238) 2020-05-19 11:49:48 +02:00
Adrienne Cohea 6aea8ead6a
Support named builds in HCL2 templates. 2020-05-17 22:13:35 -07:00
Megan Marsh ee5635722b enable force, debug, and on-error for hcl2 builds 2020-05-14 16:22:51 -07:00
Adrien Delorme 52b2151b21 go generate ./packer 2020-05-12 16:19:26 +02:00
Adrien Delorme d147ebe79f packer/new_stuff.go => packer/run_interfaces.go 2020-05-12 12:31:05 +02:00
Adrien Delorme d34cecc668 Update new_stuff.go 2020-05-12 12:29:31 +02:00
Adrien Delorme ec083083ce Update new_stuff.go 2020-05-08 16:59:19 +02:00
Adrien Delorme 7e45a1e950 fix enum 2020-05-08 16:54:44 +02:00
Adrien Delorme 42a05e1e80 more refactoring 2020-05-08 16:41:47 +02:00
Adrien Delorme e50eb341bf Update core_test.go 2020-04-30 16:40:58 +02:00
Adrien Delorme c71a792186 simplify/refactor core for build & validate 2020-04-30 16:36:01 +02:00
Sylvia Moss 553b1fb9f8
Add RetriedProvisioner to allow retry provisioners (#9061) 2020-04-16 11:58:54 +02:00
Megan Marsh 890d7b2ec4
Merge pull request #8875 from hashicorp/fix_8812
Fix user var recursion with env vars
2020-03-13 12:52:17 -07:00
Megan Marsh 32595f71cf sort interpolation input to make the interpolation deterministic 2020-03-12 13:40:56 -07:00
Megan Marsh 17f59c4ddc fix regex and actually test the check function 2020-03-12 10:00:56 -07:00
Megan Marsh ad5495ac8f
Update packer/core.go
Co-Authored-By: Adrien Delorme <azr@users.noreply.github.com>
2020-03-12 09:50:02 -07:00
Megan Marsh 051155270f add test for fixed behavior 2020-03-11 12:48:35 -07:00
Megan Marsh 52f03de0f0 adding tests 2020-03-11 10:49:45 -07:00
Megan Marsh 063dd5c133 fix interpolation when env vars interpolate before user vars 2020-03-11 09:55:40 -07:00