types.go 8.9 KB

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