types.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. package config
  2. import (
  3. "fmt"
  4. "runtime"
  5. "github.com/coreos/coreos-cloudinit/config"
  6. "github.com/docker/engine-api/types"
  7. composeConfig "github.com/docker/libcompose/config"
  8. "github.com/rancher/os/config/yaml"
  9. )
  10. const (
  11. OEM = "/usr/share/ros/oem"
  12. DockerBin = "/usr/bin/docker"
  13. DockerDistBin = "/usr/bin/docker.dist"
  14. RosBin = "/usr/bin/ros"
  15. SysInitBin = "/usr/bin/ros-sysinit"
  16. SystemDockerHome = "/var/lib/system-docker"
  17. SystemDockerHost = "unix:///var/run/system-docker.sock"
  18. DockerHost = "unix:///var/run/docker.sock"
  19. ImagesPath = "/usr/share/ros"
  20. ImagesPattern = "images*.tar"
  21. ModulesArchive = "/modules.tar"
  22. Debug = false
  23. SystemDockerLog = "/var/log/system-docker.log"
  24. SystemDockerBin = "/usr/bin/system-docker"
  25. HashLabel = "io.rancher.os.hash"
  26. IDLabel = "io.rancher.os.id"
  27. DetachLabel = "io.rancher.os.detach"
  28. CreateOnlyLabel = "io.rancher.os.createonly"
  29. ReloadConfigLabel = "io.rancher.os.reloadconfig"
  30. ConsoleLabel = "io.rancher.os.console"
  31. ScopeLabel = "io.rancher.os.scope"
  32. RebuildLabel = "io.docker.compose.rebuild"
  33. System = "system"
  34. OsConfigFile = "/usr/share/ros/os-config.yml"
  35. CloudConfigDir = "/var/lib/rancher/conf/cloud-config.d"
  36. CloudConfigBootFile = "/var/lib/rancher/conf/cloud-config.d/boot.yml"
  37. CloudConfigNetworkFile = "/var/lib/rancher/conf/cloud-config.d/network.yml"
  38. CloudConfigScriptFile = "/var/lib/rancher/conf/cloud-config-script"
  39. MetaDataFile = "/var/lib/rancher/conf/metadata"
  40. CloudConfigFile = "/var/lib/rancher/conf/cloud-config.yml"
  41. )
  42. var (
  43. OemConfigFile = OEM + "/oem-config.yml"
  44. Version string
  45. Arch string
  46. Suffix string
  47. OsRepo string
  48. OsBase string
  49. PrivateKeys = []string{
  50. "rancher.ssh",
  51. "rancher.docker.ca_key",
  52. "rancher.docker.ca_cert",
  53. "rancher.docker.server_key",
  54. "rancher.docker.server_cert",
  55. }
  56. )
  57. func init() {
  58. if Version == "" {
  59. Version = "v0.0.0-dev"
  60. }
  61. if Arch == "" {
  62. Arch = runtime.GOARCH
  63. }
  64. if Suffix == "" && Arch != "amd64" {
  65. Suffix = "_" + Arch
  66. }
  67. if OsBase == "" {
  68. OsBase = fmt.Sprintf("%s/os-base:%s%s", OsRepo, Version, Suffix)
  69. }
  70. }
  71. type Repository struct {
  72. URL string `yaml:"url,omitempty"`
  73. }
  74. type Repositories map[string]Repository
  75. type CloudConfig struct {
  76. SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
  77. WriteFiles []File `yaml:"write_files"`
  78. Hostname string `yaml:"hostname"`
  79. Mounts [][]string `yaml:"mounts,omitempty"`
  80. Rancher RancherConfig `yaml:"rancher,omitempty"`
  81. Runcmd []yaml.StringandSlice `yaml:"runcmd,omitempty"`
  82. Bootcmd []yaml.StringandSlice `yaml:"bootcmd,omitempty"`
  83. }
  84. type File struct {
  85. config.File
  86. Container string `yaml:"container,omitempty"`
  87. }
  88. type RancherConfig struct {
  89. Console string `yaml:"console,omitempty"`
  90. Environment map[string]string `yaml:"environment,omitempty"`
  91. Services map[string]*composeConfig.ServiceConfigV1 `yaml:"services,omitempty"`
  92. BootstrapContainers map[string]*composeConfig.ServiceConfigV1 `yaml:"bootstrap,omitempty"`
  93. CloudInitServices map[string]*composeConfig.ServiceConfigV1 `yaml:"cloud_init_services,omitempty"`
  94. BootstrapDocker DockerConfig `yaml:"bootstrap_docker,omitempty"`
  95. CloudInit CloudInit `yaml:"cloud_init,omitempty"`
  96. Debug bool `yaml:"debug,omitempty"`
  97. RmUsr bool `yaml:"rm_usr,omitempty"`
  98. NoSharedRoot bool `yaml:"no_sharedroot,omitempty"`
  99. Log bool `yaml:"log,omitempty"`
  100. ForceConsoleRebuild bool `yaml:"force_console_rebuild,omitempty"`
  101. Disable []string `yaml:"disable,omitempty"`
  102. ServicesInclude map[string]bool `yaml:"services_include,omitempty"`
  103. Modules []string `yaml:"modules,omitempty"`
  104. Network NetworkConfig `yaml:"network,omitempty"`
  105. DefaultNetwork NetworkConfig `yaml:"default_network,omitempty"`
  106. Repositories Repositories `yaml:"repositories,omitempty"`
  107. SSH SSHConfig `yaml:"ssh,omitempty"`
  108. State StateConfig `yaml:"state,omitempty"`
  109. SystemDocker DockerConfig `yaml:"system_docker,omitempty"`
  110. Upgrade UpgradeConfig `yaml:"upgrade,omitempty"`
  111. Docker DockerConfig `yaml:"docker,omitempty"`
  112. RegistryAuths map[string]types.AuthConfig `yaml:"registry_auths,omitempty"`
  113. Defaults Defaults `yaml:"defaults,omitempty"`
  114. ResizeDevice string `yaml:"resize_device,omitempty"`
  115. Sysctl map[string]string `yaml:"sysctl,omitempty"`
  116. RestartServices []string `yaml:"restart_services,omitempty"`
  117. }
  118. type UpgradeConfig struct {
  119. URL string `yaml:"url,omitempty"`
  120. Image string `yaml:"image,omitempty"`
  121. Rollback string `yaml:"rollback,omitempty"`
  122. }
  123. type EngineOpts struct {
  124. Bridge string `yaml:"bridge,omitempty" opt:"bridge"`
  125. ConfigFile string `yaml:"config_file,omitempty" opt:"config-file"`
  126. Containerd string `yaml:"containerd,omitempty" opt:"containerd"`
  127. Debug *bool `yaml:"debug,omitempty" opt:"debug"`
  128. ExecRoot string `yaml:"exec_root,omitempty" opt:"exec-root"`
  129. Group string `yaml:"group,omitempty" opt:"group"`
  130. Graph string `yaml:"graph,omitempty" opt:"graph"`
  131. Host []string `yaml:"host,omitempty" opt:"host"`
  132. InsecureRegistry []string `yaml:"insecure_registry" opt:"insecure-registry"`
  133. LiveRestore *bool `yaml:"live_restore,omitempty" opt:"live-restore"`
  134. LogDriver string `yaml:"log_driver,omitempty" opt:"log-driver"`
  135. LogOpts map[string]string `yaml:"log_opts,omitempty" opt:"log-opt"`
  136. PidFile string `yaml:"pid_file,omitempty" opt:"pidfile"`
  137. RegistryMirror string `yaml:"registry_mirror,omitempty" opt:"registry-mirror"`
  138. Restart *bool `yaml:"restart,omitempty" opt:"restart"`
  139. SelinuxEnabled *bool `yaml:"selinux_enabled,omitempty" opt:"selinux-enabled"`
  140. StorageDriver string `yaml:"storage_driver,omitempty" opt:"storage-driver"`
  141. UserlandProxy *bool `yaml:"userland_proxy,omitempty" opt:"userland-proxy"`
  142. }
  143. type DockerConfig struct {
  144. EngineOpts
  145. Engine string `yaml:"engine,omitempty"`
  146. TLS bool `yaml:"tls,omitempty"`
  147. TLSArgs []string `yaml:"tls_args,flow,omitempty"`
  148. ExtraArgs []string `yaml:"extra_args,flow,omitempty"`
  149. ServerCert string `yaml:"server_cert,omitempty"`
  150. ServerKey string `yaml:"server_key,omitempty"`
  151. CACert string `yaml:"ca_cert,omitempty"`
  152. CAKey string `yaml:"ca_key,omitempty"`
  153. Environment []string `yaml:"environment,omitempty"`
  154. StorageContext string `yaml:"storage_context,omitempty"`
  155. Exec bool `yaml:"exec,omitempty"`
  156. }
  157. type NetworkConfig struct {
  158. PreCmds []string `yaml:"pre_cmds,omitempty"`
  159. DNS DNSConfig `yaml:"dns,omitempty"`
  160. Interfaces map[string]InterfaceConfig `yaml:"interfaces,omitempty"`
  161. PostCmds []string `yaml:"post_cmds,omitempty"`
  162. HTTPProxy string `yaml:"http_proxy,omitempty"`
  163. HTTPSProxy string `yaml:"https_proxy,omitempty"`
  164. NoProxy string `yaml:"no_proxy,omitempty"`
  165. }
  166. type InterfaceConfig struct {
  167. Match string `yaml:"match,omitempty"`
  168. DHCP bool `yaml:"dhcp,omitempty"`
  169. DHCPArgs string `yaml:"dhcp_args,omitempty"`
  170. Address string `yaml:"address,omitempty"`
  171. Addresses []string `yaml:"addresses,omitempty"`
  172. IPV4LL bool `yaml:"ipv4ll,omitempty"`
  173. Gateway string `yaml:"gateway,omitempty"`
  174. GatewayIpv6 string `yaml:"gateway_ipv6,omitempty"`
  175. MTU int `yaml:"mtu,omitempty"`
  176. Bridge string `yaml:"bridge,omitempty"`
  177. Bond string `yaml:"bond,omitempty"`
  178. BondOpts map[string]string `yaml:"bond_opts,omitempty"`
  179. PostUp []string `yaml:"post_up,omitempty"`
  180. PreUp []string `yaml:"pre_up,omitempty"`
  181. Vlans string `yaml:"vlans,omitempty"`
  182. }
  183. type DNSConfig struct {
  184. Nameservers []string `yaml:"nameservers,flow,omitempty"`
  185. Search []string `yaml:"search,flow,omitempty"`
  186. }
  187. type SSHConfig struct {
  188. Keys map[string]string `yaml:"keys,omitempty"`
  189. }
  190. type StateConfig struct {
  191. Directory string `yaml:"directory,omitempty"`
  192. FsType string `yaml:"fstype,omitempty"`
  193. Dev string `yaml:"dev,omitempty"`
  194. Wait bool `yaml:"wait,omitempty"`
  195. Required bool `yaml:"required,omitempty"`
  196. Autoformat []string `yaml:"autoformat,omitempty"`
  197. MdadmScan bool `yaml:"mdadm_scan,omitempty"`
  198. Script string `yaml:"script,omitempty"`
  199. OemFsType string `yaml:"oem_fstype,omitempty"`
  200. OemDev string `yaml:"oem_dev,omitempty"`
  201. }
  202. type CloudInit struct {
  203. Datasources []string `yaml:"datasources,omitempty"`
  204. }
  205. type Defaults struct {
  206. Hostname string `yaml:"hostname,omitempty"`
  207. Docker DockerConfig `yaml:"docker,omitempty"`
  208. Network NetworkConfig `yaml:"network,omitempty"`
  209. }
  210. func (r Repositories) ToArray() []string {
  211. result := make([]string, 0, len(r))
  212. for _, repo := range r {
  213. if repo.URL != "" {
  214. result = append(result, repo.URL)
  215. }
  216. }
  217. return result
  218. }