Skip to content

Commit

Permalink
Merge pull request #4708 from mitchellh/nullablecopyfiles
Browse files Browse the repository at this point in the history
builder/amazon-chroot: nullable copy_files
  • Loading branch information
mwhooker authored Mar 24, 2017
2 parents 0c4b67f + 506a1e6 commit c8113e8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
12 changes: 6 additions & 6 deletions builder/amazon/chroot/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.ChrootMounts = make([][]string, 0)
}

if b.config.CopyFiles == nil {
b.config.CopyFiles = make([]string, 0)
}

if len(b.config.ChrootMounts) == 0 {
b.config.ChrootMounts = [][]string{
{"proc", "proc", "/proc"},
Expand All @@ -101,8 +97,12 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
}

if len(b.config.CopyFiles) == 0 && !b.config.FromScratch {
b.config.CopyFiles = []string{"/etc/resolv.conf"}
// set default copy file if we're not giving our own
if b.config.CopyFiles == nil {
b.config.CopyFiles = make([]string, 0)
if !b.config.FromScratch {
b.config.CopyFiles = []string{"/etc/resolv.conf"}
}
}

if b.config.CommandWrapper == "" {
Expand Down
33 changes: 32 additions & 1 deletion builder/amazon/chroot/builder_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package chroot

import (
"github.com/mitchellh/packer/packer"
"testing"

"github.com/mitchellh/packer/packer"
)

func testConfig() map[string]interface{} {
Expand Down Expand Up @@ -117,3 +118,33 @@ func TestBuilderPrepare_CommandWrapper(t *testing.T) {
t.Errorf("err: %s", err)
}
}

func TestBuilderPrepare_CopyFiles(t *testing.T) {
b := &Builder{}
config := testConfig()

warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Errorf("err: %s", err)
}

if len(b.config.CopyFiles) != 1 && b.config.CopyFiles[0] != "/etc/resolv.conf" {
t.Errorf("Was expecting default value for copy_files.")
}

config["copy_files"] = []string{}
warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Errorf("err: %s", err)
}

if len(b.config.CopyFiles) > 0 {
t.Errorf("Was expecting no default value for copy_files.")
}
}
3 changes: 2 additions & 1 deletion website/source/docs/builders/amazon-chroot.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ each category, the available configuration keys are alphabetized.

- `copy_files` (array of strings) - Paths to files on the running EC2 instance
that will be copied into the chroot environment prior to provisioning. Defaults
to `/etc/resolv.conf` so that DNS lookups work.
to `/etc/resolv.conf` so that DNS lookups work. Pass an empty list to skip
copying `/etc/resolv.conf`.

- `device_path` (string) - The path to the device where the root volume of the
source AMI will be attached. This defaults to "" (empty string), which
Expand Down

0 comments on commit c8113e8

Please sign in to comment.