1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package v1
16
17 import (
18 "encoding/json"
19 "io"
20 "time"
21 )
22
23
24
25
26
27
28
29 type ConfigFile struct {
30 Architecture string `json:"architecture"`
31 Author string `json:"author,omitempty"`
32 Container string `json:"container,omitempty"`
33 Created Time `json:"created,omitempty"`
34 DockerVersion string `json:"docker_version,omitempty"`
35 History []History `json:"history,omitempty"`
36 OS string `json:"os"`
37 RootFS RootFS `json:"rootfs"`
38 Config Config `json:"config"`
39 OSVersion string `json:"os.version,omitempty"`
40 Variant string `json:"variant,omitempty"`
41 OSFeatures []string `json:"os.features,omitempty"`
42 }
43
44
45 func (cf *ConfigFile) Platform() *Platform {
46 if cf.OS == "" && cf.Architecture == "" && cf.OSVersion == "" && cf.Variant == "" && len(cf.OSFeatures) == 0 {
47 return nil
48 }
49 return &Platform{
50 OS: cf.OS,
51 Architecture: cf.Architecture,
52 OSVersion: cf.OSVersion,
53 Variant: cf.Variant,
54 OSFeatures: cf.OSFeatures,
55 }
56 }
57
58
59 type History struct {
60 Author string `json:"author,omitempty"`
61 Created Time `json:"created,omitempty"`
62 CreatedBy string `json:"created_by,omitempty"`
63 Comment string `json:"comment,omitempty"`
64 EmptyLayer bool `json:"empty_layer,omitempty"`
65 }
66
67
68 type Time struct {
69 time.Time
70 }
71
72
73
74
75 func (t *Time) DeepCopyInto(out *Time) {
76 *out = *t
77 }
78
79
80
81 type RootFS struct {
82 Type string `json:"type"`
83 DiffIDs []Hash `json:"diff_ids"`
84 }
85
86
87 type HealthConfig struct {
88
89
90
91
92
93
94
95 Test []string `json:",omitempty"`
96
97
98 Interval time.Duration `json:",omitempty"`
99 Timeout time.Duration `json:",omitempty"`
100 StartPeriod time.Duration `json:",omitempty"`
101
102
103
104 Retries int `json:",omitempty"`
105 }
106
107
108
109
110
111
112
113
114
115
116
117 type Config struct {
118 AttachStderr bool `json:"AttachStderr,omitempty"`
119 AttachStdin bool `json:"AttachStdin,omitempty"`
120 AttachStdout bool `json:"AttachStdout,omitempty"`
121 Cmd []string `json:"Cmd,omitempty"`
122 Healthcheck *HealthConfig `json:"Healthcheck,omitempty"`
123 Domainname string `json:"Domainname,omitempty"`
124 Entrypoint []string `json:"Entrypoint,omitempty"`
125 Env []string `json:"Env,omitempty"`
126 Hostname string `json:"Hostname,omitempty"`
127 Image string `json:"Image,omitempty"`
128 Labels map[string]string `json:"Labels,omitempty"`
129 OnBuild []string `json:"OnBuild,omitempty"`
130 OpenStdin bool `json:"OpenStdin,omitempty"`
131 StdinOnce bool `json:"StdinOnce,omitempty"`
132 Tty bool `json:"Tty,omitempty"`
133 User string `json:"User,omitempty"`
134 Volumes map[string]struct{} `json:"Volumes,omitempty"`
135 WorkingDir string `json:"WorkingDir,omitempty"`
136 ExposedPorts map[string]struct{} `json:"ExposedPorts,omitempty"`
137 ArgsEscaped bool `json:"ArgsEscaped,omitempty"`
138 NetworkDisabled bool `json:"NetworkDisabled,omitempty"`
139 MacAddress string `json:"MacAddress,omitempty"`
140 StopSignal string `json:"StopSignal,omitempty"`
141 Shell []string `json:"Shell,omitempty"`
142 }
143
144
145 func ParseConfigFile(r io.Reader) (*ConfigFile, error) {
146 cf := ConfigFile{}
147 if err := json.NewDecoder(r).Decode(&cf); err != nil {
148 return nil, err
149 }
150 return &cf, nil
151 }
152
View as plain text