packer-cn/packer/run_interfaces.go

69 lines
1.7 KiB
Go
Raw Normal View History

2020-05-08 10:41:47 -04:00
package packer
import (
"github.com/hashicorp/hcl/v2"
2020-12-17 16:29:25 -05:00
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)
2020-05-08 10:41:47 -04:00
type GetBuildsOptions struct {
// Get builds except the ones that match with except and with only the ones
2020-05-08 10:59:19 -04:00
// that match with Only. When those are empty everything matches.
2020-05-08 10:41:47 -04:00
Except, Only []string
Debug, Force bool
OnError string
2020-05-08 10:41:47 -04:00
}
type BuildGetter interface {
2020-05-12 06:29:31 -04:00
// GetBuilds return all possible builds for a config. It also starts all
// builders.
2020-05-08 10:41:47 -04:00
// TODO(azr): rename to builder starter ?
GetBuilds(GetBuildsOptions) ([]packersdk.Build, hcl.Diagnostics)
2020-05-08 10:41:47 -04:00
}
2020-06-05 11:23:54 -04:00
type Evaluator interface {
// EvaluateExpression is meant to be used in the `packer console` command.
// It parses the input string and returns what needs to be displayed. In
// case of an error the error should be displayed.
EvaluateExpression(expr string) (output string, exit bool, diags hcl.Diagnostics)
}
// The packer.Handler handles all Packer things.
type Handler interface {
Initialize() hcl.Diagnostics
2020-06-05 11:23:54 -04:00
Evaluator
BuildGetter
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-02 14:58:33 -04:00
ConfigFixer
2020-06-23 05:58:57 -04:00
ConfigInspector
2020-06-05 11:23:54 -04:00
}
2020-05-08 10:54:44 -04:00
//go:generate enumer -type FixConfigMode
2020-05-08 10:41:47 -04:00
type FixConfigMode int
const (
2020-05-12 07:03:43 -04:00
// Stdout will make FixConfig simply print what the config should be; it
// will only work when a single file is passed.
2020-05-08 10:54:44 -04:00
Stdout FixConfigMode = iota
2020-05-12 06:29:31 -04:00
// Inplace fixes your files on the spot.
2020-05-08 10:54:44 -04:00
Inplace
2020-05-12 06:29:31 -04:00
// Diff shows a full diff.
2020-05-08 10:54:44 -04:00
Diff
2020-05-08 10:41:47 -04:00
)
type FixConfigOptions struct {
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-02 14:58:33 -04:00
Mode FixConfigMode
2020-05-08 10:41:47 -04:00
}
2020-05-12 06:29:31 -04:00
type ConfigFixer interface {
2020-05-08 10:41:47 -04:00
// FixConfig will output the config in a fixed manner.
FixConfig(FixConfigOptions) hcl.Diagnostics
}
2020-06-23 05:58:57 -04:00
type InspectConfigOptions struct {
packersdk.Ui
2020-06-23 05:58:57 -04:00
}
type ConfigInspector interface {
// Inspect will output self inspection for a configuration
InspectConfig(InspectConfigOptions) (ret int)
}