add Source attribute to File

Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
This commit is contained in:
Chanwit Kaewkasi 2017-05-12 00:56:33 +07:00
parent ba07bbfb0d
commit d83c35259a
2 changed files with 21 additions and 9 deletions

View File

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -34,6 +35,7 @@ type Moby struct {
Directory bool Directory bool
Symlink string Symlink string
Contents string Contents string
Source string
} }
Outputs []struct { Outputs []struct {
Format string Format string
@ -440,7 +442,16 @@ func filesystem(m *Moby) (*bytes.Buffer, error) {
return buf, errors.New("Did not specify path for file") return buf, errors.New("Did not specify path for file")
} }
if !f.Directory && f.Contents == "" && f.Symlink == "" { 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 // we need all the leading directories
parts := strings.Split(path.Dir(f.Path), "/") parts := strings.Split(path.Dir(f.Path), "/")

View File

@ -21,11 +21,12 @@ var schema = string(`
"path": {"type": "string"}, "path": {"type": "string"},
"directory": {"type": "boolean"}, "directory": {"type": "boolean"},
"symlink": {"type": "string"}, "symlink": {"type": "string"},
"contents": {"type": "string"} "contents": {"type": "string"},
"source": {"type": "string"}
} }
}, },
"files": { "files": {
"type": "array", "type": "array",
"items": { "$ref": "#/definitions/file" } "items": { "$ref": "#/definitions/file" }
}, },
"output": { "output": {
@ -36,7 +37,7 @@ var schema = string(`
} }
}, },
"outputs": { "outputs": {
"type": "array", "type": "array",
"items": { "$ref": "#/definitions/output" } "items": { "$ref": "#/definitions/output" }
}, },
"trust": { "trust": {
@ -48,7 +49,7 @@ var schema = string(`
} }
}, },
"strings": { "strings": {
"type": "array", "type": "array",
"items": {"type": "string"} "items": {"type": "string"}
}, },
"mount": { "mount": {
@ -89,7 +90,7 @@ var schema = string(`
"uid": {"type": "integer"}, "uid": {"type": "integer"},
"gid": {"type": "integer"}, "gid": {"type": "integer"},
"additionalGids": { "additionalGids": {
"type": "array", "type": "array",
"items": { "type": "integer" } "items": { "type": "integer" }
}, },
"noNewPrivileges": {"type": "boolean"}, "noNewPrivileges": {"type": "boolean"},
@ -99,18 +100,18 @@ var schema = string(`
"rootfsPropagation": {"type": "string"}, "rootfsPropagation": {"type": "string"},
"cgroupsPath": {"type": "string"}, "cgroupsPath": {"type": "string"},
"sysctl": { "sysctl": {
"type": "array", "type": "array",
"items": { "$ref": "#/definitions/strings" } "items": { "$ref": "#/definitions/strings" }
} }
} }
}, },
"images": { "images": {
"type": "array", "type": "array",
"items": { "$ref": "#/definitions/image" } "items": { "$ref": "#/definitions/image" }
} }
}, },
"properties": { "properties": {
"kernel": { "$ref": "#/definitions/kernel" }, "kernel": { "$ref": "#/definitions/kernel" },
"init": { "$ref": "#/definitions/strings" }, "init": { "$ref": "#/definitions/strings" },
"onboot": { "$ref": "#/definitions/images" }, "onboot": { "$ref": "#/definitions/images" },
"services": { "$ref": "#/definitions/images" }, "services": { "$ref": "#/definitions/images" },