Commit Graph

103 Commits

Author SHA1 Message Date
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 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
Adrienne Cohea 6aea8ead6a
Support named builds in HCL2 templates. 2020-05-17 22:13:35 -07:00
Sylvia Moss 2981fd627d
Avoid calling CoreBuild.Prepare(...) for HCL2 templates (#8742) 2020-02-14 17:39:32 +01:00
Megan Marsh 76fa85fd93
Merge pull request #8613 from hashicorp/add_pp_names
log name of postprocessor running to disambiguate long chains of pps
2020-01-16 13:12:02 -08:00
Adrien Delorme 2d1a67c6cb hcl2: allow to optionnaly name provisioners and post-processors 2020-01-16 12:08:39 +01:00
Sylvia Moss 0677b02e18
Share SourceImageName with provisioners and manifest post-processor (#8603) 2020-01-16 12:04:03 +01:00
Megan Marsh e228a5bcb9 log name of postprocessor running to disambiguate long chains of pps 2020-01-15 14:47:56 -08:00
Caleb Lemoine 9f6eb0ef65 fix: mispelled variables names in packer/build.go (#8568) 2020-01-06 14:02:29 +01:00
Megan Marsh 8490bbc45c add tests for info sharing 2019-12-17 13:41:48 -08:00
Adrien Delorme 4b7132c87c Merge remote-tracking branch 'origin/master' into sharing_info 2019-12-17 11:57:09 +01:00
Adrien Delorme 0785c2f6fc
build using HCL2 (#8423)
This follows #8232 which added the code to generate the code required to parse
HCL files for each packer component.

All old config files of packer will keep on working the same. Packer takes one
argument. When a directory is passed, all files in the folder with a name
ending with  “.pkr.hcl” or “.pkr.json” will be parsed using the HCL2 format.
When a file ending with “.pkr.hcl” or “.pkr.json” is passed it will be parsed
using the HCL2 format. For every other case; the old packer style will be used.

## 1. the hcl2template pkg can create a packer.Build from a set of HCL (v2) files

I had to make the packer.coreBuild (which is our one and only packer.Build ) a public struct with public fields

## 2. Components interfaces get a new ConfigSpec Method to read a file from an HCL file.

  This is a breaking change for packer plugins.

a packer component can be a: builder/provisioner/post-processor

each component interface now gets a `ConfigSpec() hcldec.ObjectSpec`
which allows packer to tell what is the layout of the hcl2 config meant
to configure that specific component.

This ObjectSpec is sent through the wire (RPC) and a cty.Value is now
sent through the already existing configuration entrypoints:

 Provisioner.Prepare(raws ...interface{}) error
 Builder.Prepare(raws ...interface{}) ([]string, error)
 PostProcessor.Configure(raws ...interface{}) error

close #1768


Example hcl files:

```hcl
// file amazon-ebs-kms-key/run.pkr.hcl
build {
    sources = [
        "source.amazon-ebs.first",
    ]

    provisioner "shell" {
        inline = [
            "sleep 5"
        ]
    }

    post-processor "shell-local" {
        inline = [
            "sleep 5"
        ]
    }
}

// amazon-ebs-kms-key/source.pkr.hcl

source "amazon-ebs" "first" {

    ami_name = "hcl2-test"
    region = "us-east-1"
    instance_type = "t2.micro"

    kms_key_id = "c729958f-c6ba-44cd-ab39-35ab68ce0a6c"
    encrypt_boot = true
    source_ami_filter {
        filters {
          virtualization-type = "hvm"
          name =  "amzn-ami-hvm-????.??.?.????????-x86_64-gp2"
          root-device-type = "ebs"
        }
        most_recent = true
        owners = ["amazon"]
    }
    launch_block_device_mappings {
        device_name = "/dev/xvda"
        volume_size = 20
        volume_type = "gp2"
        delete_on_termination = "true"
    }
    launch_block_device_mappings {
        device_name = "/dev/xvdf"
        volume_size = 500
        volume_type = "gp2"
        delete_on_termination = true
        encrypted = true
    }

    ami_regions = ["eu-central-1"]
    run_tags {
        Name = "packer-solr-something"
        stack-name = "DevOps Tools"
    }
    
    communicator = "ssh"
    ssh_pty = true
    ssh_username = "ec2-user"
    associate_public_ip_address = true
}
```
2019-12-17 11:25:56 +01:00
Megan Marsh 0f6d1beccf add an extra string array to the Prepare() return values in the builder interfaces; this sets up the ability for builders to give the provisioners custom user-accessible build-time variables. 2019-12-16 21:23:05 -08:00
Megan Marsh 5bd8fee708 Creates a final "cleanup" provisioner to run if an error occurs during a provisioning step, allowing users to perform any custom cleanup tasks that must happen on the VM before the VM is shut down and destroyed. 2019-09-24 16:08:15 -07:00
Adrien Delorme a81abd297b Merge remote-tracking branch 'origin/master' into context_provisioner 2019-04-08 20:09:01 +02:00
Megan Marsh 96c94d2fa0 clean up code comments 2019-04-03 14:04:03 -07:00
Megan Marsh 10f47b5158 document clearly what keep_input_artifact does for each post-processor 2019-04-03 13:57:22 -07:00
Megan Marsh 365b32eb9c goofing 2019-04-03 09:43:39 -07:00
Adrien Delorme e65115a7a0 contextualize post-processor 2019-04-03 15:55:55 +02:00
Adrien Delorme a4bf94dd3c change Builder to be passed a context for cancellation
we have to to give it to our hook
2019-04-03 15:55:55 +02:00
Megan Marsh 12fc1fa751 default_keep_input_artifact 2019-04-02 16:51:58 -07:00
Adrien Delorme 9f82b75e57 Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 12:11:58 +01:00
Megan Marsh 91aa5f8bbb resolve conflicts; fix to work with hookedprovisioner which has been added since PR was made 2018-06-07 15:53:18 -07:00
Matthew Hooker b07a0cd6f0
fix tests
always sort telemetry options
2017-11-14 16:39:03 -08:00
Matthew Hooker 3e3768ec3e
fix tests 2017-11-14 16:30:43 -08:00
Matthew Hooker 46f41d1f12
WIP: add options to telemetry 2017-11-14 16:30:43 -08:00
Matthew Hooker 2d581dfc7b
fix tests. 2017-06-15 14:08:17 -07:00
Matthew Hooker 7382382727
Add telemetry reporting through checkpoint
Will report builders/provisioner/post-processor types used per build,
and whether or not the build passed.

Will also report any panics we see.

You may opt out of this reporting by setting the environment variable
`CHECKPOINT_DISABLE`.
2017-06-15 13:21:11 -07:00
Matthew Hooker 048e316645
s/TargettedUi/TargetedUI/ 2017-03-29 12:44:42 -07:00
Matthew Hooker 230079f73a
spell fixes 2017-03-28 20:36:19 -07:00
Orivej Desh 389603cc0f Allow upper case input to -on-error=ask 2016-09-16 12:15:00 +00:00
Orivej Desh 6762965696 Add -on-error command line argument to allow preserving artifacts on builder errors
Resolves #409
2016-09-16 12:15:00 +00:00
Mitchell Hashimoto 639e63fd7c packer: test for template path 2015-05-29 14:29:32 -07:00
Mitchell Hashimoto 6a3dd16a3a packer: template now handles user var logic 2013-12-27 09:17:51 -07:00
Mitchell Hashimoto 336051e316 packer: builder prepare can return warnings 2013-11-02 22:31:12 -05:00
Mitchell Hashimoto ac2a4807d4 packer: fix required var check to work properly 2013-08-31 17:36:43 -07:00
Mitchell Hashimoto fd4b01cf85 packer: required user variables [GH-374] 2013-08-31 17:33:17 -07:00
Mitchell Hashimoto 0dc347c70d packer: implement Cancel in ProvisionHook 2013-08-30 23:39:29 -07:00
Mitchell Hashimoto e210151408 packer: implement Cancel on DispatchHook 2013-08-30 17:26:51 -07:00
Mitchell Hashimoto a329d7dd2f packer: remove keep_input_artifact prior to sending to build [GH-310] 2013-08-19 16:00:25 -07:00
Mitchell Hashimoto 03c10a9aa8 packer: renamed PrefixedUi to TargettedUi 2013-08-11 18:31:28 -07:00
Mitchell Hashimoto 598f11f168 packer: properly override/send user variables to prepare 2013-08-09 15:57:08 -07:00
Mitchell Hashimoto 3f0a268e1e packer, packer/rpc: Update Build interface to allow variable overrides 2013-08-09 15:57:07 -07:00
Mitchell Hashimoto 95b598f748 packer: Template understands variables, puts it into a Build 2013-08-09 15:57:07 -07:00
Mitchell Hashimoto 9387ba0fd4 packer: Make builder type available in configs [GH-154] 2013-07-15 09:58:32 +09:00
Mitchell Hashimoto f621f88913 packer: move constants into a single const() 2013-07-15 09:55:41 +09:00
Mitchell Hashimoto 2981da4eef fmt 2013-07-13 10:01:27 +09:00
Jason A. Beranek 13c733a3db Add support for -force flag on builds [GH-119] 2013-07-11 23:43:23 -05:00
Mitchell Hashimoto 44e0a7def5 packer: Send packerConfig into PostProcessors 2013-07-01 15:00:21 -07:00