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
9c93c9e8
Commit
9c93c9e8
authored
Sep 08, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: check for latest version
parent
d51364a8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
2 deletions
+71
-2
checkpoint.go
checkpoint.go
+34
-1
packer/version.go
packer/version.go
+37
-1
No files found.
checkpoint.go
View file @
9c93c9e8
...
@@ -9,18 +9,27 @@ import (
...
@@ -9,18 +9,27 @@ import (
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
)
)
func
init
()
{
packer
.
VersionChecker
=
packerVersionCheck
checkpointResult
=
make
(
chan
*
checkpoint
.
CheckResponse
,
1
)
}
var
checkpointResult
chan
*
checkpoint
.
CheckResponse
// runCheckpoint runs a HashiCorp Checkpoint request. You can read about
// runCheckpoint runs a HashiCorp Checkpoint request. You can read about
// Checkpoint here: https://github.com/hashicorp/go-checkpoint.
// Checkpoint here: https://github.com/hashicorp/go-checkpoint.
func
runCheckpoint
(
c
*
config
)
{
func
runCheckpoint
(
c
*
config
)
{
// If the user doesn't want checkpoint at all, then return.
// If the user doesn't want checkpoint at all, then return.
if
c
.
DisableCheckpoint
{
if
c
.
DisableCheckpoint
{
log
.
Printf
(
"[INFO] Checkpoint disabled. Not running."
)
log
.
Printf
(
"[INFO] Checkpoint disabled. Not running."
)
checkpointResult
<-
nil
return
return
}
}
configDir
,
err
:=
ConfigDir
()
configDir
,
err
:=
ConfigDir
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"[ERR] Checkpoint setup error: %s"
,
err
)
log
.
Printf
(
"[ERR] Checkpoint setup error: %s"
,
err
)
checkpointResult
<-
nil
return
return
}
}
...
@@ -35,7 +44,7 @@ func runCheckpoint(c *config) {
...
@@ -35,7 +44,7 @@ func runCheckpoint(c *config) {
signaturePath
=
""
signaturePath
=
""
}
}
_
,
err
=
checkpoint
.
Check
(
&
checkpoint
.
CheckParams
{
resp
,
err
:
=
checkpoint
.
Check
(
&
checkpoint
.
CheckParams
{
Product
:
"packer"
,
Product
:
"packer"
,
Version
:
version
,
Version
:
version
,
SignatureFile
:
signaturePath
,
SignatureFile
:
signaturePath
,
...
@@ -43,5 +52,29 @@ func runCheckpoint(c *config) {
...
@@ -43,5 +52,29 @@ func runCheckpoint(c *config) {
})
})
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"[ERR] Checkpoint error: %s"
,
err
)
log
.
Printf
(
"[ERR] Checkpoint error: %s"
,
err
)
resp
=
nil
}
checkpointResult
<-
resp
}
// packerVersionCheck implements packer.VersionCheckFunc and is used
// as the version checker.
func
packerVersionCheck
(
current
string
)
(
packer
.
VersionCheckInfo
,
error
)
{
info
:=
<-
checkpointResult
if
info
==
nil
{
var
zero
packer
.
VersionCheckInfo
return
zero
,
nil
}
}
alerts
:=
make
([]
string
,
len
(
info
.
Alerts
))
for
i
,
a
:=
range
info
.
Alerts
{
alerts
[
i
]
=
a
.
Message
}
return
packer
.
VersionCheckInfo
{
Outdated
:
info
.
Outdated
,
Latest
:
info
.
CurrentVersion
,
Alerts
:
alerts
,
},
nil
}
}
packer/version.go
View file @
9c93c9e8
...
@@ -9,6 +9,12 @@ import (
...
@@ -9,6 +9,12 @@ import (
// compiler for source builds.
// compiler for source builds.
var
GitCommit
string
var
GitCommit
string
// This should be check to a callback to check for the latest version.
//
// The global nature of this variable is dirty, but a version checker
// really shouldn't change anyways.
var
VersionChecker
VersionCheckFunc
// The version of packer.
// The version of packer.
const
Version
=
"0.6.2"
const
Version
=
"0.6.2"
...
@@ -17,6 +23,18 @@ const Version = "0.6.2"
...
@@ -17,6 +23,18 @@ const Version = "0.6.2"
// pre-release marker.
// pre-release marker.
const
VersionPrerelease
=
"dev"
const
VersionPrerelease
=
"dev"
// VersionCheckFunc is the callback that is called to check the latest
// version of Packer.
type
VersionCheckFunc
func
(
string
)
(
VersionCheckInfo
,
error
)
// VersionCheckInfo is the return value for the VersionCheckFunc that
// contains the latest version information.
type
VersionCheckInfo
struct
{
Outdated
bool
Latest
string
Alerts
[]
string
}
type
versionCommand
byte
type
versionCommand
byte
func
(
versionCommand
)
Help
()
string
{
func
(
versionCommand
)
Help
()
string
{
...
@@ -30,8 +48,26 @@ func (versionCommand) Run(env Environment, args []string) int {
...
@@ -30,8 +48,26 @@ func (versionCommand) Run(env Environment, args []string) int {
env
.
Ui
()
.
Machine
(
"version"
,
Version
)
env
.
Ui
()
.
Machine
(
"version"
,
Version
)
env
.
Ui
()
.
Machine
(
"version-prelease"
,
VersionPrerelease
)
env
.
Ui
()
.
Machine
(
"version-prelease"
,
VersionPrerelease
)
env
.
Ui
()
.
Machine
(
"version-commit"
,
GitCommit
)
env
.
Ui
()
.
Machine
(
"version-commit"
,
GitCommit
)
env
.
Ui
()
.
Say
(
VersionString
())
env
.
Ui
()
.
Say
(
VersionString
())
if
VersionChecker
!=
nil
{
current
:=
Version
if
VersionPrerelease
!=
""
{
current
+=
fmt
.
Sprintf
(
".%s"
,
VersionPrerelease
)
}
info
,
err
:=
VersionChecker
(
current
)
if
err
!=
nil
{
env
.
Ui
()
.
Say
(
fmt
.
Sprintf
(
"
\n
Error checking latest version: %s"
,
err
))
}
if
info
.
Outdated
{
env
.
Ui
()
.
Say
(
fmt
.
Sprintf
(
"
\n
Your version of Packer is out of date! The latest version
\n
"
+
"is %s. You can update by downloading from www.packer.io."
,
info
.
Latest
))
}
}
return
0
return
0
}
}
...
...
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