types.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. package config
  2. import (
  3. "fmt"
  4. "runtime"
  5. "github.com/rancher/os/config/cloudinit/config"
  6. "github.com/rancher/os/config/yaml"
  7. "github.com/rancher/os/pkg/netconf"
  8. "github.com/docker/engine-api/types"
  9. composeConfig "github.com/docker/libcompose/config"
  10. )
  11. const (
  12. OemDir = "/usr/share/ros/oem"
  13. BootDir = "/boot"
  14. StateDir = "/state"
  15. RosBin = "/usr/bin/ros"
  16. SysInitBin = "/usr/bin/ros-sysinit"
  17. SystemDockerHost = "unix:///var/run/system-docker.sock"
  18. DockerHost = "unix:///var/run/docker.sock"
  19. ImagesPath = "/usr/share/ros"
  20. InitImages = "images-init.tar"
  21. SystemImages = "images-system.tar"
  22. Debug = false
  23. SystemDockerBin = "/usr/bin/system-dockerd"
  24. DefaultDind = "rancher/os-dind:17.12.1"
  25. DetachLabel = "io.rancher.os.detach"
  26. CreateOnlyLabel = "io.rancher.os.createonly"
  27. ReloadConfigLabel = "io.rancher.os.reloadconfig"
  28. ConsoleLabel = "io.rancher.os.console"
  29. ScopeLabel = "io.rancher.os.scope"
  30. RebuildLabel = "io.docker.compose.rebuild"
  31. UserDockerLabel = "io.rancher.user_docker.name"
  32. UserDockerNetLabel = "io.rancher.user_docker.net"
  33. UserDockerFIPLabel = "io.rancher.user_docker.fix_ip"
  34. System = "system"
  35. OsConfigFile = "/usr/share/ros/os-config.yml"
  36. VarRancherDir = "/var/lib/rancher"
  37. CloudConfigDir = "/var/lib/rancher/conf/cloud-config.d"
  38. CloudConfigInitFile = "/var/lib/rancher/conf/cloud-config.d/init.yml"
  39. CloudConfigBootFile = "/var/lib/rancher/conf/cloud-config.d/boot.yml"
  40. CloudConfigNetworkFile = "/var/lib/rancher/conf/cloud-config.d/network.yml"
  41. CloudConfigScriptFile = "/var/lib/rancher/conf/cloud-config-script"
  42. MetaDataFile = "/var/lib/rancher/conf/metadata"
  43. CloudConfigFile = "/var/lib/rancher/conf/cloud-config.yml"
  44. EtcResolvConfFile = "/etc/resolv.conf"
  45. WPAConfigFile = "/etc/wpa_supplicant-%s.conf"
  46. WPATemplateFile = "/etc/wpa_supplicant.conf.tpl"
  47. DHCPCDConfigFile = "/etc/dhcpcd.conf"
  48. DHCPCDTemplateFile = "/etc/dhcpcd.conf.tpl"
  49. MultiDockerConfFile = "/var/lib/rancher/conf.d/m-user-docker.yml"
  50. MultiDockerDataDir = "/var/lib/m-user-docker"
  51. UdevRulesDir = "/etc/udev/rules.d"
  52. UdevRulesExtrasDir = "/lib/udev/rules-extras.d"
  53. )
  54. var (
  55. OemConfigFile = OemDir + "/oem-config.yml"
  56. Version string
  57. BuildDate string
  58. Arch string
  59. Suffix string
  60. OsRepo string
  61. OsBase string
  62. PrivateKeys = []string{
  63. "rancher.ssh",
  64. "rancher.docker.ca_key",
  65. "rancher.docker.ca_cert",
  66. "rancher.docker.server_key",
  67. "rancher.docker.server_cert",
  68. }
  69. Additional = []string{
  70. "rancher.password",
  71. "rancher.autologin",
  72. "EXTRA_CMDLINE",
  73. }
  74. SupportedDinds = []string{
  75. "rancher/os-dind:17.12.1",
  76. "rancher/os-dind:18.03.1",
  77. }
  78. )
  79. func init() {
  80. if Version == "" {
  81. Version = "v0.0.0-dev"
  82. }
  83. if Arch == "" {
  84. Arch = runtime.GOARCH
  85. }
  86. if Suffix == "" && Arch != "amd64" {
  87. Suffix = "_" + Arch
  88. }
  89. if OsBase == "" {
  90. OsBase = fmt.Sprintf("%s/os-base:%s%s", OsRepo, Version, Suffix)
  91. }
  92. }
  93. type Repository struct {
  94. URL string `yaml:"url,omitempty"`
  95. }
  96. type Repositories map[string]Repository
  97. type CloudConfig struct {
  98. SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"`
  99. WriteFiles []File `yaml:"write_files,omitempty"`
  100. Hostname string `yaml:"hostname,omitempty"`
  101. Mounts [][]string `yaml:"mounts,omitempty"`
  102. Rancher RancherConfig `yaml:"rancher,omitempty"`
  103. Runcmd []yaml.StringandSlice `yaml:"runcmd,omitempty"`
  104. Bootcmd []yaml.StringandSlice `yaml:"bootcmd,omitempty"`
  105. }
  106. type File struct {
  107. config.File
  108. Container string `yaml:"container,omitempty"`
  109. }
  110. type RancherConfig struct {
  111. Console string `yaml:"console,omitempty"`
  112. Environment map[string]string `yaml:"environment,omitempty"`
  113. Services map[string]*composeConfig.ServiceConfigV1 `yaml:"services,omitempty"`
  114. BootstrapContainers map[string]*composeConfig.ServiceConfigV1 `yaml:"bootstrap,omitempty"`
  115. CloudInitServices map[string]*composeConfig.ServiceConfigV1 `yaml:"cloud_init_services,omitempty"`
  116. BootstrapDocker DockerConfig `yaml:"bootstrap_docker,omitempty"`
  117. CloudInit CloudInit `yaml:"cloud_init,omitempty"`
  118. Debug bool `yaml:"debug,omitempty"`
  119. RmUsr bool `yaml:"rm_usr,omitempty"`
  120. NoSharedRoot bool `yaml:"no_sharedroot,omitempty"`
  121. Log bool `yaml:"log,omitempty"`
  122. ForceConsoleRebuild bool `yaml:"force_console_rebuild,omitempty"`
  123. Recovery bool `yaml:"recovery,omitempty"`
  124. Disable []string `yaml:"disable,omitempty"`
  125. ServicesInclude map[string]bool `yaml:"services_include,omitempty"`
  126. Modules []string `yaml:"modules,omitempty"`
  127. Network netconf.NetworkConfig `yaml:"network,omitempty"`
  128. Repositories Repositories `yaml:"repositories,omitempty"`
  129. SSH SSHConfig `yaml:"ssh,omitempty"`
  130. State StateConfig `yaml:"state,omitempty"`
  131. SystemDocker DockerConfig `yaml:"system_docker,omitempty"`
  132. Upgrade UpgradeConfig `yaml:"upgrade,omitempty"`
  133. Docker DockerConfig `yaml:"docker,omitempty"`
  134. RegistryAuths map[string]types.AuthConfig `yaml:"registry_auths,omitempty"`
  135. Defaults Defaults `yaml:"defaults,omitempty"`
  136. ResizeDevice string `yaml:"resize_device,omitempty"`
  137. Sysctl map[string]string `yaml:"sysctl,omitempty"`
  138. RestartServices []string `yaml:"restart_services,omitempty"`
  139. HypervisorService bool `yaml:"hypervisor_service,omitempty"`
  140. ShutdownTimeout int `yaml:"shutdown_timeout,omitempty"`
  141. PreloadWait bool `yaml:"preload_wait,omitempty"`
  142. }
  143. type UpgradeConfig struct {
  144. URL string `yaml:"url,omitempty"`
  145. Image string `yaml:"image,omitempty"`
  146. Rollback string `yaml:"rollback,omitempty"`
  147. Policy string `yaml:"policy,omitempty"`
  148. }
  149. type EngineOpts struct {
  150. Bridge string `yaml:"bridge,omitempty" opt:"bridge"`
  151. BIP string `yaml:"bip,omitempty" opt:"bip"`
  152. ConfigFile string `yaml:"config_file,omitempty" opt:"config-file"`
  153. Containerd string `yaml:"containerd,omitempty" opt:"containerd"`
  154. Debug *bool `yaml:"debug,omitempty" opt:"debug"`
  155. ExecRoot string `yaml:"exec_root,omitempty" opt:"exec-root"`
  156. Group string `yaml:"group,omitempty" opt:"group"`
  157. Graph string `yaml:"graph,omitempty" opt:"graph"`
  158. Host []string `yaml:"host,omitempty" opt:"host"`
  159. InsecureRegistry []string `yaml:"insecure_registry" opt:"insecure-registry"`
  160. LiveRestore *bool `yaml:"live_restore,omitempty" opt:"live-restore"`
  161. LogDriver string `yaml:"log_driver,omitempty" opt:"log-driver"`
  162. LogOpts map[string]string `yaml:"log_opts,omitempty" opt:"log-opt"`
  163. PidFile string `yaml:"pid_file,omitempty" opt:"pidfile"`
  164. RegistryMirror string `yaml:"registry_mirror,omitempty" opt:"registry-mirror"`
  165. Restart *bool `yaml:"restart,omitempty" opt:"restart"`
  166. SelinuxEnabled *bool `yaml:"selinux_enabled,omitempty" opt:"selinux-enabled"`
  167. StorageDriver string `yaml:"storage_driver,omitempty" opt:"storage-driver"`
  168. UserlandProxy *bool `yaml:"userland_proxy,omitempty" opt:"userland-proxy"`
  169. }
  170. type DockerConfig struct {
  171. EngineOpts
  172. Engine string `yaml:"engine,omitempty"`
  173. TLS bool `yaml:"tls,omitempty"`
  174. TLSArgs []string `yaml:"tls_args,flow,omitempty"`
  175. ExtraArgs []string `yaml:"extra_args,flow,omitempty"`
  176. ServerCert string `yaml:"server_cert,omitempty"`
  177. ServerKey string `yaml:"server_key,omitempty"`
  178. CACert string `yaml:"ca_cert,omitempty"`
  179. CAKey string `yaml:"ca_key,omitempty"`
  180. Environment []string `yaml:"environment,omitempty"`
  181. StorageContext string `yaml:"storage_context,omitempty"`
  182. Exec bool `yaml:"exec,omitempty"`
  183. }
  184. type SSHConfig struct {
  185. Keys map[string]string `yaml:"keys,omitempty"`
  186. Daemon bool `yaml:"daemon,omitempty"`
  187. Port int `yaml:"port,omitempty"`
  188. ListenAddress string `yaml:"listen_address,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. LvmScan bool `yaml:"lvm_scan,omitempty"`
  199. Cryptsetup bool `yaml:"cryptsetup,omitempty"`
  200. Rngd bool `yaml:"rngd,omitempty"`
  201. Script string `yaml:"script,omitempty"`
  202. OemFsType string `yaml:"oem_fstype,omitempty"`
  203. OemDev string `yaml:"oem_dev,omitempty"`
  204. BootFsType string `yaml:"boot_fstype,omitempty"`
  205. BootDev string `yaml:"boot_dev,omitempty"`
  206. }
  207. type CloudInit struct {
  208. Datasources []string `yaml:"datasources,omitempty"`
  209. }
  210. type Defaults struct {
  211. Hostname string `yaml:"hostname,omitempty"`
  212. Docker DockerConfig `yaml:"docker,omitempty"`
  213. Network netconf.NetworkConfig `yaml:"network,omitempty"`
  214. SystemDockerLogs string `yaml:"system_docker_logs,omitempty"`
  215. }
  216. func (r Repositories) ToArray() []string {
  217. result := make([]string, 0, len(r))
  218. for _, repo := range r {
  219. if repo.URL != "" {
  220. result = append(result, repo.URL)
  221. }
  222. }
  223. return result
  224. }