diff --git a/builder/amazon/chroot/step_chroot_provision.go b/builder/amazon/chroot/step_chroot_provision.go index 09ad9b8c9..168b65bb8 100644 --- a/builder/amazon/chroot/step_chroot_provision.go +++ b/builder/amazon/chroot/step_chroot_provision.go @@ -1,14 +1,14 @@ package chroot import ( + "log" + "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" - "log" ) // StepChrootProvision provisions the instance within a chroot. type StepChrootProvision struct { - mounts []string } func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction { diff --git a/builder/amazon/chroot/step_prepare_device.go b/builder/amazon/chroot/step_prepare_device.go index d8683620b..62ac82b93 100644 --- a/builder/amazon/chroot/step_prepare_device.go +++ b/builder/amazon/chroot/step_prepare_device.go @@ -2,15 +2,15 @@ package chroot import ( "fmt" - "github.com/mitchellh/multistep" - "github.com/mitchellh/packer/packer" "log" "os" + + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" ) // StepPrepareDevice finds an available device and sets it. type StepPrepareDevice struct { - mounts []string } func (s *StepPrepareDevice) Run(state multistep.StateBag) multistep.StepAction { diff --git a/builder/azure/arm/step_get_certificate.go b/builder/azure/arm/step_get_certificate.go index 22403ea94..fb2a36ccc 100644 --- a/builder/azure/arm/step_get_certificate.go +++ b/builder/azure/arm/step_get_certificate.go @@ -13,12 +13,11 @@ import ( ) type StepGetCertificate struct { - client *AzureClient - template string - get func(keyVaultName string, secretName string) (string, error) - say func(message string) - error func(e error) - pause func() + client *AzureClient + get func(keyVaultName string, secretName string) (string, error) + say func(message string) + error func(e error) + pause func() } func NewStepGetCertificate(client *AzureClient, ui packer.Ui) *StepGetCertificate { diff --git a/builder/azure/pkcs12/pkcs12.go b/builder/azure/pkcs12/pkcs12.go index 316c2e731..7db1a2e05 100644 --- a/builder/azure/pkcs12/pkcs12.go +++ b/builder/azure/pkcs12/pkcs12.go @@ -30,23 +30,6 @@ type contentInfo struct { Content asn1.RawValue `asn1:"tag:0,explicit,optional"` } -type encryptedData struct { - Version int - EncryptedContentInfo encryptedContentInfo -} - -type encryptedContentInfo struct { - ContentType asn1.ObjectIdentifier - ContentEncryptionAlgorithm pkix.AlgorithmIdentifier - EncryptedContent []byte `asn1:"tag:0,optional"` -} - -func (i encryptedContentInfo) GetAlgorithm() pkix.AlgorithmIdentifier { - return i.ContentEncryptionAlgorithm -} - -func (i encryptedContentInfo) GetData() []byte { return i.EncryptedContent } - type safeBag struct { Id asn1.ObjectIdentifier Value asn1.RawValue `asn1:"tag:0,explicit"` diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index 330ea5900..fd8b7ba8a 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -54,7 +54,6 @@ type Config struct { Zone string `mapstructure:"zone"` Account AccountFile - privateKeyBytes []byte stateTimeout time.Duration imageAlreadyExists bool ctx interpolate.Context diff --git a/builder/googlecompute/step_instance_info.go b/builder/googlecompute/step_instance_info.go index 511906206..63653f420 100644 --- a/builder/googlecompute/step_instance_info.go +++ b/builder/googlecompute/step_instance_info.go @@ -12,8 +12,6 @@ import ( // stepInstanceInfo represents a Packer build step that gathers GCE instance info. type StepInstanceInfo struct { Debug bool - - info int } // Run executes the Packer build step that gathers GCE instance info. diff --git a/builder/hyperv/common/step_polling_installation.go b/builder/hyperv/common/step_polling_installation.go index 7cef6a108..aa61a1e53 100644 --- a/builder/hyperv/common/step_polling_installation.go +++ b/builder/hyperv/common/step_polling_installation.go @@ -3,18 +3,18 @@ package common import ( "bytes" "fmt" - "github.com/mitchellh/multistep" - "github.com/mitchellh/packer/packer" "log" "os/exec" "strings" "time" + + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" ) const port string = "13000" type StepPollingInstalation struct { - step int } func (s *StepPollingInstalation) Run(state multistep.StateBag) multistep.StepAction { diff --git a/builder/profitbricks/step_take_snapshot.go b/builder/profitbricks/step_take_snapshot.go index 6f06f446c..35820f3e1 100644 --- a/builder/profitbricks/step_take_snapshot.go +++ b/builder/profitbricks/step_take_snapshot.go @@ -2,8 +2,6 @@ package profitbricks import ( "encoding/json" - "errors" - "fmt" "time" "github.com/mitchellh/multistep" @@ -48,13 +46,6 @@ func (s *stepTakeSnapshot) Run(state multistep.StateBag) multistep.StepAction { func (s *stepTakeSnapshot) Cleanup(state multistep.StateBag) { } -func (d *stepTakeSnapshot) checkForErrors(instance profitbricks.Resp) error { - if instance.StatusCode > 299 { - return errors.New(fmt.Sprintf("Error occurred %s", string(instance.Body))) - } - return nil -} - func (d *stepTakeSnapshot) waitTillProvisioned(path string, config Config) { d.setPB(config.PBUsername, config.PBPassword, config.PBUrl) waitCount := 50 diff --git a/builder/qemu/step_wait_for_shutdown.go b/builder/qemu/step_wait_for_shutdown.go deleted file mode 100644 index 5418b967f..000000000 --- a/builder/qemu/step_wait_for_shutdown.go +++ /dev/null @@ -1,43 +0,0 @@ -package qemu - -import ( - "github.com/mitchellh/multistep" - "github.com/mitchellh/packer/packer" - "time" -) - -// stepWaitForShutdown waits for the shutdown of the currently running -// qemu VM. -type stepWaitForShutdown struct { - Message string -} - -func (s *stepWaitForShutdown) Run(state multistep.StateBag) multistep.StepAction { - driver := state.Get("driver").(Driver) - ui := state.Get("ui").(packer.Ui) - - stopCh := make(chan struct{}) - defer close(stopCh) - - cancelCh := make(chan struct{}) - go func() { - for { - if _, ok := state.GetOk(multistep.StateCancelled); ok { - close(cancelCh) - return - } - - select { - case <-stopCh: - return - case <-time.After(100 * time.Millisecond): - } - } - }() - - ui.Say(s.Message) - driver.WaitForShutdown(cancelCh) - return multistep.ActionContinue -} - -func (s *stepWaitForShutdown) Cleanup(state multistep.StateBag) {} diff --git a/builder/vmware/iso/output_dir.go b/builder/vmware/iso/output_dir.go index 0c08a225f..30eab2e31 100644 --- a/builder/vmware/iso/output_dir.go +++ b/builder/vmware/iso/output_dir.go @@ -1,10 +1,5 @@ package iso -import ( - "os" - "path/filepath" -) - // OutputDir is an interface type that abstracts the creation and handling // of the output directory for VMware-based products. The abstraction is made // so that the output directory can be properly made on remote (ESXi) based @@ -17,50 +12,3 @@ type OutputDir interface { RemoveAll() error SetOutputDir(string) } - -// localOutputDir is an OutputDir implementation where the directory -// is on the local machine. -type localOutputDir struct { - dir string -} - -func (d *localOutputDir) DirExists() (bool, error) { - _, err := os.Stat(d.dir) - return err == nil, nil -} - -func (d *localOutputDir) ListFiles() ([]string, error) { - files := make([]string, 0, 10) - - visit := func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() { - files = append(files, path) - } - return nil - } - - return files, filepath.Walk(d.dir, visit) -} - -func (d *localOutputDir) MkdirAll() error { - return os.MkdirAll(d.dir, 0755) -} - -func (d *localOutputDir) Remove(path string) error { - return os.Remove(path) -} - -func (d *localOutputDir) RemoveAll() error { - return os.RemoveAll(d.dir) -} - -func (d *localOutputDir) SetOutputDir(path string) { - d.dir = path -} - -func (d *localOutputDir) String() string { - return d.dir -} diff --git a/commands.go b/commands.go index 02d55c707..9b02b5941 100644 --- a/commands.go +++ b/commands.go @@ -1,9 +1,6 @@ package main import ( - "os" - "os/signal" - "github.com/mitchellh/cli" "github.com/mitchellh/packer/command" "github.com/mitchellh/packer/version" @@ -68,20 +65,3 @@ func init() { }, } } - -// makeShutdownCh creates an interrupt listener and returns a channel. -// A message will be sent on the channel for every interrupt received. -func makeShutdownCh() <-chan struct{} { - resultCh := make(chan struct{}) - - signalCh := make(chan os.Signal, 4) - signal.Notify(signalCh, os.Interrupt) - go func() { - for { - <-signalCh - resultCh <- struct{}{} - } - }() - - return resultCh -} diff --git a/main.go b/main.go index 5f760e824..06a4c7402 100644 --- a/main.go +++ b/main.go @@ -187,8 +187,6 @@ func wrappedMain() int { Ui: ui, } - //setupSignalHandlers(env) - cli := &cli.CLI{ Args: args, Commands: Commands, diff --git a/packer/rpc/dial.go b/packer/rpc/dial.go deleted file mode 100644 index 10e2cad14..000000000 --- a/packer/rpc/dial.go +++ /dev/null @@ -1,33 +0,0 @@ -package rpc - -import ( - "net" - "net/rpc" -) - -// rpcDial makes a TCP connection to a remote RPC server and returns -// the client. This will set the connection up properly so that keep-alives -// are set and so on and should be used to make all RPC connections within -// this package. -func rpcDial(address string) (*rpc.Client, error) { - tcpConn, err := tcpDial(address) - if err != nil { - return nil, err - } - - // Create an RPC client around our connection - return rpc.NewClient(tcpConn), nil -} - -// tcpDial connects via TCP to the designated address. -func tcpDial(address string) (*net.TCPConn, error) { - conn, err := net.Dial("tcp", address) - if err != nil { - return nil, err - } - - // Set a keep-alive so that the connection stays alive even when idle - tcpConn := conn.(*net.TCPConn) - tcpConn.SetKeepAlive(true) - return tcpConn, nil -} diff --git a/packer/rpc/post_processor.go b/packer/rpc/post_processor.go index b183780b9..5831b125e 100644 --- a/packer/rpc/post_processor.go +++ b/packer/rpc/post_processor.go @@ -1,8 +1,9 @@ package rpc import ( - "github.com/mitchellh/packer/packer" "net/rpc" + + "github.com/mitchellh/packer/packer" ) // An implementation of packer.PostProcessor where the PostProcessor is actually @@ -15,9 +16,8 @@ type postProcessor struct { // PostProcessorServer wraps a packer.PostProcessor implementation and makes it // exportable as part of a Golang RPC server. type PostProcessorServer struct { - client *rpc.Client - mux *muxBroker - p packer.PostProcessor + mux *muxBroker + p packer.PostProcessor } type PostProcessorConfigureArgs struct { diff --git a/packer/rpc/server.go b/packer/rpc/server.go index c82772049..ff1753269 100644 --- a/packer/rpc/server.go +++ b/packer/rpc/server.go @@ -4,14 +4,11 @@ import ( "io" "log" "net/rpc" - "sync/atomic" "github.com/mitchellh/packer/packer" "github.com/ugorji/go/codec" ) -var endpointId uint64 - const ( DefaultArtifactEndpoint string = "Artifact" DefaultBuildEndpoint = "Build" @@ -140,18 +137,3 @@ func (s *Server) Serve() { rpcCodec := codec.GoRpc.ServerCodec(stream, h) s.server.ServeCodec(rpcCodec) } - -// registerComponent registers a single Packer RPC component onto -// the RPC server. If id is true, then a unique ID number will be appended -// onto the end of the endpoint. -// -// The endpoint name is returned. -func registerComponent(server *rpc.Server, name string, rcvr interface{}, id bool) string { - endpoint := name - if id { - log.Printf("%s.%d", endpoint, atomic.AddUint64(&endpointId, 1)) - } - - server.RegisterName(endpoint, rcvr) - return endpoint -} diff --git a/post-processor/compress/artifact.go b/post-processor/compress/artifact.go index 4b19f779f..9bd89b213 100644 --- a/post-processor/compress/artifact.go +++ b/post-processor/compress/artifact.go @@ -8,8 +8,7 @@ import ( const BuilderId = "packer.post-processor.compress" type Artifact struct { - Path string - files []string + Path string } func (a *Artifact) BuilderId() string { diff --git a/provisioner/chef-client/provisioner.go b/provisioner/chef-client/provisioner.go index aeac7d274..a0be8df9b 100644 --- a/provisioner/chef-client/provisioner.go +++ b/provisioner/chef-client/provisioner.go @@ -319,20 +319,6 @@ func (p *Provisioner) Cancel() { os.Exit(0) } -func (p *Provisioner) uploadDirectory(ui packer.Ui, comm packer.Communicator, dst string, src string) error { - if err := p.createDir(ui, comm, dst); err != nil { - return err - } - - // Make sure there is a trailing "/" so that the directory isn't - // created on the other side. - if src[len(src)-1] != '/' { - src = src + "/" - } - - return comm.UploadDir(dst, src, nil) -} - func (p *Provisioner) uploadFile(ui packer.Ui, comm packer.Communicator, remotePath string, localPath string) error { ui.Message(fmt.Sprintf("Uploading %s...", localPath)) diff --git a/signal.go b/signal.go deleted file mode 100644 index 8846a3451..000000000 --- a/signal.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "log" - "os" - "os/signal" - "syscall" - - "github.com/mitchellh/packer/packer" - "github.com/mitchellh/packer/packer/plugin" -) - -// Prepares the signal handlers so that we handle interrupts properly. -// The signal handler exists in a goroutine. -func setupSignalHandlers(ui packer.Ui) { - ch := make(chan os.Signal, 1) - signal.Notify(ch, os.Interrupt) - signal.Notify(ch, syscall.SIGTERM) - - go func() { - // First interrupt. We mostly ignore this because it allows the - // plugins time to cleanup. - <-ch - log.Println("First interrupt. Ignoring to allow plugins to clean up.") - - ui.Error("Interrupt signal received. Cleaning up...") - - // Second interrupt. Go down hard. - <-ch - log.Println("Second interrupt. Exiting now.") - - ui.Error("Interrupt signal received twice. Forcefully exiting now.") - - // Force kill all the plugins, but mark that we're killing them - // first so that we don't get panics everywhere. - plugin.CleanupClients() - os.Exit(1) - }() -} diff --git a/template/interpolate/render.go b/template/interpolate/render.go index 2120c171f..4c49d43b8 100644 --- a/template/interpolate/render.go +++ b/template/interpolate/render.go @@ -147,14 +147,13 @@ type renderWalker struct { // If it is nil, it means the top wasn't replaced. Top interface{} - key []string - lastValue reflect.Value - loc reflectwalk.Location - cs []reflect.Value - csKey []reflect.Value - csData interface{} - sliceIndex int - unknownKeys []string + key []string + lastValue reflect.Value + loc reflectwalk.Location + cs []reflect.Value + csKey []reflect.Value + csData interface{} + sliceIndex int } // renderWalkerFunc is the callback called by interpolationWalk. @@ -281,34 +280,3 @@ func (w *renderWalker) Primitive(v reflect.Value) error { return nil } - -func (w *renderWalker) removeCurrent() { - // Append the key to the unknown keys - w.unknownKeys = append(w.unknownKeys, strings.Join(w.key, ".")) - - for i := 1; i <= len(w.cs); i++ { - c := w.cs[len(w.cs)-i] - switch c.Kind() { - case reflect.Map: - // Zero value so that we delete the map key - var val reflect.Value - - // Get the key and delete it - k := w.csData.(reflect.Value) - c.SetMapIndex(k, val) - return - } - } - - panic("No container found for removeCurrent") -} - -func (w *renderWalker) replaceCurrent(v reflect.Value) { - c := w.cs[len(w.cs)-2] - switch c.Kind() { - case reflect.Map: - // Get the key and delete it - k := w.csKey[len(w.csKey)-1] - c.SetMapIndex(k, v) - } -}