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 {
|
||||
PackerBuildName string `mapstructure:"packer_build_name"`
|
||||
PackerBuilderType string `mapstructure:"packer_builder_type"`
|
||||
PackerCoreVersion bool `mapstructure:"packer_core_version"`
|
||||
PackerCoreVersion string `mapstructure:"packer_core_version"`
|
||||
PackerDebug bool `mapstructure:"packer_debug"`
|
||||
PackerForce bool `mapstructure:"packer_force"`
|
||||
PackerOnError string `mapstructure:"packer_on_error"`
|
||||
|
|
|
@ -113,6 +113,7 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
|
|||
} else {
|
||||
config.InterpolateContext.BuildName = ctx.BuildName
|
||||
config.InterpolateContext.BuildType = ctx.BuildType
|
||||
config.InterpolateContext.CorePackerVersionString = ctx.CorePackerVersionString
|
||||
config.InterpolateContext.TemplatePath = ctx.TemplatePath
|
||||
config.InterpolateContext.UserVariables = ctx.UserVariables
|
||||
if config.InterpolateContext.Data == nil {
|
||||
|
@ -261,6 +262,7 @@ func DetectContext(raws ...interface{}) (*interpolate.Context, error) {
|
|||
var s struct {
|
||||
BuildName string `mapstructure:"packer_build_name"`
|
||||
BuildType string `mapstructure:"packer_builder_type"`
|
||||
CorePackerVersionString string `mapstructure:"packer_core_version"`
|
||||
TemplatePath string `mapstructure:"packer_template_path"`
|
||||
Vars map[string]string `mapstructure:"packer_user_variables"`
|
||||
SensitiveVars []string `mapstructure:"packer_sensitive_variables"`
|
||||
|
@ -276,6 +278,7 @@ func DetectContext(raws ...interface{}) (*interpolate.Context, error) {
|
|||
return &interpolate.Context{
|
||||
BuildName: s.BuildName,
|
||||
BuildType: s.BuildType,
|
||||
CorePackerVersionString: s.CorePackerVersionString,
|
||||
TemplatePath: s.TemplatePath,
|
||||
UserVariables: s.Vars,
|
||||
SensitiveVariables: s.SensitiveVars,
|
||||
|
|
|
@ -166,7 +166,7 @@ func (b *CoreBuild) Prepare() (warn []string, err error) {
|
|||
packerConfig := map[string]interface{}{
|
||||
BuildNameConfigKey: b.Type,
|
||||
BuilderTypeConfigKey: b.BuilderType,
|
||||
CoreVersionConfigKey: version.Version,
|
||||
CoreVersionConfigKey: version.FormattedVersion(),
|
||||
DebugConfigKey: b.debug,
|
||||
ForceConfigKey: b.force,
|
||||
OnErrorConfigKey: b.onError,
|
||||
|
|
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/hashicorp/packer/common/packerbuilderdata"
|
||||
commontpl "github.com/hashicorp/packer/common/template"
|
||||
"github.com/hashicorp/packer/common/uuid"
|
||||
"github.com/hashicorp/packer/version"
|
||||
strftime "github.com/jehiah/go-strftime"
|
||||
)
|
||||
|
||||
|
@ -242,8 +241,12 @@ func funcGenUuid(ctx *Context) interface{} {
|
|||
}
|
||||
|
||||
func funcGenPackerVersion(ctx *Context) interface{} {
|
||||
return func() string {
|
||||
return version.FormattedVersion()
|
||||
return func() (string, error) {
|
||||
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.
|
||||
BuildName string
|
||||
BuildType string
|
||||
CorePackerVersionString string
|
||||
TemplatePath string
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue