types.go 9.8 KB

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