Remove version from "packer" package
This commit is contained in:
parent
bf9e734179
commit
8dbe0f065c
|
@ -6,11 +6,10 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/hashicorp/go-checkpoint"
|
"github.com/hashicorp/go-checkpoint"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/command"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
packer.VersionChecker = packerVersionCheck
|
|
||||||
checkpointResult = make(chan *checkpoint.CheckResponse, 1)
|
checkpointResult = make(chan *checkpoint.CheckResponse, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +32,9 @@ func runCheckpoint(c *config) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
version := packer.Version
|
version := Version
|
||||||
if packer.VersionPrerelease != "" {
|
if VersionPrerelease != "" {
|
||||||
version += fmt.Sprintf(".%s", packer.VersionPrerelease)
|
version += fmt.Sprintf(".%s", VersionPrerelease)
|
||||||
}
|
}
|
||||||
|
|
||||||
signaturePath := filepath.Join(configDir, "checkpoint_signature")
|
signaturePath := filepath.Join(configDir, "checkpoint_signature")
|
||||||
|
@ -58,21 +57,23 @@ func runCheckpoint(c *config) {
|
||||||
checkpointResult <- resp
|
checkpointResult <- resp
|
||||||
}
|
}
|
||||||
|
|
||||||
// packerVersionCheck implements packer.VersionCheckFunc and is used
|
// commandVersionCheck implements command.VersionCheckFunc and is used
|
||||||
// as the version checker.
|
// as the version checker.
|
||||||
func packerVersionCheck(current string) (packer.VersionCheckInfo, error) {
|
func commandVersionCheck() (command.VersionCheckInfo, error) {
|
||||||
|
// Wait for the result to come through
|
||||||
info := <-checkpointResult
|
info := <-checkpointResult
|
||||||
if info == nil {
|
if info == nil {
|
||||||
var zero packer.VersionCheckInfo
|
var zero command.VersionCheckInfo
|
||||||
return zero, nil
|
return zero, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build the alerts that we may have received about our version
|
||||||
alerts := make([]string, len(info.Alerts))
|
alerts := make([]string, len(info.Alerts))
|
||||||
for i, a := range info.Alerts {
|
for i, a := range info.Alerts {
|
||||||
alerts[i] = a.Message
|
alerts[i] = a.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
return packer.VersionCheckInfo{
|
return command.VersionCheckInfo{
|
||||||
Outdated: info.Outdated,
|
Outdated: info.Outdated,
|
||||||
Latest: info.CurrentVersion,
|
Latest: info.CurrentVersion,
|
||||||
Alerts: alerts,
|
Alerts: alerts,
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
package command
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// VersionCommand is a Command implementation prints the version.
|
||||||
|
type VersionCommand struct {
|
||||||
|
Meta
|
||||||
|
|
||||||
|
Revision string
|
||||||
|
Version string
|
||||||
|
VersionPrerelease string
|
||||||
|
CheckFunc VersionCheckFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
// VersionCheckFunc is the callback called by the Version command to
|
||||||
|
// check if there is a new version of Packer.
|
||||||
|
type VersionCheckFunc func() (VersionCheckInfo, error)
|
||||||
|
|
||||||
|
// VersionCheckInfo is the return value for the VersionCheckFunc callback
|
||||||
|
// and tells the Version command information about the latest version
|
||||||
|
// of Packer.
|
||||||
|
type VersionCheckInfo struct {
|
||||||
|
Outdated bool
|
||||||
|
Latest string
|
||||||
|
Alerts []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *VersionCommand) Help() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *VersionCommand) Run(args []string) int {
|
||||||
|
/*
|
||||||
|
env.Ui().Machine("version", Version)
|
||||||
|
env.Ui().Machine("version-prelease", VersionPrerelease)
|
||||||
|
env.Ui().Machine("version-commit", GitCommit)
|
||||||
|
*/
|
||||||
|
|
||||||
|
var versionString bytes.Buffer
|
||||||
|
fmt.Fprintf(&versionString, "Packer v%s", c.Version)
|
||||||
|
if c.VersionPrerelease != "" {
|
||||||
|
fmt.Fprintf(&versionString, ".%s", c.VersionPrerelease)
|
||||||
|
|
||||||
|
if c.Revision != "" {
|
||||||
|
fmt.Fprintf(&versionString, " (%s)", c.Revision)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Ui.Output(versionString.String())
|
||||||
|
|
||||||
|
// If we have a version check function, then let's check for
|
||||||
|
// the latest version as well.
|
||||||
|
if c.CheckFunc != nil {
|
||||||
|
// Separate the prior output with a newline
|
||||||
|
c.Ui.Output("")
|
||||||
|
|
||||||
|
// Check the latest version
|
||||||
|
info, err := c.CheckFunc()
|
||||||
|
if err != nil {
|
||||||
|
c.Ui.Error(fmt.Sprintf(
|
||||||
|
"Error checking latest version: %s", err))
|
||||||
|
}
|
||||||
|
if info.Outdated {
|
||||||
|
c.Ui.Output(fmt.Sprintf(
|
||||||
|
"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
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *VersionCommand) Synopsis() string {
|
||||||
|
return "Prints the Packer version"
|
||||||
|
}
|
10
commands.go
10
commands.go
|
@ -55,6 +55,16 @@ func init() {
|
||||||
Meta: meta,
|
Meta: meta,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"version": func() (cli.Command, error) {
|
||||||
|
return &command.VersionCommand{
|
||||||
|
Meta: meta,
|
||||||
|
Revision: GitCommit,
|
||||||
|
Version: Version,
|
||||||
|
VersionPrerelease: VersionPrerelease,
|
||||||
|
CheckFunc: commandVersionCheck,
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,11 @@ package common
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/multistep"
|
|
||||||
"github.com/mitchellh/packer/packer"
|
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
|
"github.com/mitchellh/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StepDownload downloads a remote file using the download client within
|
// StepDownload downloads a remote file using the download client within
|
||||||
|
@ -70,7 +71,7 @@ func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
CopyFile: false,
|
CopyFile: false,
|
||||||
Hash: HashForType(s.ChecksumType),
|
Hash: HashForType(s.ChecksumType),
|
||||||
Checksum: checksum,
|
Checksum: checksum,
|
||||||
UserAgent: packer.VersionString(),
|
UserAgent: "Packer",
|
||||||
}
|
}
|
||||||
|
|
||||||
path, err, retry := s.download(config, state)
|
path, err, retry := s.download(config, state)
|
||||||
|
|
4
main.go
4
main.go
|
@ -101,8 +101,8 @@ func wrappedMain() int {
|
||||||
log.SetOutput(os.Stderr)
|
log.SetOutput(os.Stderr)
|
||||||
|
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"Packer Version: %s %s %s",
|
"[INFO] Packer version: %s %s %s",
|
||||||
packer.Version, packer.VersionPrerelease, packer.GitCommit)
|
Version, VersionPrerelease, GitCommit)
|
||||||
log.Printf("Packer Target OS/Arch: %s %s", runtime.GOOS, runtime.GOARCH)
|
log.Printf("Packer Target OS/Arch: %s %s", runtime.GOOS, runtime.GOARCH)
|
||||||
log.Printf("Built with Go Version: %s", runtime.Version())
|
log.Printf("Built with Go Version: %s", runtime.Version())
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ package plugin
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/packer/packer"
|
|
||||||
packrpc "github.com/mitchellh/packer/packer/rpc"
|
packrpc "github.com/mitchellh/packer/packer/rpc"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -38,8 +37,6 @@ const APIVersion = "4"
|
||||||
// Server waits for a connection to this plugin and returns a Packer
|
// Server waits for a connection to this plugin and returns a Packer
|
||||||
// RPC server that you can use to register components and serve them.
|
// RPC server that you can use to register components and serve them.
|
||||||
func Server() (*packrpc.Server, error) {
|
func Server() (*packrpc.Server, error) {
|
||||||
log.Printf("Plugin build against Packer '%s'", packer.GitCommit)
|
|
||||||
|
|
||||||
if os.Getenv(MagicCookieKey) != MagicCookieValue {
|
if os.Getenv(MagicCookieKey) != MagicCookieValue {
|
||||||
return nil, errors.New(
|
return nil, errors.New(
|
||||||
"Please do not execute plugins directly. Packer will execute these for you.")
|
"Please do not execute plugins directly. Packer will execute these for you.")
|
||||||
|
|
|
@ -119,6 +119,8 @@ func ParseTemplate(data []byte, vars map[string]string) (t *Template, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rawTpl.MinimumPackerVersion != "" {
|
if rawTpl.MinimumPackerVersion != "" {
|
||||||
|
// TODO: NOPE! Replace this
|
||||||
|
Version := "1.0"
|
||||||
vCur, err := version.NewVersion(Version)
|
vCur, err := version.NewVersion(Version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
package packer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
// The git commit that is being compiled. This will be filled in by the
|
|
||||||
// compiler for source builds.
|
|
||||||
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.
|
|
||||||
const Version = "0.7.1"
|
|
||||||
|
|
||||||
// Any pre-release marker for the version. If this is "" (empty string),
|
|
||||||
// then it means that it is a final release. Otherwise, this is the
|
|
||||||
// pre-release marker.
|
|
||||||
const VersionPrerelease = ""
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
func (versionCommand) Help() string {
|
|
||||||
return `usage: packer version
|
|
||||||
|
|
||||||
Outputs the version of Packer that is running. There are no additional
|
|
||||||
command-line flags for this command.`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (versionCommand) Run(env Environment, args []string) int {
|
|
||||||
env.Ui().Machine("version", Version)
|
|
||||||
env.Ui().Machine("version-prelease", VersionPrerelease)
|
|
||||||
env.Ui().Machine("version-commit", GitCommit)
|
|
||||||
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("\nError checking latest version: %s", err))
|
|
||||||
}
|
|
||||||
if info.Outdated {
|
|
||||||
env.Ui().Say(fmt.Sprintf(
|
|
||||||
"\nYour 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
|
|
||||||
}
|
|
||||||
|
|
||||||
func (versionCommand) Synopsis() string {
|
|
||||||
return "print Packer version"
|
|
||||||
}
|
|
||||||
|
|
||||||
// VersionString returns the Packer version in human-readable
|
|
||||||
// form complete with pre-release and git commit info if it is
|
|
||||||
// available.
|
|
||||||
func VersionString() string {
|
|
||||||
var versionString bytes.Buffer
|
|
||||||
fmt.Fprintf(&versionString, "Packer v%s", Version)
|
|
||||||
if VersionPrerelease != "" {
|
|
||||||
fmt.Fprintf(&versionString, ".%s", VersionPrerelease)
|
|
||||||
|
|
||||||
if GitCommit != "" {
|
|
||||||
fmt.Fprintf(&versionString, " (%s)", GitCommit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return versionString.String()
|
|
||||||
}
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
// The git commit that was compiled. This will be filled in by the compiler.
|
||||||
|
var GitCommit string
|
||||||
|
|
||||||
|
// The main version number that is being run at the moment.
|
||||||
|
const Version = "0.8.0"
|
||||||
|
|
||||||
|
// A pre-release marker for the version. If this is "" (empty string)
|
||||||
|
// then it means that it is a final release. Otherwise, this is a pre-release
|
||||||
|
// such as "dev" (in development), "beta", "rc1", etc.
|
||||||
|
const VersionPrerelease = "dev"
|
Loading…
Reference in New Issue