Skip to content

Commit

Permalink
Use the hashicorp/go-getter to download files
Browse files Browse the repository at this point in the history
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
  • Loading branch information
azr committed Mar 13, 2019
1 parent 0196d7f commit 9f82b75
Show file tree
Hide file tree
Showing 1,367 changed files with 186,841 additions and 43,625 deletions.
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ build_script:
- git rev-parse HEAD
# go test $(go list ./... | grep -v vendor)
- ps: |
go.exe test -timeout=2m (go.exe list ./... `
go.exe test -v -timeout=2m (go.exe list ./... `
|? { -not $_.Contains('/vendor/') } `
|? { $_ -ne 'github.com/hashicorp/packer/builder/parallels/common' } `
|? { $_ -ne 'github.com/hashicorp/packer/common' }`
|? { $_ -ne 'github.com/hashicorp/packer/provisioner/ansible' })
test: off
Expand Down
2 changes: 1 addition & 1 deletion builder/alicloud/ecs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

client, err := b.config.Client()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion builder/amazon/chroot/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return warns, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
if runtime.GOOS != "linux" {
return nil, errors.New("The amazon-chroot builder only works on Linux environments.")
}
Expand Down
3 changes: 2 additions & 1 deletion builder/amazon/ebs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

session, err := b.config.Session()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion builder/amazon/ebssurrogate/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
session, err := b.config.Session()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion builder/amazon/ebsvolume/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
session, err := b.config.Session()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion builder/amazon/instance/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
session, err := b.config.Session()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion builder/azure/arm/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return warnings, errs
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

ui.Say("Running builder ...")

Expand Down
2 changes: 1 addition & 1 deletion builder/cloudstack/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}

// Run implements the packer.Builder interface.
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
b.ui = ui

// Create a CloudStack API client.
Expand Down
2 changes: 1 addition & 1 deletion builder/digitalocean/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
client := godo.NewClient(oauth2.NewClient(oauth2.NoContext, &apiTokenSource{
AccessToken: b.config.APIToken,
}))
Expand Down
2 changes: 1 addition & 1 deletion builder/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return warnings, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
driver := &DockerDriver{Ctx: &b.config.ctx, Ui: ui}
if err := driver.Verify(); err != nil {
return nil, err
Expand Down
9 changes: 3 additions & 6 deletions builder/docker/communicator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func TestCommunicator_impl(t *testing.T) {
// TestUploadDownload verifies that basic upload / download functionality works
func TestUploadDownload(t *testing.T) {
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}

tpl, err := template.Parse(strings.NewReader(dockerBuilderConfig))
if err != nil {
Expand Down Expand Up @@ -76,7 +75,7 @@ func TestUploadDownload(t *testing.T) {
hook := &packer.DispatchHook{Mapping: hooks}

// Run things
artifact, err := builder.Run(ui, hook, cache)
artifact, err := builder.Run(ui, hook)
if err != nil {
t.Fatalf("Error running build %s", err)
}
Expand Down Expand Up @@ -105,7 +104,6 @@ func TestUploadDownload(t *testing.T) {
// only intermittently.
func TestLargeDownload(t *testing.T) {
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}

tpl, err := template.Parse(strings.NewReader(dockerLargeBuilderConfig))
if err != nil {
Expand Down Expand Up @@ -166,7 +164,7 @@ func TestLargeDownload(t *testing.T) {
hook := &packer.DispatchHook{Mapping: hooks}

// Run things
artifact, err := builder.Run(ui, hook, cache)
artifact, err := builder.Run(ui, hook)
if err != nil {
t.Fatalf("Error running build %s", err)
}
Expand Down Expand Up @@ -210,7 +208,6 @@ func TestLargeDownload(t *testing.T) {
// TestFixUploadOwner verifies that owner of uploaded files is the user the container is running as.
func TestFixUploadOwner(t *testing.T) {
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}

tpl, err := template.Parse(strings.NewReader(testFixUploadOwnerTemplate))
if err != nil {
Expand Down Expand Up @@ -275,7 +272,7 @@ func TestFixUploadOwner(t *testing.T) {
}
hook := &packer.DispatchHook{Mapping: hooks}

artifact, err := builder.Run(ui, hook, cache)
artifact, err := builder.Run(ui, hook)
if err != nil {
t.Fatalf("Error running build %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion builder/file/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}

// Run is where the actual build should take place. It takes a Build and a Ui.
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
artifact := new(FileArtifact)

if b.config.Source != "" {
Expand Down
2 changes: 1 addition & 1 deletion builder/googlecompute/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {

// Run executes a googlecompute Packer build and returns a packer.Artifact
// representing a GCE machine image.
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
driver, err := NewDriverGCE(
ui, b.config.ProjectId, &b.config.Account)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion builder/hcloud/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
opts := []hcloud.ClientOption{
hcloud.WithToken(b.config.HCloudToken),
hcloud.WithEndpoint(b.config.Endpoint),
Expand Down
4 changes: 2 additions & 2 deletions builder/hyperone/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
"github.com/hyperonecom/h1-client-go"
openapi "github.com/hyperonecom/h1-client-go"
)

const BuilderID = "hyperone.builder"
Expand Down Expand Up @@ -50,7 +50,7 @@ type wrappedCommandTemplate struct {
Command string
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
wrappedCommand := func(command string) (string, error) {
ctx := b.config.ctx
ctx.Data = &wrappedCommandTemplate{Command: command}
Expand Down
3 changes: 1 addition & 2 deletions builder/hyperv/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {

// Run executes a Packer build and returns a packer.Artifact representing
// a Hyperv appliance.
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Create the driver that we'll use to communicate with Hyperv
driver, err := hypervcommon.NewHypervPS4Driver()
if err != nil {
Expand All @@ -365,7 +365,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe

// Set up the state.
state := new(multistep.BasicStateBag)
state.Put("cache", cache)
state.Put("config", &b.config)
state.Put("debug", b.config.PackerDebug)
state.Put("driver", driver)
Expand Down
12 changes: 3 additions & 9 deletions builder/hyperv/iso/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package iso
import (
"context"
"fmt"
"os"
"reflect"
"strconv"
"testing"
Expand Down Expand Up @@ -287,9 +286,6 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
t.Fatalf("should not have error: %s", err)
}

if b.config.ISOChecksum != "foo" {
t.Fatalf("should've lowercased: %s", b.config.ISOChecksum)
}
}

func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
Expand All @@ -302,8 +298,8 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil {
t.Fatal("should have error")
if err != nil {
t.Fatalf("should not have error: %s", err)
}

// Test good
Expand All @@ -329,7 +325,7 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
t.Fatalf("bad: %#v", warns)
}
if err == nil {
t.Fatal("should have error")
t.Log("should error in prepare but go-getter doesn't let us validate yet. This will fail before dl.")
}

// Test none
Expand Down Expand Up @@ -606,13 +602,11 @@ func TestUserVariablesInBootCommand(t *testing.T) {
}

ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}
hook := &packer.MockHook{}
driver := &hypervcommon.DriverMock{}

// Set up the state.
state := new(multistep.BasicStateBag)
state.Put("cache", cache)
state.Put("config", &b.config)
state.Put("driver", driver)
state.Put("hook", hook)
Expand Down
3 changes: 1 addition & 2 deletions builder/hyperv/vmcx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {

// Run executes a Packer build and returns a packer.Artifact representing
// a Hyperv appliance.
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
// Create the driver that we'll use to communicate with Hyperv
driver, err := hypervcommon.NewHypervPS4Driver()
if err != nil {
Expand All @@ -381,7 +381,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe

// Set up the state.
state := new(multistep.BasicStateBag)
state.Put("cache", cache)
state.Put("config", &b.config)
state.Put("debug", b.config.PackerDebug)
state.Put("driver", driver)
Expand Down
20 changes: 2 additions & 18 deletions builder/hyperv/vmcx/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
t.Fatalf("should not have error: %s", err)
}

if b.config.ISOChecksum != "foo" {
t.Fatalf("should've lowercased: %s", b.config.ISOChecksum)
}
}

func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
Expand All @@ -226,8 +223,8 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil {
t.Fatal("should have error")
if err != nil {
t.Fatalf("should not have error: %s", err)
}

// Test good
Expand All @@ -245,17 +242,6 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
t.Fatalf("should've lowercased: %s", b.config.ISOChecksumType)
}

// Test unknown
config["iso_checksum_type"] = "fake"
b = Builder{}
warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil {
t.Fatal("should have error")
}

// Test none
config["iso_checksum_type"] = "none"
b = Builder{}
Expand Down Expand Up @@ -517,13 +503,11 @@ func TestUserVariablesInBootCommand(t *testing.T) {
}

ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}
hook := &packer.MockHook{}
driver := &hypervcommon.DriverMock{}

// Set up the state.
state := new(multistep.BasicStateBag)
state.Put("cache", cache)
state.Put("config", &b.config)
state.Put("driver", driver)
state.Put("hook", hook)
Expand Down
3 changes: 1 addition & 2 deletions builder/lxc/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
wrappedCommand := func(command string) (string, error) {
b.config.ctx.Data = &wrappedCommandTemplate{Command: command}
return interpolate.Render(b.config.CommandWrapper, &b.config.ctx)
Expand All @@ -52,7 +52,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Setup the state bag
state := new(multistep.BasicStateBag)
state.Put("config", b.config)
state.Put("cache", cache)
state.Put("hook", hook)
state.Put("ui", ui)
state.Put("wrappedCommand", CommandWrapper(wrappedCommand))
Expand Down
3 changes: 1 addition & 2 deletions builder/lxd/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
wrappedCommand := func(command string) (string, error) {
b.config.ctx.Data = &wrappedCommandTemplate{Command: command}
return interpolate.Render(b.config.CommandWrapper, &b.config.ctx)
Expand All @@ -46,7 +46,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Setup the state bag
state := new(multistep.BasicStateBag)
state.Put("config", b.config)
state.Put("cache", cache)
state.Put("hook", hook)
state.Put("ui", ui)
state.Put("wrappedCommand", CommandWrapper(wrappedCommand))
Expand Down
2 changes: 1 addition & 1 deletion builder/ncloud/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return warnings, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
ui.Message("Creating Naver Cloud Platform Connection ...")
conn := ncloud.NewConnection(b.config.AccessKey, b.config.SecretKey)

Expand Down
2 changes: 1 addition & 1 deletion builder/null/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return warnings, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
steps := []multistep.Step{}

if b.config.CommConfig.Type != "none" {
Expand Down
2 changes: 1 addition & 1 deletion builder/oneandone/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return warnings, nil
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

state := new(multistep.BasicStateBag)

Expand Down
Loading

0 comments on commit 9f82b75

Please sign in to comment.