-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathspec.go
47 lines (41 loc) · 1021 Bytes
/
spec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package codetainer
import (
"encoding/json"
"fmt"
"io"
"os"
docker "github.com/fsouza/go-dockerclient"
)
var defaultSpec string = `
{
"Config": {
"NetworkDisabled": false
},
"HostConfig": {
"Privileged": false,
"ReadonlyRootfs": false,
"Ulimits": [{ "Name": "nofile", "Soft": 1024, "Hard": 2048 }]
}
}`
type CodetainerProfileSpec struct {
Config *docker.Config `json:"Config,omitempty" yaml:"Config,omitempty"`
HostConfig *docker.HostConfig `json:"HostConfig,omitempty" yaml:"HostConfig,omitempty"`
}
func parseJsonSpec(reader io.Reader) (*CodetainerProfileSpec, error) {
var s *CodetainerProfileSpec
if err := json.NewDecoder(reader).Decode(&s); err != nil {
return nil, err
}
return s, nil
}
func loadJsonSpec(path string) (*CodetainerProfileSpec, error) {
f, err := os.Open(path)
if err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("JSON specification file for %s not found", path)
}
return nil, err
}
defer f.Close()
return parseJsonSpec(f)
}