types.go 9.3 KB

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