types.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package config
  2. import (
  3. "fmt"
  4. "runtime"
  5. "github.com/coreos/coreos-cloudinit/config"
  6. "github.com/docker/engine-api/types"
  7. composeConfig "github.com/docker/libcompose/config"
  8. "github.com/rancher/netconf"
  9. )
  10. const (
  11. OEM = "/usr/share/ros/oem"
  12. DOCKER_BIN = "/usr/bin/docker"
  13. DOCKER_DIST_BIN = "/usr/bin/docker.dist"
  14. ROS_BIN = "/usr/bin/ros"
  15. SYSINIT_BIN = "/usr/bin/ros-sysinit"
  16. DOCKER_SYSTEM_HOME = "/var/lib/system-docker"
  17. DOCKER_SYSTEM_HOST = "unix:///var/run/system-docker.sock"
  18. DOCKER_HOST = "unix:///var/run/docker.sock"
  19. IMAGES_PATH = "/usr/share/ros"
  20. IMAGES_PATTERN = "images*.tar"
  21. MODULES_ARCHIVE = "/modules.tar"
  22. DEBUG = false
  23. SYSTEM_DOCKER_LOG = "/var/log/system-docker.log"
  24. SYSTEM_DOCKER_BIN = "/usr/bin/system-docker"
  25. LABEL = "label"
  26. HASH = "io.rancher.os.hash"
  27. ID = "io.rancher.os.id"
  28. DETACH = "io.rancher.os.detach"
  29. CREATE_ONLY = "io.rancher.os.createonly"
  30. RELOAD_CONFIG = "io.rancher.os.reloadconfig"
  31. CONSOLE = "io.rancher.os.console"
  32. SCOPE = "io.rancher.os.scope"
  33. REBUILD = "io.docker.compose.rebuild"
  34. SYSTEM = "system"
  35. OsConfigFile = "/usr/share/ros/os-config.yml"
  36. CloudConfigDir = "/var/lib/rancher/conf/cloud-config.d"
  37. CloudConfigBootFile = "/var/lib/rancher/conf/cloud-config.d/boot.yml"
  38. CloudConfigNetworkFile = "/var/lib/rancher/conf/cloud-config.d/network.yml"
  39. CloudConfigScriptFile = "/var/lib/rancher/conf/cloud-config-script"
  40. MetaDataFile = "/var/lib/rancher/conf/metadata"
  41. CloudConfigFile = "/var/lib/rancher/conf/cloud-config.yml"
  42. )
  43. var (
  44. OemConfigFile = OEM + "/oem-config.yml"
  45. VERSION string
  46. ARCH string
  47. SUFFIX string
  48. OS_REPO string
  49. OS_BASE string
  50. PrivateKeys = []string{
  51. "rancher.ssh",
  52. "rancher.docker.ca_key",
  53. "rancher.docker.ca_cert",
  54. "rancher.docker.server_key",
  55. "rancher.docker.server_cert",
  56. }
  57. )
  58. func init() {
  59. if VERSION == "" {
  60. VERSION = "v0.0.0-dev"
  61. }
  62. if ARCH == "" {
  63. ARCH = runtime.GOARCH
  64. }
  65. if SUFFIX == "" && ARCH != "amd64" {
  66. SUFFIX = "_" + ARCH
  67. }
  68. if OS_BASE == "" {
  69. OS_BASE = fmt.Sprintf("%s/os-base:%s%s", OS_REPO, VERSION, SUFFIX)
  70. }
  71. }
  72. type Repository struct {
  73. Url string `yaml:"url,omitempty"`
  74. }
  75. type Repositories map[string]Repository
  76. type CloudConfig struct {
  77. SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
  78. WriteFiles []File `yaml:"write_files"`
  79. Hostname string `yaml:"hostname"`
  80. Mounts [][]string `yaml:"mounts,omitempty"`
  81. Rancher RancherConfig `yaml:"rancher,omitempty"`
  82. Runcmd [][]string `yaml:"runcmd,omitempty"`
  83. }
  84. type File struct {
  85. config.File
  86. Container string `yaml:"container,omitempty"`
  87. }
  88. type RancherConfig struct {
  89. Console string `yaml:"console,omitempty"`
  90. Environment map[string]string `yaml:"environment,omitempty"`
  91. Services map[string]*composeConfig.ServiceConfigV1 `yaml:"services,omitempty"`
  92. BootstrapContainers map[string]*composeConfig.ServiceConfigV1 `yaml:"bootstrap,omitempty"`
  93. Autoformat map[string]*composeConfig.ServiceConfigV1 `yaml:"autoformat,omitempty"`
  94. BootstrapDocker DockerConfig `yaml:"bootstrap_docker,omitempty"`
  95. CloudInit CloudInit `yaml:"cloud_init,omitempty"`
  96. Debug bool `yaml:"debug,omitempty"`
  97. RmUsr bool `yaml:"rm_usr,omitempty"`
  98. NoSharedRoot bool `yaml:"no_sharedroot,omitempty"`
  99. Log bool `yaml:"log,omitempty"`
  100. ForceConsoleRebuild bool `yaml:"force_console_rebuild,omitempty"`
  101. Disable []string `yaml:"disable,omitempty"`
  102. ServicesInclude map[string]bool `yaml:"services_include,omitempty"`
  103. Modules []string `yaml:"modules,omitempty"`
  104. Network netconf.NetworkConfig `yaml:"network,omitempty"`
  105. DefaultNetwork netconf.NetworkConfig `yaml:"default_network,omitempty"`
  106. Repositories Repositories `yaml:"repositories,omitempty"`
  107. Ssh SshConfig `yaml:"ssh,omitempty"`
  108. State StateConfig `yaml:"state,omitempty"`
  109. SystemDocker DockerConfig `yaml:"system_docker,omitempty"`
  110. Upgrade UpgradeConfig `yaml:"upgrade,omitempty"`
  111. Docker DockerConfig `yaml:"docker,omitempty"`
  112. RegistryAuths map[string]types.AuthConfig `yaml:"registry_auths,omitempty"`
  113. Defaults Defaults `yaml:"defaults,omitempty"`
  114. ResizeDevice string `yaml:"resize_device,omitempty"`
  115. Sysctl map[string]string `yaml:"sysctl,omitempty"`
  116. RestartServices []string `yaml:"restart_services,omitempty"`
  117. }
  118. type UpgradeConfig struct {
  119. Url string `yaml:"url,omitempty"`
  120. Image string `yaml:"image,omitempty"`
  121. Rollback string `yaml:"rollback,omitempty"`
  122. }
  123. type EngineOpts struct {
  124. Bridge string `yaml:"bridge,omitempty" opt:"bridge"`
  125. ConfigFile string `yaml:"config_file,omitempty" opt:"config-file"`
  126. Containerd string `yaml:"containerd,omitempty" opt:"containerd"`
  127. Debug *bool `yaml:"debug,omitempty" opt:"debug"`
  128. ExecRoot string `yaml:"exec_root,omitempty" opt:"exec-root"`
  129. Group string `yaml:"group,omitempty" opt:"group"`
  130. Graph string `yaml:"graph,omitempty" opt:"graph"`
  131. Host string `yaml:"host,omitempty" opt:"host"`
  132. LiveRestore *bool `yaml:"live_restore,omitempty" opt:"live-restore"`
  133. LogDriver string `yaml:"log_driver,omitempty" opt:"log-driver"`
  134. LogOpts map[string]string `yaml:"log_opts,omitempty" opt:"log-opt"`
  135. PidFile string `yaml:"pid_file,omitempty" opt:"pidfile"`
  136. RegistryMirror string `yaml:"registry_mirror,omitempty" opt:"registry-mirror"`
  137. Restart *bool `yaml:"restart,omitempty" opt:"restart"`
  138. SelinuxEnabled *bool `yaml:"selinux_enabled,omitempty" opt:"selinux-enabled"`
  139. StorageDriver string `yaml:"storage_driver,omitempty" opt:"storage-driver"`
  140. UserlandProxy *bool `yaml:"userland_proxy,omitempty" opt:"userland-proxy"`
  141. }
  142. type DockerConfig struct {
  143. EngineOpts
  144. Engine string `yaml:"engine,omitempty"`
  145. TLS bool `yaml:"tls,omitempty"`
  146. TLSArgs []string `yaml:"tls_args,flow,omitempty"`
  147. ExtraArgs []string `yaml:"extra_args,flow,omitempty"`
  148. ServerCert string `yaml:"server_cert,omitempty"`
  149. ServerKey string `yaml:"server_key,omitempty"`
  150. CACert string `yaml:"ca_cert,omitempty"`
  151. CAKey string `yaml:"ca_key,omitempty"`
  152. Environment []string `yaml:"environment,omitempty"`
  153. StorageContext string `yaml:"storage_context,omitempty"`
  154. Exec bool `yaml:"exec,omitempty"`
  155. }
  156. type SshConfig struct {
  157. Keys map[string]string `yaml:"keys,omitempty"`
  158. }
  159. type StateConfig struct {
  160. Directory string `yaml:"directory,omitempty"`
  161. FsType string `yaml:"fstype,omitempty"`
  162. Dev string `yaml:"dev,omitempty"`
  163. Wait bool `yaml:"wait,omitempty"`
  164. Required bool `yaml:"required,omitempty"`
  165. Autoformat []string `yaml:"autoformat,omitempty"`
  166. MdadmScan bool `yaml:"mdadm_scan,omitempty"`
  167. Script string `yaml:"script,omitempty"`
  168. OemFsType string `yaml:"oem_fstype,omitempty"`
  169. OemDev string `yaml:"oem_dev,omitempty"`
  170. }
  171. type CloudInit struct {
  172. Datasources []string `yaml:"datasources,omitempty"`
  173. }
  174. type Defaults struct {
  175. Hostname string `yaml:"hostname,omitempty"`
  176. Docker DockerConfig `yaml:"docker,omitempty"`
  177. Network netconf.NetworkConfig `yaml:"network,omitempty"`
  178. }
  179. func (r Repositories) ToArray() []string {
  180. result := make([]string, 0, len(r))
  181. for _, repo := range r {
  182. if repo.Url != "" {
  183. result = append(result, repo.Url)
  184. }
  185. }
  186. return result
  187. }