refactor core version pkg imports out of json interpolation/decode pathway.
This commit is contained in:
parent
bc85854a53
commit
cd59d938b2
|
@ -6,7 +6,7 @@ package common
|
||||||
type PackerConfig struct {
|
type PackerConfig struct {
|
||||||
PackerBuildName string `mapstructure:"packer_build_name"`
|
PackerBuildName string `mapstructure:"packer_build_name"`
|
||||||
PackerBuilderType string `mapstructure:"packer_builder_type"`
|
PackerBuilderType string `mapstructure:"packer_builder_type"`
|
||||||
PackerCoreVersion bool `mapstructure:"packer_core_version"`
|
PackerCoreVersion string `mapstructure:"packer_core_version"`
|
||||||
PackerDebug bool `mapstructure:"packer_debug"`
|
PackerDebug bool `mapstructure:"packer_debug"`
|
||||||
PackerForce bool `mapstructure:"packer_force"`
|
PackerForce bool `mapstructure:"packer_force"`
|
||||||
PackerOnError string `mapstructure:"packer_on_error"`
|
PackerOnError string `mapstructure:"packer_on_error"`
|
||||||
|
|
|
@ -113,6 +113,7 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
|
||||||
} else {
|
} else {
|
||||||
config.InterpolateContext.BuildName = ctx.BuildName
|
config.InterpolateContext.BuildName = ctx.BuildName
|
||||||
config.InterpolateContext.BuildType = ctx.BuildType
|
config.InterpolateContext.BuildType = ctx.BuildType
|
||||||
|
config.InterpolateContext.CorePackerVersionString = ctx.CorePackerVersionString
|
||||||
config.InterpolateContext.TemplatePath = ctx.TemplatePath
|
config.InterpolateContext.TemplatePath = ctx.TemplatePath
|
||||||
config.InterpolateContext.UserVariables = ctx.UserVariables
|
config.InterpolateContext.UserVariables = ctx.UserVariables
|
||||||
if config.InterpolateContext.Data == nil {
|
if config.InterpolateContext.Data == nil {
|
||||||
|
@ -261,6 +262,7 @@ func DetectContext(raws ...interface{}) (*interpolate.Context, error) {
|
||||||
var s struct {
|
var s struct {
|
||||||
BuildName string `mapstructure:"packer_build_name"`
|
BuildName string `mapstructure:"packer_build_name"`
|
||||||
BuildType string `mapstructure:"packer_builder_type"`
|
BuildType string `mapstructure:"packer_builder_type"`
|
||||||
|
CorePackerVersionString string `mapstructure:"packer_core_version"`
|
||||||
TemplatePath string `mapstructure:"packer_template_path"`
|
TemplatePath string `mapstructure:"packer_template_path"`
|
||||||
Vars map[string]string `mapstructure:"packer_user_variables"`
|
Vars map[string]string `mapstructure:"packer_user_variables"`
|
||||||
SensitiveVars []string `mapstructure:"packer_sensitive_variables"`
|
SensitiveVars []string `mapstructure:"packer_sensitive_variables"`
|
||||||
|
@ -276,6 +278,7 @@ func DetectContext(raws ...interface{}) (*interpolate.Context, error) {
|
||||||
return &interpolate.Context{
|
return &interpolate.Context{
|
||||||
BuildName: s.BuildName,
|
BuildName: s.BuildName,
|
||||||
BuildType: s.BuildType,
|
BuildType: s.BuildType,
|
||||||
|
CorePackerVersionString: s.CorePackerVersionString,
|
||||||
TemplatePath: s.TemplatePath,
|
TemplatePath: s.TemplatePath,
|
||||||
UserVariables: s.Vars,
|
UserVariables: s.Vars,
|
||||||
SensitiveVariables: s.SensitiveVars,
|
SensitiveVariables: s.SensitiveVars,
|
||||||
|
|
|
@ -166,7 +166,7 @@ func (b *CoreBuild) Prepare() (warn []string, err error) {
|
||||||
packerConfig := map[string]interface{}{
|
packerConfig := map[string]interface{}{
|
||||||
BuildNameConfigKey: b.Type,
|
BuildNameConfigKey: b.Type,
|
||||||
BuilderTypeConfigKey: b.BuilderType,
|
BuilderTypeConfigKey: b.BuilderType,
|
||||||
CoreVersionConfigKey: version.Version,
|
CoreVersionConfigKey: version.FormattedVersion(),
|
||||||
DebugConfigKey: b.debug,
|
DebugConfigKey: b.debug,
|
||||||
ForceConfigKey: b.force,
|
ForceConfigKey: b.force,
|
||||||
OnErrorConfigKey: b.onError,
|
OnErrorConfigKey: b.onError,
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"github.com/hashicorp/packer/common/packerbuilderdata"
|
"github.com/hashicorp/packer/common/packerbuilderdata"
|
||||||
commontpl "github.com/hashicorp/packer/common/template"
|
commontpl "github.com/hashicorp/packer/common/template"
|
||||||
"github.com/hashicorp/packer/common/uuid"
|
"github.com/hashicorp/packer/common/uuid"
|
||||||
"github.com/hashicorp/packer/version"
|
|
||||||
strftime "github.com/jehiah/go-strftime"
|
strftime "github.com/jehiah/go-strftime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -242,8 +241,12 @@ func funcGenUuid(ctx *Context) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
func funcGenPackerVersion(ctx *Context) interface{} {
|
func funcGenPackerVersion(ctx *Context) interface{} {
|
||||||
return func() string {
|
return func() (string, error) {
|
||||||
return version.FormattedVersion()
|
if ctx == nil || ctx.CorePackerVersionString == "" {
|
||||||
|
return "", errors.New("packer_version not available")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.CorePackerVersionString, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ type Context struct {
|
||||||
// rendered within.
|
// rendered within.
|
||||||
BuildName string
|
BuildName string
|
||||||
BuildType string
|
BuildType string
|
||||||
|
CorePackerVersionString string
|
||||||
TemplatePath string
|
TemplatePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue