This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compose.go
63 lines (52 loc) · 1.65 KB
/
compose.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package compose
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
// DockerCompose is an object which encapsulates a Docker Compose file.
type DockerCompose struct {
Services map[string]Service
}
// Service a service declared in a Docker Compose file.
type Service struct {
Image string `yaml:"image"`
Build string `yaml:"build"`
Volumes []string `yaml:"volumes"`
Entrypoint []string `yaml:"entrypoint"`
Ports []string `yaml:"ports"`
Environment []string `yaml:"environment"`
CapAdd []string `yaml:"cap_add"`
Tmpfs []string `yaml:"tmpfs"`
Deploy ServiceDeploy `yaml:"deploy"`
ExtraHosts []string `yaml:"extra_hosts"`
Labels map[string]string `yaml:"labels"`
}
// ServiceDeploy provides deployment information for a service.
type ServiceDeploy struct {
Resources ServiceDeployResources `yaml:"resources"`
}
// ServiceDeployResources provides deployment resources information for a service.
type ServiceDeployResources struct {
Limits ServiceDeployResource `yaml:"limits"`
Reservations ServiceDeployResource `yaml:"reservations"`
}
// ServiceDeployResource provides a single deployment resource information for a service.
type ServiceDeployResource struct {
CPUs string `yaml:"cpus"`
Memory string `yaml:"memory"`
}
// Load the Docker Compose files.
func Load(paths []string) (DockerCompose, error) {
var dc DockerCompose
for _, path := range paths {
file, err := ioutil.ReadFile(path)
if err != nil {
return dc, err
}
err = yaml.Unmarshal(file, &dc)
if err != nil {
return dc, err
}
}
return dc, nil
}