Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
5c82ac28
Commit
5c82ac28
authored
Jun 29, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2356 from mitchellh/b-min-version
packer: validate minimum version [GH-2310]
parents
aa3a336e
2498ad02
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
0 deletions
+58
-0
command/meta.go
command/meta.go
+2
-0
main.go
main.go
+1
-0
packer/core.go
packer/core.go
+27
-0
packer/core_test.go
packer/core_test.go
+14
-0
packer/test-fixtures/validate-min-version-high.json
packer/test-fixtures/validate-min-version-high.json
+7
-0
packer/test-fixtures/validate-min-version.json
packer/test-fixtures/validate-min-version.json
+7
-0
No files found.
command/meta.go
View file @
5c82ac28
...
@@ -28,6 +28,7 @@ type Meta struct {
...
@@ -28,6 +28,7 @@ type Meta struct {
CoreConfig
*
packer
.
CoreConfig
CoreConfig
*
packer
.
CoreConfig
Cache
packer
.
Cache
Cache
packer
.
Cache
Ui
packer
.
Ui
Ui
packer
.
Ui
Version
string
// These are set by command-line flags
// These are set by command-line flags
flagBuildExcept
[]
string
flagBuildExcept
[]
string
...
@@ -42,6 +43,7 @@ func (m *Meta) Core(tpl *template.Template) (*packer.Core, error) {
...
@@ -42,6 +43,7 @@ func (m *Meta) Core(tpl *template.Template) (*packer.Core, error) {
config
:=
*
m
.
CoreConfig
config
:=
*
m
.
CoreConfig
config
.
Template
=
tpl
config
.
Template
=
tpl
config
.
Variables
=
m
.
flagVars
config
.
Variables
=
m
.
flagVars
config
.
Version
=
m
.
Version
// Init the core
// Init the core
core
,
err
:=
packer
.
NewCore
(
&
config
)
core
,
err
:=
packer
.
NewCore
(
&
config
)
...
...
main.go
View file @
5c82ac28
...
@@ -168,6 +168,7 @@ func wrappedMain() int {
...
@@ -168,6 +168,7 @@ func wrappedMain() int {
PostProcessor
:
config
.
LoadPostProcessor
,
PostProcessor
:
config
.
LoadPostProcessor
,
Provisioner
:
config
.
LoadProvisioner
,
Provisioner
:
config
.
LoadProvisioner
,
},
},
Version
:
Version
,
},
},
Cache
:
cache
,
Cache
:
cache
,
Ui
:
ui
,
Ui
:
ui
,
...
...
packer/core.go
View file @
5c82ac28
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"sort"
"sort"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-version"
"github.com/mitchellh/packer/template"
"github.com/mitchellh/packer/template"
"github.com/mitchellh/packer/template/interpolate"
"github.com/mitchellh/packer/template/interpolate"
)
)
...
@@ -17,6 +18,7 @@ type Core struct {
...
@@ -17,6 +18,7 @@ type Core struct {
components
ComponentFinder
components
ComponentFinder
variables
map
[
string
]
string
variables
map
[
string
]
string
builds
map
[
string
]
*
template
.
Builder
builds
map
[
string
]
*
template
.
Builder
version
string
}
}
// CoreConfig is the structure for initializing a new Core. Once a CoreConfig
// CoreConfig is the structure for initializing a new Core. Once a CoreConfig
...
@@ -25,6 +27,7 @@ type CoreConfig struct {
...
@@ -25,6 +27,7 @@ type CoreConfig struct {
Components
ComponentFinder
Components
ComponentFinder
Template
*
template
.
Template
Template
*
template
.
Template
Variables
map
[
string
]
string
Variables
map
[
string
]
string
Version
string
}
}
// The function type used to lookup Builder implementations.
// The function type used to lookup Builder implementations.
...
@@ -55,6 +58,7 @@ func NewCore(c *CoreConfig) (*Core, error) {
...
@@ -55,6 +58,7 @@ func NewCore(c *CoreConfig) (*Core, error) {
Template
:
c
.
Template
,
Template
:
c
.
Template
,
components
:
c
.
Components
,
components
:
c
.
Components
,
variables
:
c
.
Variables
,
variables
:
c
.
Variables
,
version
:
c
.
Version
,
}
}
if
err
:=
result
.
validate
();
err
!=
nil
{
if
err
:=
result
.
validate
();
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -226,6 +230,29 @@ func (c *Core) validate() error {
...
@@ -226,6 +230,29 @@ func (c *Core) validate() error {
return
err
return
err
}
}
// Validate the minimum version is satisfied
if
c
.
Template
.
MinVersion
!=
""
{
versionActual
,
err
:=
version
.
NewVersion
(
c
.
version
)
if
err
!=
nil
{
// This shouldn't happen since we set it via the compiler
panic
(
err
)
}
versionMin
,
err
:=
version
.
NewVersion
(
c
.
Template
.
MinVersion
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"min_version is invalid: %s"
,
err
)
}
if
versionActual
.
LessThan
(
versionMin
)
{
return
fmt
.
Errorf
(
"This template requires a minimum Packer version of %s,
\n
"
+
"but version %s is running."
,
versionMin
,
versionActual
)
}
}
// Validate variables are set
// Validate variables are set
var
err
error
var
err
error
for
n
,
v
:=
range
c
.
Template
.
Variables
{
for
n
,
v
:=
range
c
.
Template
.
Variables
{
...
...
packer/core_test.go
View file @
5c82ac28
...
@@ -484,6 +484,19 @@ func TestCoreValidate(t *testing.T) {
...
@@ -484,6 +484,19 @@ func TestCoreValidate(t *testing.T) {
map
[
string
]
string
{
"foo"
:
"bar"
},
map
[
string
]
string
{
"foo"
:
"bar"
},
false
,
false
,
},
},
// Min version good
{
"validate-min-version.json"
,
map
[
string
]
string
{
"foo"
:
"bar"
},
false
,
},
{
"validate-min-version-high.json"
,
map
[
string
]
string
{
"foo"
:
"bar"
},
true
,
},
}
}
for
_
,
tc
:=
range
cases
{
for
_
,
tc
:=
range
cases
{
...
@@ -501,6 +514,7 @@ func TestCoreValidate(t *testing.T) {
...
@@ -501,6 +514,7 @@ func TestCoreValidate(t *testing.T) {
_
,
err
=
NewCore
(
&
CoreConfig
{
_
,
err
=
NewCore
(
&
CoreConfig
{
Template
:
tpl
,
Template
:
tpl
,
Variables
:
tc
.
Vars
,
Variables
:
tc
.
Vars
,
Version
:
"1.0.0"
,
})
})
if
(
err
!=
nil
)
!=
tc
.
Err
{
if
(
err
!=
nil
)
!=
tc
.
Err
{
t
.
Fatalf
(
"err: %s
\n\n
%s"
,
tc
.
File
,
err
)
t
.
Fatalf
(
"err: %s
\n\n
%s"
,
tc
.
File
,
err
)
...
...
packer/test-fixtures/validate-min-version-high.json
0 → 100644
View file @
5c82ac28
{
"min_packer_version"
:
"2.1.0"
,
"builders"
:
[
{
"type"
:
"foo"
}
]
}
packer/test-fixtures/validate-min-version.json
0 → 100644
View file @
5c82ac28
{
"min_packer_version"
:
"0.1.0"
,
"builders"
:
[
{
"type"
:
"foo"
}
]
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment