diff --git a/cmd/moby/build.go b/cmd/moby/build.go index f550cba01..4ea263300 100644 --- a/cmd/moby/build.go +++ b/cmd/moby/build.go @@ -574,6 +574,14 @@ func filesystem(m Moby, tw *tar.Writer) error { if len(f.Source) > 2 && f.Source[:2] == "~/" { f.Source = homeDir() + f.Source[1:] } + if f.Optional { + _, err := os.Stat(f.Source) + if err != nil { + // skip if not found or readable + log.Debugf("Skipping file [%s] as not readable and marked optional", f.Source) + continue + } + } contents, err := ioutil.ReadFile(f.Source) if err != nil { return err diff --git a/cmd/moby/config.go b/cmd/moby/config.go index 4f100e9b7..2650b610b 100644 --- a/cmd/moby/config.go +++ b/cmd/moby/config.go @@ -32,6 +32,7 @@ type Moby struct { Symlink string Contents string Source string + Optional bool Mode string } } diff --git a/cmd/moby/schema.go b/cmd/moby/schema.go index ddfed0d45..5444cf47d 100644 --- a/cmd/moby/schema.go +++ b/cmd/moby/schema.go @@ -23,6 +23,7 @@ var schema = string(` "symlink": {"type": "string"}, "contents": {"type": "string"}, "source": {"type": "string"}, + "optional": {"type": "boolean"}, "mode": {"type": "string"} } }, diff --git a/docs/yaml.md b/docs/yaml.md index 7ac729747..af23567a8 100644 --- a/docs/yaml.md +++ b/docs/yaml.md @@ -58,12 +58,17 @@ files: source: "/some/path/on/local/filesystem" mode: "0666" - path: dir/name2 + source: "/some/path/that/it/is/ok/to/omit" + optional: true + mode: "0666" + - path: dir/name3 contents: "orange" mode: "0644" ``` Specifying the `mode` is optional, and will default to `0600`. Leading directories will be -created if not specified. +created if not specified. You can use `~/path` in `source` to specify a path in the build +user's home directory. ## `trust`