diff --git a/cmd/moby/build.go b/cmd/moby/build.go index 1201fd407..1a373ed19 100644 --- a/cmd/moby/build.go +++ b/cmd/moby/build.go @@ -568,7 +568,11 @@ func filesystem(m Moby, tw *tar.Writer) error { if dirMode&0007 != 0 { dirMode |= 0001 } - if !f.Directory && f.Contents == "" && f.Symlink == "" { + var contents []byte + if f.Contents != nil { + contents = []byte(*f.Contents) + } + if !f.Directory && f.Contents == nil && f.Symlink == "" { if f.Source == "" { return errors.New("Contents of file not specified") } @@ -583,12 +587,11 @@ func filesystem(m Moby, tw *tar.Writer) error { continue } } - contents, err := ioutil.ReadFile(f.Source) + var err error + contents, err = ioutil.ReadFile(f.Source) if err != nil { return err } - - f.Contents = string(contents) } // we need all the leading directories parts := strings.Split(path.Dir(f.Path), "/") @@ -617,7 +620,7 @@ func filesystem(m Moby, tw *tar.Writer) error { } addedFiles[f.Path] = true if f.Directory { - if f.Contents != "" { + if f.Contents != nil { return errors.New("Directory with contents not allowed") } hdr := &tar.Header{ @@ -644,13 +647,13 @@ func filesystem(m Moby, tw *tar.Writer) error { hdr := &tar.Header{ Name: f.Path, Mode: mode, - Size: int64(len(f.Contents)), + Size: int64(len(contents)), } err := tw.WriteHeader(hdr) if err != nil { return err } - _, err = tw.Write([]byte(f.Contents)) + _, err = tw.Write(contents) if err != nil { return err } diff --git a/cmd/moby/config.go b/cmd/moby/config.go index c7bbe08f2..d3398ff4d 100644 --- a/cmd/moby/config.go +++ b/cmd/moby/config.go @@ -31,7 +31,7 @@ type Moby struct { Path string Directory bool Symlink string - Contents string + Contents *string Source string Optional bool Mode string diff --git a/test/test.yml b/test/test.yml index 41488d860..3a91b06e7 100644 --- a/test/test.yml +++ b/test/test.yml @@ -29,6 +29,8 @@ services: files: - path: etc/docker/daemon.json contents: '{"debug": true}' + - path: /empty + contents: "" trust: org: - library