github.com/bdwilliams/libcompose@v0.3.1-0.20160826154243-d81a9bdacff0/config/types.go (about) 1 package config 2 3 import ( 4 "sync" 5 6 "github.com/docker/libcompose/yaml" 7 ) 8 9 // EnvironmentLookup defines methods to provides environment variable loading. 10 type EnvironmentLookup interface { 11 Lookup(key, serviceName string, config *ServiceConfig) []string 12 } 13 14 // ResourceLookup defines methods to provides file loading. 15 type ResourceLookup interface { 16 Lookup(file, relativeTo string) ([]byte, string, error) 17 ResolvePath(path, inFile string) string 18 } 19 20 // ServiceConfigV1 holds version 1 of libcompose service configuration 21 type ServiceConfigV1 struct { 22 Build string `yaml:"build,omitempty"` 23 CapAdd []string `yaml:"cap_add,omitempty"` 24 CapDrop []string `yaml:"cap_drop,omitempty"` 25 CgroupParent string `yaml:"cgroup_parent,omitempty"` 26 CPUQuota yaml.StringorInt `yaml:"cpu_quota,omitempty"` 27 CPUSet string `yaml:"cpuset,omitempty"` 28 CPUShares yaml.StringorInt `yaml:"cpu_shares,omitempty"` 29 Command yaml.Command `yaml:"command,flow,omitempty"` 30 ContainerName string `yaml:"container_name,omitempty"` 31 Devices []string `yaml:"devices,omitempty"` 32 DNS yaml.Stringorslice `yaml:"dns,omitempty"` 33 DNSSearch yaml.Stringorslice `yaml:"dns_search,omitempty"` 34 Dockerfile string `yaml:"dockerfile,omitempty"` 35 DomainName string `yaml:"domainname,omitempty"` 36 Entrypoint yaml.Command `yaml:"entrypoint,flow,omitempty"` 37 EnvFile yaml.Stringorslice `yaml:"env_file,omitempty"` 38 Environment yaml.MaporEqualSlice `yaml:"environment,omitempty"` 39 Hostname string `yaml:"hostname,omitempty"` 40 Image string `yaml:"image,omitempty"` 41 Labels yaml.SliceorMap `yaml:"labels,omitempty"` 42 Links yaml.MaporColonSlice `yaml:"links,omitempty"` 43 LogDriver string `yaml:"log_driver,omitempty"` 44 MacAddress string `yaml:"mac_address,omitempty"` 45 MemLimit yaml.StringorInt `yaml:"mem_limit,omitempty"` 46 MemSwapLimit yaml.StringorInt `yaml:"memswap_limit,omitempty"` 47 Name string `yaml:"name,omitempty"` 48 Net string `yaml:"net,omitempty"` 49 Pid string `yaml:"pid,omitempty"` 50 Uts string `yaml:"uts,omitempty"` 51 Ipc string `yaml:"ipc,omitempty"` 52 Ports []string `yaml:"ports,omitempty"` 53 Privileged bool `yaml:"privileged,omitempty"` 54 Restart string `yaml:"restart,omitempty"` 55 ReadOnly bool `yaml:"read_only,omitempty"` 56 ShmSize yaml.StringorInt `yaml:"shm_size,omitempty"` 57 StdinOpen bool `yaml:"stdin_open,omitempty"` 58 SecurityOpt []string `yaml:"security_opt,omitempty"` 59 Tty bool `yaml:"tty,omitempty"` 60 User string `yaml:"user,omitempty"` 61 VolumeDriver string `yaml:"volume_driver,omitempty"` 62 Volumes []string `yaml:"volumes,omitempty"` 63 VolumesFrom []string `yaml:"volumes_from,omitempty"` 64 WorkingDir string `yaml:"working_dir,omitempty"` 65 Expose []string `yaml:"expose,omitempty"` 66 ExternalLinks []string `yaml:"external_links,omitempty"` 67 LogOpt map[string]string `yaml:"log_opt,omitempty"` 68 ExtraHosts []string `yaml:"extra_hosts,omitempty"` 69 Ulimits yaml.Ulimits `yaml:"ulimits,omitempty"` 70 } 71 72 // Log holds v2 logging information 73 type Log struct { 74 Driver string `yaml:"driver,omitempty"` 75 Options map[string]string `yaml:"options,omitempty"` 76 } 77 78 // ServiceConfig holds version 2 of libcompose service configuration 79 type ServiceConfig struct { 80 Build yaml.Build `yaml:"build,omitempty"` 81 CapAdd []string `yaml:"cap_add,omitempty"` 82 CapDrop []string `yaml:"cap_drop,omitempty"` 83 CPUSet string `yaml:"cpuset,omitempty"` 84 CPUShares yaml.StringorInt `yaml:"cpu_shares,omitempty"` 85 CPUQuota yaml.StringorInt `yaml:"cpu_quota,omitempty"` 86 Command yaml.Command `yaml:"command,flow,omitempty"` 87 CgroupParent string `yaml:"cgroup_parent,omitempty"` 88 ContainerName string `yaml:"container_name,omitempty"` 89 Devices []string `yaml:"devices,omitempty"` 90 DependsOn []string `yaml:"depends_on,omitempty"` 91 DNS yaml.Stringorslice `yaml:"dns,omitempty"` 92 DNSSearch yaml.Stringorslice `yaml:"dns_search,omitempty"` 93 DomainName string `yaml:"domainname,omitempty"` 94 Entrypoint yaml.Command `yaml:"entrypoint,flow,omitempty"` 95 EnvFile yaml.Stringorslice `yaml:"env_file,omitempty"` 96 Environment yaml.MaporEqualSlice `yaml:"environment,omitempty"` 97 Expose []string `yaml:"expose,omitempty"` 98 Extends yaml.MaporEqualSlice `yaml:"extends,omitempty"` 99 ExternalLinks []string `yaml:"external_links,omitempty"` 100 ExtraHosts []string `yaml:"extra_hosts,omitempty"` 101 Image string `yaml:"image,omitempty"` 102 Hostname string `yaml:"hostname,omitempty"` 103 Ipc string `yaml:"ipc,omitempty"` 104 Labels yaml.SliceorMap `yaml:"labels,omitempty"` 105 Links yaml.MaporColonSlice `yaml:"links,omitempty"` 106 Logging Log `yaml:"logging,omitempty"` 107 MacAddress string `yaml:"mac_address,omitempty"` 108 MemLimit yaml.StringorInt `yaml:"mem_limit,omitempty"` 109 MemSwapLimit yaml.StringorInt `yaml:"memswap_limit,omitempty"` 110 NetworkMode string `yaml:"network_mode,omitempty"` 111 Networks *yaml.Networks `yaml:"networks,omitempty"` 112 Pid string `yaml:"pid,omitempty"` 113 Ports []string `yaml:"ports,omitempty"` 114 Privileged bool `yaml:"privileged,omitempty"` 115 SecurityOpt []string `yaml:"security_opt,omitempty"` 116 ShmSize yaml.StringorInt `yaml:"shm_size,omitempty"` 117 StopSignal string `yaml:"stop_signal,omitempty"` 118 VolumeDriver string `yaml:"volume_driver,omitempty"` 119 Volumes *yaml.Volumes `yaml:"volumes,omitempty"` 120 VolumesFrom []string `yaml:"volumes_from,omitempty"` 121 Uts string `yaml:"uts,omitempty"` 122 Restart string `yaml:"restart,omitempty"` 123 ReadOnly bool `yaml:"read_only,omitempty"` 124 StdinOpen bool `yaml:"stdin_open,omitempty"` 125 Tty bool `yaml:"tty,omitempty"` 126 User string `yaml:"user,omitempty"` 127 WorkingDir string `yaml:"working_dir,omitempty"` 128 Ulimits yaml.Ulimits `yaml:"ulimits,omitempty"` 129 } 130 131 // VolumeConfig holds v2 volume configuration 132 type VolumeConfig struct { 133 Driver string `yaml:"driver,omitempty"` 134 DriverOpts map[string]string `yaml:"driver_opts,omitempty"` 135 External yaml.External `yaml:"external,omitempty"` 136 } 137 138 // Ipam holds v2 network IPAM information 139 type Ipam struct { 140 Driver string `yaml:"driver,omitempty"` 141 Config []IpamConfig `yaml:"config,omitempty"` 142 } 143 144 // IpamConfig holds v2 network IPAM configuration information 145 type IpamConfig struct { 146 Subnet string `yaml:"subnet,omitempty"` 147 IPRange string `yaml:"ip_range,omitempty"` 148 Gateway string `yaml:"gateway,omitempty"` 149 AuxAddress map[string]string `yaml:"aux_addresses,omitempty"` 150 } 151 152 // NetworkConfig holds v2 network configuration 153 type NetworkConfig struct { 154 Driver string `yaml:"driver,omitempty"` 155 DriverOpts map[string]string `yaml:"driver_opts,omitempty"` 156 External yaml.External `yaml:"external,omitempty"` 157 Ipam Ipam `yaml:"ipam,omitempty"` 158 } 159 160 // Config holds libcompose top level configuration 161 type Config struct { 162 Version string `yaml:"version,omitempty"` 163 Services RawServiceMap `yaml:"services,omitempty"` 164 Volumes map[string]*VolumeConfig `yaml:"volumes,omitempty"` 165 Networks map[string]*NetworkConfig `yaml:"networks,omitempty"` 166 } 167 168 // NewServiceConfigs initializes a new Configs struct 169 func NewServiceConfigs() *ServiceConfigs { 170 return &ServiceConfigs{ 171 m: make(map[string]*ServiceConfig), 172 } 173 } 174 175 // ServiceConfigs holds a concurrent safe map of ServiceConfig 176 type ServiceConfigs struct { 177 m map[string]*ServiceConfig 178 mu sync.RWMutex 179 } 180 181 // Has checks if the config map has the specified name 182 func (c *ServiceConfigs) Has(name string) bool { 183 c.mu.RLock() 184 defer c.mu.RUnlock() 185 _, ok := c.m[name] 186 return ok 187 } 188 189 // Get returns the config and the presence of the specified name 190 func (c *ServiceConfigs) Get(name string) (*ServiceConfig, bool) { 191 c.mu.RLock() 192 defer c.mu.RUnlock() 193 service, ok := c.m[name] 194 return service, ok 195 } 196 197 // Add add the specifed config with the specified name 198 func (c *ServiceConfigs) Add(name string, service *ServiceConfig) { 199 c.mu.Lock() 200 c.m[name] = service 201 c.mu.Unlock() 202 } 203 204 // Remove removes the config with the specified name 205 func (c *ServiceConfigs) Remove(name string) { 206 c.mu.Lock() 207 delete(c.m, name) 208 c.mu.Unlock() 209 } 210 211 // Len returns the len of the configs 212 func (c *ServiceConfigs) Len() int { 213 c.mu.RLock() 214 defer c.mu.RUnlock() 215 return len(c.m) 216 } 217 218 // Keys returns the names of the config 219 func (c *ServiceConfigs) Keys() []string { 220 keys := []string{} 221 c.mu.RLock() 222 defer c.mu.RUnlock() 223 for name := range c.m { 224 keys = append(keys, name) 225 } 226 return keys 227 } 228 229 // All returns all the config at once 230 func (c *ServiceConfigs) All() map[string]*ServiceConfig { 231 c.mu.RLock() 232 defer c.mu.RUnlock() 233 return c.m 234 } 235 236 // RawService is represent a Service in map form unparsed 237 type RawService map[string]interface{} 238 239 // RawServiceMap is a collection of RawServices 240 type RawServiceMap map[string]RawService 241 242 // ParseOptions are a set of options to customize the parsing process 243 type ParseOptions struct { 244 Interpolate bool 245 Validate bool 246 Preprocess func(RawServiceMap) (RawServiceMap, error) 247 Postprocess func(map[string]*ServiceConfig) (map[string]*ServiceConfig, error) 248 }