types.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package config
  2. import (
  3. "runtime"
  4. "github.com/coreos/coreos-cloudinit/config"
  5. "github.com/docker/engine-api/types"
  6. composeConfig "github.com/docker/libcompose/config"
  7. "github.com/rancher/netconf"
  8. )
  9. const (
  10. OEM = "/usr/share/ros/oem"
  11. DOCKER_BIN = "/usr/bin/docker"
  12. DOCKER_DIST_BIN = "/usr/bin/docker.dist"
  13. ROS_BIN = "/usr/bin/ros"
  14. SYSINIT_BIN = "/usr/bin/ros-sysinit"
  15. DOCKER_SYSTEM_HOME = "/var/lib/system-docker"
  16. DOCKER_SYSTEM_HOST = "unix:///var/run/system-docker.sock"
  17. DOCKER_HOST = "unix:///var/run/docker.sock"
  18. IMAGES_PATH = "/usr/share/ros"
  19. IMAGES_PATTERN = "images*.tar"
  20. MODULES_ARCHIVE = "/modules.tar"
  21. DEBUG = false
  22. SYSTEM_DOCKER_LOG = "/var/log/system-docker.log"
  23. SYSTEM_DOCKER_BIN = "/usr/bin/system-docker"
  24. LABEL = "label"
  25. HASH = "io.rancher.os.hash"
  26. ID = "io.rancher.os.id"
  27. DETACH = "io.rancher.os.detach"
  28. CREATE_ONLY = "io.rancher.os.createonly"
  29. RELOAD_CONFIG = "io.rancher.os.reloadconfig"
  30. CONSOLE = "io.rancher.os.console"
  31. SCOPE = "io.rancher.os.scope"
  32. REBUILD = "io.docker.compose.rebuild"
  33. SYSTEM = "system"
  34. OsConfigFile = "/usr/share/ros/os-config.yml"
  35. CloudConfigDir = "/var/lib/rancher/conf/cloud-config.d"
  36. CloudConfigBootFile = "/var/lib/rancher/conf/cloud-config.d/boot.yml"
  37. CloudConfigNetworkFile = "/var/lib/rancher/conf/cloud-config.d/network.yml"
  38. CloudConfigScriptFile = "/var/lib/rancher/conf/cloud-config-script"
  39. MetaDataFile = "/var/lib/rancher/conf/metadata"
  40. CloudConfigFile = "/var/lib/rancher/conf/cloud-config.yml"
  41. )
  42. var (
  43. OemConfigFile = OEM + "/oem-config.yml"
  44. VERSION string
  45. ARCH string
  46. SUFFIX string
  47. PrivateKeys = []string{
  48. "rancher.ssh",
  49. "rancher.docker.ca_key",
  50. "rancher.docker.ca_cert",
  51. "rancher.docker.server_key",
  52. "rancher.docker.server_cert",
  53. }
  54. )
  55. func init() {
  56. if VERSION == "" {
  57. VERSION = "v0.0.0-dev"
  58. }
  59. if ARCH == "" {
  60. ARCH = runtime.GOARCH
  61. }
  62. if SUFFIX == "" && ARCH != "amd64" {
  63. SUFFIX = "_" + ARCH
  64. }
  65. }
  66. type Repository struct {
  67. Url string `yaml:"url,omitempty"`
  68. }
  69. type Repositories map[string]Repository
  70. type CloudConfig struct {
  71. SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
  72. WriteFiles []config.File `yaml:"write_files"`
  73. Hostname string `yaml:"hostname"`
  74. Rancher RancherConfig `yaml:"rancher,omitempty"`
  75. }
  76. type RancherConfig struct {
  77. Console string `yaml:"console,omitempty"`
  78. Environment map[string]string `yaml:"environment,omitempty"`
  79. Services map[string]*composeConfig.ServiceConfigV1 `yaml:"services,omitempty"`
  80. BootstrapContainers map[string]*composeConfig.ServiceConfigV1 `yaml:"bootstrap,omitempty"`
  81. Autoformat map[string]*composeConfig.ServiceConfigV1 `yaml:"autoformat,omitempty"`
  82. BootstrapDocker DockerConfig `yaml:"bootstrap_docker,omitempty"`
  83. CloudInit CloudInit `yaml:"cloud_init,omitempty"`
  84. Debug bool `yaml:"debug,omitempty"`
  85. RmUsr bool `yaml:"rm_usr,omitempty"`
  86. Log bool `yaml:"log,omitempty"`
  87. ForceConsoleRebuild bool `yaml:"force_console_rebuild,omitempty"`
  88. Disable []string `yaml:"disable,omitempty"`
  89. ServicesInclude map[string]bool `yaml:"services_include,omitempty"`
  90. Modules []string `yaml:"modules,omitempty"`
  91. Network netconf.NetworkConfig `yaml:"network,omitempty"`
  92. DefaultNetwork netconf.NetworkConfig `yaml:"default_network,omitempty"`
  93. Repositories Repositories `yaml:"repositories,omitempty"`
  94. Ssh SshConfig `yaml:"ssh,omitempty"`
  95. State StateConfig `yaml:"state,omitempty"`
  96. SystemDocker DockerConfig `yaml:"system_docker,omitempty"`
  97. Upgrade UpgradeConfig `yaml:"upgrade,omitempty"`
  98. Docker DockerConfig `yaml:"docker,omitempty"`
  99. RegistryAuths map[string]types.AuthConfig `yaml:"registry_auths,omitempty"`
  100. Defaults Defaults `yaml:"defaults,omitempty"`
  101. ResizeDevice string `yaml:"resize_device,omitempty"`
  102. }
  103. type UpgradeConfig struct {
  104. Url string `yaml:"url,omitempty"`
  105. Image string `yaml:"image,omitempty"`
  106. Rollback string `yaml:"rollback,omitempty"`
  107. }
  108. type DockerConfig struct {
  109. TLS bool `yaml:"tls,omitempty"`
  110. TLSArgs []string `yaml:"tls_args,flow,omitempty"`
  111. Args []string `yaml:"args,flow,omitempty"`
  112. ExtraArgs []string `yaml:"extra_args,flow,omitempty"`
  113. ServerCert string `yaml:"server_cert,omitempty"`
  114. ServerKey string `yaml:"server_key,omitempty"`
  115. CACert string `yaml:"ca_cert,omitempty"`
  116. CAKey string `yaml:"ca_key,omitempty"`
  117. Environment []string `yaml:"environment,omitempty"`
  118. StorageContext string `yaml:"storage_context,omitempty"`
  119. Exec bool `yaml:"exec,omitempty"`
  120. }
  121. type SshConfig struct {
  122. Keys map[string]string `yaml:"keys,omitempty"`
  123. }
  124. type StateConfig struct {
  125. Directory string `yaml:"directory,omitempty"`
  126. FsType string `yaml:"fstype,omitempty"`
  127. Dev string `yaml:"dev,omitempty"`
  128. Required bool `yaml:"required,omitempty"`
  129. Autoformat []string `yaml:"autoformat,omitempty"`
  130. FormatZero bool `yaml:"formatzero,omitempty"`
  131. MdadmScan bool `yaml:"mdadm_scan,omitempty"`
  132. Script string `yaml:"script,omitempty"`
  133. OemFsType string `yaml:"oem_fstype,omitempty"`
  134. OemDev string `yaml:"oem_dev,omitempty"`
  135. }
  136. type CloudInit struct {
  137. Datasources []string `yaml:"datasources,omitempty"`
  138. }
  139. type Defaults struct {
  140. Hostname string `yaml:"hostname,omitempty"`
  141. Network netconf.NetworkConfig `yaml:"network,omitempty"`
  142. }
  143. func (r Repositories) ToArray() []string {
  144. result := make([]string, 0, len(r))
  145. for _, repo := range r {
  146. if repo.Url != "" {
  147. result = append(result, repo.Url)
  148. }
  149. }
  150. return result
  151. }