Merge pull request #27 from chanwit/add_source

add Source attribute to File
This commit is contained in:
Justin Cormack 2017-05-22 11:28:06 +01:00 committed by GitHub
commit b47f3dec4a
2 changed files with 21 additions and 9 deletions

View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
@ -35,6 +36,7 @@ type Moby struct {
Directory bool
Symlink string
Contents string
Source string
}
Outputs []struct {
Format string
@ -671,7 +673,16 @@ func filesystem(m Moby) (*bytes.Buffer, error) {
return buf, errors.New("Did not specify path for file")
}
if !f.Directory && f.Contents == "" && f.Symlink == "" {
return buf, errors.New("Contents of file not specified")
if f.Source == "" {
return buf, errors.New("Contents of file not specified")
}
contents, err := ioutil.ReadFile(f.Source)
if err != nil {
return buf, err
}
f.Contents = string(contents)
}
// we need all the leading directories
parts := strings.Split(path.Dir(f.Path), "/")

View File

@ -21,7 +21,8 @@ var schema = string(`
"path": {"type": "string"},
"directory": {"type": "boolean"},
"symlink": {"type": "string"},
"contents": {"type": "string"}
"contents": {"type": "string"},
"source": {"type": "string"}
}
},
"files": {