types.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. SystemDockerLog = "/var/log/system-docker.log"
  25. SystemDockerBin = "/usr/bin/system-dockerd"
  26. HashLabel = "io.rancher.os.hash"
  27. IDLabel = "io.rancher.os.id"
  28. DetachLabel = "io.rancher.os.detach"
  29. CreateOnlyLabel = "io.rancher.os.createonly"
  30. ReloadConfigLabel = "io.rancher.os.reloadconfig"
  31. ConsoleLabel = "io.rancher.os.console"
  32. ScopeLabel = "io.rancher.os.scope"
  33. RebuildLabel = "io.docker.compose.rebuild"
  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. CNIBridgeConfigFile = "/etc/docker/cni/bridge.d/bridge.conf"
  46. RKPDockerSysBridgeSubnet = "rancher.system_docker.subnet"
  47. )
  48. var (
  49. OemConfigFile = OEM + "/oem-config.yml"
  50. Version string
  51. BuildDate string
  52. Arch string
  53. Suffix string
  54. OsRepo string
  55. OsBase string
  56. PrivateKeys = []string{
  57. "rancher.ssh",
  58. "rancher.docker.ca_key",
  59. "rancher.docker.ca_cert",
  60. "rancher.docker.server_key",
  61. "rancher.docker.server_cert",
  62. }
  63. )
  64. func init() {
  65. if Version == "" {
  66. Version = "v0.0.0-dev"
  67. }
  68. if Arch == "" {
  69. Arch = runtime.GOARCH
  70. }
  71. if Suffix == "" && Arch != "amd64" {
  72. Suffix = "_" + Arch
  73. }
  74. if OsBase == "" {
  75. OsBase = fmt.Sprintf("%s/os-base:%s%s", OsRepo, Version, Suffix)
  76. }
  77. }
  78. type Repository struct {
  79. URL string `yaml:"url,omitempty"`
  80. }
  81. type Repositories map[string]Repository
  82. type CloudConfig struct {
  83. SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"`
  84. WriteFiles []File `yaml:"write_files,omitempty"`
  85. Hostname string `yaml:"hostname,omitempty"`
  86. Mounts [][]string `yaml:"mounts,omitempty"`
  87. Rancher RancherConfig `yaml:"rancher,omitempty"`
  88. Runcmd []yaml.StringandSlice `yaml:"runcmd,omitempty"`
  89. Bootcmd []yaml.StringandSlice `yaml:"bootcmd,omitempty"`
  90. }
  91. type File struct {
  92. config.File
  93. Container string `yaml:"container,omitempty"`
  94. }
  95. type RancherConfig struct {
  96. Console string `yaml:"console,omitempty"`
  97. Environment map[string]string `yaml:"environment,omitempty"`
  98. Services map[string]*composeConfig.ServiceConfigV1 `yaml:"services,omitempty"`
  99. BootstrapContainers map[string]*composeConfig.ServiceConfigV1 `yaml:"bootstrap,omitempty"`
  100. CloudInitServices map[string]*composeConfig.ServiceConfigV1 `yaml:"cloud_init_services,omitempty"`
  101. BootstrapDocker DockerConfig `yaml:"bootstrap_docker,omitempty"`
  102. CloudInit CloudInit `yaml:"cloud_init,omitempty"`
  103. Debug bool `yaml:"debug,omitempty"`
  104. RmUsr bool `yaml:"rm_usr,omitempty"`
  105. NoSharedRoot bool `yaml:"no_sharedroot,omitempty"`
  106. Log bool `yaml:"log,omitempty"`
  107. ForceConsoleRebuild bool `yaml:"force_console_rebuild,omitempty"`
  108. Recovery bool `yaml:"recovery,omitempty"`
  109. Disable []string `yaml:"disable,omitempty"`
  110. ServicesInclude map[string]bool `yaml:"services_include,omitempty"`
  111. Modules []string `yaml:"modules,omitempty"`
  112. Network netconf.NetworkConfig `yaml:"network,omitempty"`
  113. DefaultNetwork netconf.NetworkConfig `yaml:"default_network,omitempty"`
  114. Repositories Repositories `yaml:"repositories,omitempty"`
  115. SSH SSHConfig `yaml:"ssh,omitempty"`
  116. State StateConfig `yaml:"state,omitempty"`
  117. SystemDocker DockerConfig `yaml:"system_docker,omitempty"`
  118. Upgrade UpgradeConfig `yaml:"upgrade,omitempty"`
  119. Docker DockerConfig `yaml:"docker,omitempty"`
  120. RegistryAuths map[string]types.AuthConfig `yaml:"registry_auths,omitempty"`
  121. Defaults Defaults `yaml:"defaults,omitempty"`
  122. ResizeDevice string `yaml:"resize_device,omitempty"`
  123. Sysctl map[string]string `yaml:"sysctl,omitempty"`
  124. RestartServices []string `yaml:"restart_services,omitempty"`
  125. HypervisorService bool `yaml:"hypervisor_service,omitempty"`
  126. ShutdownTimeout int `yaml:"shutdown_timeout,omitempty"`
  127. }
  128. type UpgradeConfig struct {
  129. URL string `yaml:"url,omitempty"`
  130. Image string `yaml:"image,omitempty"`
  131. Rollback string `yaml:"rollback,omitempty"`
  132. }
  133. type EngineOpts struct {
  134. Bridge string `yaml:"bridge,omitempty" opt:"bridge"`
  135. ConfigFile string `yaml:"config_file,omitempty" opt:"config-file"`
  136. Containerd string `yaml:"containerd,omitempty" opt:"containerd"`
  137. Debug *bool `yaml:"debug,omitempty" opt:"debug"`
  138. ExecRoot string `yaml:"exec_root,omitempty" opt:"exec-root"`
  139. Group string `yaml:"group,omitempty" opt:"group"`
  140. Graph string `yaml:"graph,omitempty" opt:"graph"`
  141. Host []string `yaml:"host,omitempty" opt:"host"`
  142. InsecureRegistry []string `yaml:"insecure_registry" opt:"insecure-registry"`
  143. LiveRestore *bool `yaml:"live_restore,omitempty" opt:"live-restore"`
  144. LogDriver string `yaml:"log_driver,omitempty" opt:"log-driver"`
  145. LogOpts map[string]string `yaml:"log_opts,omitempty" opt:"log-opt"`
  146. PidFile string `yaml:"pid_file,omitempty" opt:"pidfile"`
  147. RegistryMirror string `yaml:"registry_mirror,omitempty" opt:"registry-mirror"`
  148. Restart *bool `yaml:"restart,omitempty" opt:"restart"`
  149. SelinuxEnabled *bool `yaml:"selinux_enabled,omitempty" opt:"selinux-enabled"`
  150. StorageDriver string `yaml:"storage_driver,omitempty" opt:"storage-driver"`
  151. UserlandProxy *bool `yaml:"userland_proxy,omitempty" opt:"userland-proxy"`
  152. }
  153. type DockerConfig struct {
  154. EngineOpts
  155. Engine string `yaml:"engine,omitempty"`
  156. TLS bool `yaml:"tls,omitempty"`
  157. TLSArgs []string `yaml:"tls_args,flow,omitempty"`
  158. ExtraArgs []string `yaml:"extra_args,flow,omitempty"`
  159. ServerCert string `yaml:"server_cert,omitempty"`
  160. ServerKey string `yaml:"server_key,omitempty"`
  161. CACert string `yaml:"ca_cert,omitempty"`
  162. CAKey string `yaml:"ca_key,omitempty"`
  163. Environment []string `yaml:"environment,omitempty"`
  164. StorageContext string `yaml:"storage_context,omitempty"`
  165. Exec bool `yaml:"exec,omitempty"`
  166. }
  167. type SSHConfig struct {
  168. Keys map[string]string `yaml:"keys,omitempty"`
  169. Daemon bool `yaml:"daemon,omitempty"`
  170. Port int `yaml:"port,omitempty"`
  171. ListenAddress string `yaml:"listen_address,omitempty"`
  172. }
  173. type StateConfig struct {
  174. Directory string `yaml:"directory,omitempty"`
  175. FsType string `yaml:"fstype,omitempty"`
  176. Dev string `yaml:"dev,omitempty"`
  177. Wait bool `yaml:"wait,omitempty"`
  178. Required bool `yaml:"required,omitempty"`
  179. Autoformat []string `yaml:"autoformat,omitempty"`
  180. MdadmScan bool `yaml:"mdadm_scan,omitempty"`
  181. Script string `yaml:"script,omitempty"`
  182. OemFsType string `yaml:"oem_fstype,omitempty"`
  183. OemDev string `yaml:"oem_dev,omitempty"`
  184. }
  185. type CloudInit struct {
  186. Datasources []string `yaml:"datasources,omitempty"`
  187. }
  188. type Defaults struct {
  189. Hostname string `yaml:"hostname,omitempty"`
  190. Docker DockerConfig `yaml:"docker,omitempty"`
  191. Network netconf.NetworkConfig `yaml:"network,omitempty"`
  192. }
  193. func (r Repositories) ToArray() []string {
  194. result := make([]string, 0, len(r))
  195. for _, repo := range r {
  196. if repo.URL != "" {
  197. result = append(result, repo.URL)
  198. }
  199. }
  200. return result
  201. }