github.com/ijc/docker-app@v0.6.1-0.20181012090447-c7ca8bc483fb/internal/helm/templatetypes/types.go (about) 1 package templatetypes 2 3 import ( 4 "time" 5 6 "github.com/docker/cli/cli/compose/types" 7 ) 8 9 // BoolOrTemplate stores a boolean or a templated string 10 type BoolOrTemplate struct { 11 Value bool `yaml:",omitempty"` 12 ValueTemplate string `yaml:",omitempty"` 13 } 14 15 // UInt64OrTemplate stores an uint64 or a templated string 16 type UInt64OrTemplate struct { 17 Value *uint64 `yaml:",omitempty"` 18 ValueTemplate string `yaml:",omitempty"` 19 } 20 21 // UnitBytesOrTemplate stores an int64 parsed from a size or a templated string 22 type UnitBytesOrTemplate struct { 23 Value int64 `yaml:",omitempty"` 24 ValueTemplate string `yaml:",omitempty"` 25 } 26 27 // DurationOrTemplate stores a duration or a templated string 28 type DurationOrTemplate struct { 29 Value *time.Duration `yaml:",omitempty"` 30 ValueTemplate string `yaml:",omitempty"` 31 } 32 33 // StringTemplate contains a string that can be a template value 34 type StringTemplate struct { 35 Value string 36 } 37 38 // StringTemplateList is a list of StringTemplate 39 type StringTemplateList []StringTemplate 40 41 // ShellCommandTemplate is a shell command parsed as a list or string 42 type ShellCommandTemplate []StringTemplate 43 44 // HostsListTemplate is a list to hosts parsed as a list or map 45 type HostsListTemplate []StringTemplate 46 47 // LabelsTemplate is a mapping type for labels 48 type LabelsTemplate map[StringTemplate]StringTemplate 49 50 // MappingWithEqualsTemplate is a mapping type parsed as a list or map 51 type MappingWithEqualsTemplate map[StringTemplate]*StringTemplate 52 53 // ProcessTemplate can be overridden to process template values when marshaling 54 var ProcessTemplate = func(s string) (string, error) { 55 return s, nil 56 } 57 58 // UnmarshalYAML implements the Unmarshaler interface 59 func (s *StringTemplate) UnmarshalYAML(unmarshal func(interface{}) error) error { 60 return unmarshal(&s.Value) 61 } 62 63 // MarshalYAML implements the Marshaler interface 64 func (s StringTemplate) MarshalYAML() (interface{}, error) { 65 return ProcessTemplate(s.Value) 66 } 67 68 // MarshalYAML implements the Marshaler interface 69 func (s BoolOrTemplate) MarshalYAML() (interface{}, error) { 70 if s.ValueTemplate != "" { 71 return ProcessTemplate(s.ValueTemplate) 72 } 73 return s.Value, nil 74 } 75 76 // MarshalYAML implements the Marshaler interface 77 func (s UInt64OrTemplate) MarshalYAML() (interface{}, error) { 78 if s.ValueTemplate != "" { 79 return ProcessTemplate(s.ValueTemplate) 80 } 81 return s.Value, nil 82 } 83 84 // MarshalYAML implements the Marshaler interface 85 func (s UnitBytesOrTemplate) MarshalYAML() (interface{}, error) { 86 if s.ValueTemplate != "" { 87 return ProcessTemplate(s.ValueTemplate) 88 } 89 return s.Value, nil 90 } 91 92 // MarshalYAML implements the Marshaler interface 93 func (s DurationOrTemplate) MarshalYAML() (interface{}, error) { 94 if s.ValueTemplate != "" { 95 return ProcessTemplate(s.ValueTemplate) 96 } 97 return s.Value, nil 98 } 99 100 // Config is a full compose file configuration 101 type Config struct { 102 Filename string `yaml:"-"` 103 Version string 104 Services Services 105 Networks map[string]types.NetworkConfig `yaml:",omitempty"` 106 Volumes map[string]types.VolumeConfig `yaml:",omitempty"` 107 Secrets map[string]types.SecretConfig `yaml:",omitempty"` 108 Configs map[string]types.ConfigObjConfig `yaml:",omitempty"` 109 } 110 111 // Services is a list of ServiceConfig 112 type Services []ServiceConfig 113 114 // MarshalYAML makes Services implement yaml.Marshaller 115 func (s Services) MarshalYAML() (interface{}, error) { 116 services := map[string]ServiceConfig{} 117 for _, service := range s { 118 services[service.Name] = service 119 } 120 return services, nil 121 } 122 123 // ServiceConfig is the configuration of one service 124 type ServiceConfig struct { 125 Name string `yaml:"-"` 126 127 Build types.BuildConfig `yaml:",omitempty"` 128 CapAdd []StringTemplate `mapstructure:"cap_add" yaml:"cap_add,omitempty"` 129 CapDrop []StringTemplate `mapstructure:"cap_drop" yaml:"cap_drop,omitempty"` 130 CgroupParent StringTemplate `mapstructure:"cgroup_parent" yaml:"cgroup_parent,omitempty"` 131 Command ShellCommandTemplate `yaml:",omitempty"` 132 Configs []ServiceConfigObjConfig `yaml:",omitempty"` 133 ContainerName StringTemplate `mapstructure:"container_name" yaml:"container_name,omitempty"` 134 CredentialSpec types.CredentialSpecConfig `mapstructure:"credential_spec" yaml:"credential_spec,omitempty"` 135 DependsOn []StringTemplate `mapstructure:"depends_on" yaml:"depends_on,omitempty"` 136 Deploy DeployConfig `yaml:",omitempty"` 137 Devices []StringTemplate `yaml:",omitempty"` 138 DNS StringTemplateList `yaml:",omitempty"` 139 DNSSearch StringTemplateList `mapstructure:"dns_search" yaml:"dns_search,omitempty"` 140 DomainName StringTemplate `mapstructure:"domainname" yaml:"domainname,omitempty"` 141 Entrypoint ShellCommandTemplate `yaml:",omitempty"` 142 Environment MappingWithEqualsTemplate `yaml:",omitempty"` 143 EnvFile StringTemplateList `mapstructure:"env_file" yaml:"env_file,omitempty"` 144 Expose StringTemplateList `yaml:",omitempty"` 145 ExternalLinks []StringTemplate `mapstructure:"external_links" yaml:"external_links,omitempty"` 146 ExtraHosts HostsListTemplate `mapstructure:"extra_hosts" yaml:"extra_hosts,omitempty"` 147 Hostname StringTemplate `yaml:",omitempty"` 148 HealthCheck *HealthCheckConfig `yaml:",omitempty"` 149 Image StringTemplate `yaml:",omitempty"` 150 Init *BoolOrTemplate `yaml:"init,omitempty"` 151 Ipc StringTemplate `yaml:",omitempty"` 152 Isolation StringTemplate `mapstructure:"isolation" yaml:"isolation,omitempty"` 153 Labels LabelsTemplate `yaml:",omitempty"` 154 Links []StringTemplate `yaml:",omitempty"` 155 Logging *types.LoggingConfig `yaml:",omitempty"` 156 MacAddress StringTemplate `mapstructure:"mac_address" yaml:"mac_address,omitempty"` 157 NetworkMode StringTemplate `mapstructure:"network_mode" yaml:"network_mode,omitempty"` 158 Networks map[string]*types.ServiceNetworkConfig `yaml:",omitempty"` 159 Pid StringTemplate `yaml:",omitempty"` 160 Ports []ServicePortConfig `yaml:",omitempty"` 161 Privileged BoolOrTemplate `yaml:"privileged,omitempty"` 162 ReadOnly BoolOrTemplate `mapstructure:"read_only" yaml:"read_only,omitempty"` 163 Restart StringTemplate `yaml:",omitempty"` 164 Secrets []ServiceSecretConfig `yaml:",omitempty"` 165 SecurityOpt []StringTemplate `mapstructure:"security_opt" yaml:"security_opt,omitempty"` 166 StdinOpen BoolOrTemplate `mapstructure:"stdin_open" yaml:"stdin_open,omitempty"` 167 StopGracePeriod DurationOrTemplate `mapstructure:"stop_grace_period" yaml:"stop_grace_period,omitempty"` 168 StopSignal StringTemplate `mapstructure:"stop_signal" yaml:"stop_signal,omitempty"` 169 Sysctls StringTemplateList `yaml:",omitempty"` 170 Tmpfs StringTemplateList `yaml:",omitempty"` 171 Tty BoolOrTemplate `mapstructure:"tty" yaml:"tty,omitempty"` 172 Ulimits map[string]*types.UlimitsConfig `yaml:",omitempty"` 173 User StringTemplate `yaml:",omitempty"` 174 UserNSMode StringTemplate `mapstructure:"userns_mode" yaml:"userns_mode,omitempty"` 175 Volumes []ServiceVolumeConfig `yaml:",omitempty"` 176 WorkingDir StringTemplate `mapstructure:"working_dir" yaml:"working_dir,omitempty"` 177 178 Extras map[string]interface{} `yaml:",inline"` 179 } 180 181 // DeployConfig the deployment configuration for a service 182 type DeployConfig struct { 183 Mode StringTemplate `yaml:",omitempty"` 184 Replicas UInt64OrTemplate `yaml:"replicas,omitempty"` 185 Labels LabelsTemplate `yaml:",omitempty"` 186 UpdateConfig *UpdateConfig `mapstructure:"update_config" yaml:"update_config,omitempty"` 187 RollbackConfig *UpdateConfig `mapstructure:"rollback_config" yaml:"rollback_config,omitempty"` 188 Resources Resources `yaml:",omitempty"` 189 RestartPolicy *types.RestartPolicy `mapstructure:"restart_policy" yaml:"restart_policy,omitempty"` 190 Placement types.Placement `yaml:",omitempty"` 191 EndpointMode StringTemplate `mapstructure:"endpoint_mode" yaml:"endpoint_mode,omitempty"` 192 } 193 194 // HealthCheckConfig the healthcheck configuration for a service 195 type HealthCheckConfig struct { 196 Test types.HealthCheckTest `yaml:",omitempty"` 197 Timeout DurationOrTemplate `yaml:"timeout,omitempty"` 198 Interval DurationOrTemplate `yaml:"interval,omitempty"` 199 Retries UInt64OrTemplate `yaml:"retries,omitempty"` 200 StartPeriod *time.Duration `mapstructure:"start_period" yaml:"start_period,omitempty"` 201 Disable BoolOrTemplate `yaml:",omitempty"` 202 } 203 204 // UpdateConfig the service update configuration 205 type UpdateConfig struct { 206 Parallelism UInt64OrTemplate `yaml:"parallelism,omitempty"` 207 Delay time.Duration `yaml:",omitempty"` 208 FailureAction StringTemplate `mapstructure:"failure_action" yaml:"failure_action,omitempty"` 209 Monitor time.Duration `yaml:",omitempty"` 210 MaxFailureRatio float32 `mapstructure:"max_failure_ratio" yaml:"max_failure_ratio,omitempty"` 211 Order StringTemplate `yaml:",omitempty"` 212 } 213 214 // Resources the resource limits and reservations 215 type Resources struct { 216 Limits *Resource `yaml:",omitempty"` 217 Reservations *Resource `yaml:",omitempty"` 218 } 219 220 // Resource is a resource to be limited or reserved 221 type Resource struct { 222 // TODO: types to convert from units and ratios 223 NanoCPUs StringTemplate `mapstructure:"cpus" yaml:"cpus,omitempty"` 224 MemoryBytes UnitBytesOrTemplate `mapstructure:"memory" yaml:"memory,omitempty"` 225 GenericResources []types.GenericResource `mapstructure:"generic_resources" yaml:"generic_resources,omitempty"` 226 } 227 228 // ServicePortConfig is the port configuration for a service 229 type ServicePortConfig struct { 230 Mode StringTemplate `yaml:",omitempty"` 231 Target UInt64OrTemplate `yaml:"target,omitempty"` 232 Published UInt64OrTemplate `yaml:"published,omitempty"` 233 Protocol StringTemplate `yaml:",omitempty"` 234 } 235 236 // ServiceVolumeConfig are references to a volume used by a service 237 type ServiceVolumeConfig struct { 238 Type string `yaml:",omitempty"` 239 Source StringTemplate `yaml:",omitempty"` 240 Target StringTemplate `yaml:",omitempty"` 241 ReadOnly BoolOrTemplate `mapstructure:"read_only" yaml:"read_only,omitempty"` 242 Consistency StringTemplate `yaml:",omitempty"` 243 Bind *types.ServiceVolumeBind `yaml:",omitempty"` 244 Volume *types.ServiceVolumeVolume `yaml:",omitempty"` 245 Tmpfs *types.ServiceVolumeTmpfs `yaml:",omitempty"` 246 } 247 248 // FileReferenceConfig for a reference to a swarm file object 249 type FileReferenceConfig struct { 250 Source StringTemplate `yaml:",omitempty"` 251 Target StringTemplate `yaml:",omitempty"` 252 UID StringTemplate `yaml:",omitempty"` 253 GID StringTemplate `yaml:",omitempty"` 254 Mode UInt64OrTemplate `yaml:"mode,omitempty"` 255 } 256 257 // ServiceConfigObjConfig is the config obj configuration for a service 258 type ServiceConfigObjConfig FileReferenceConfig 259 260 // ServiceSecretConfig is the secret configuration for a service 261 type ServiceSecretConfig FileReferenceConfig