Пример #1
0
func NewConfig() *Config {
	return &Config{
		Debug: DEBUG,
		State: StateConfig{
			Required: false,
			Dev:      "LABEL=RANCHER_STATE",
			FsType:   "auto",
		},
		BootstrapDocker: DockerConfig{
			Args: []string{
				"docker",
				"-d",
				"-s", "overlay",
				"-b", "none",
				"--restart=false",
				"-g", "/var/lib/system-docker",
				"-G", "root",
				"-H", DOCKER_SYSTEM_HOST,
			},
		},
		SystemDocker: DockerConfig{
			Args: []string{
				"docker",
				"-d",
				"--log-driver", "syslog",
				"-s", "overlay",
				"-b", "docker-sys",
				"--fixed-cidr", "172.18.42.1/16",
				"--restart=false",
				"-g", "/var/lib/system-docker",
				"-G", "root",
				"-H", DOCKER_SYSTEM_HOST,
			},
		},
		Modules: []string{},
		UserDocker: DockerConfig{
			TLSArgs: []string{
				"--tlsverify",
				"--tlscacert=ca.pem",
				"--tlscert=server-cert.pem",
				"--tlskey=server-key.pem",
				"-H=0.0.0.0:2376",
			},
			Args: []string{
				"docker",
				"-d",
				"-s", "overlay",
				"-G", "docker",
				"-H", DOCKER_HOST,
			},
		},
		Network: NetworkConfig{
			Dns: DnsConfig{
				Nameservers: []string{"8.8.8.8", "8.8.4.4"},
			},
			Interfaces: map[string]InterfaceConfig{
				"eth*": {
					DHCP: true,
				},
				"lo": {
					Address: "127.0.0.1/8",
				},
			},
		},
		CloudInit: CloudInit{
			Datasources: []string{"configdrive:/media/config-2"},
		},
		Upgrade: UpgradeConfig{
			Url:   "https://releases.rancher.com/os/versions.yml",
			Image: "rancher/os",
		},
		BootstrapContainers: map[string]*project.ServiceConfig{
			"udev": {
				Net:        "host",
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					DETACH: "false",
					SCOPE:  SYSTEM,
				}),
				Volumes: []string{
					"/dev:/host/dev",
					"/lib/modules:/lib/modules",
					"/lib/firmware:/lib/firmware",
				},
				Image:     "udev",
				LogDriver: "json-file",
			},
		},
		SystemContainers: map[string]*project.ServiceConfig{
			"udev": {
				Image:      "udev",
				Restart:    "always",
				Net:        "host",
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					DETACH: "true",
					SCOPE:  SYSTEM,
				}),
				Environment: project.NewMaporslice([]string{
					"DAEMON=true",
				}),
				VolumesFrom: []string{
					"system-volumes",
				},
			},
			"system-volumes": {
				Image:      "state",
				Net:        "none",
				ReadOnly:   true,
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					CREATE_ONLY: "true",
					SCOPE:       SYSTEM,
				}),
				Volumes: []string{
					"/dev:/host/dev",
					"/var/lib/rancher/conf:/var/lib/rancher/conf",
					"/etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt.rancher",
					"/lib/modules:/lib/modules",
					"/lib/firmware:/lib/firmware",
					"/var/run:/var/run",
					"/var/log:/var/log",
				},
				LogDriver: "json-file",
			},
			"command-volumes": {
				Image:      "state",
				Net:        "none",
				ReadOnly:   true,
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					CREATE_ONLY: "true",
					SCOPE:       SYSTEM,
				}),
				Volumes: []string{
					"/init:/sbin/halt:ro",
					"/init:/sbin/poweroff:ro",
					"/init:/sbin/reboot:ro",
					"/init:/sbin/shutdown:ro",
					"/init:/sbin/netconf:ro",
					"/init:/usr/bin/cloud-init:ro",
					"/init:/usr/bin/rancherctl:ro", // deprecated, use `ros` instead
					"/init:/usr/bin/ros:ro",
					"/init:/usr/bin/respawn:ro",
					"/init:/usr/bin/system-docker:ro",
					"/init:/usr/sbin/wait-for-docker:ro",
					"/lib/modules:/lib/modules",
					"/usr/bin/docker:/usr/bin/docker:ro",
				},
				LogDriver: "json-file",
			},
			"user-volumes": {
				Image:      "state",
				Net:        "none",
				ReadOnly:   true,
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					CREATE_ONLY: "true",
					SCOPE:       SYSTEM,
				}),
				Volumes: []string{
					"/home:/home",
					"/opt:/opt",
				},
				LogDriver: "json-file",
			},
			"docker-volumes": {
				Image:      "state",
				Net:        "none",
				ReadOnly:   true,
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					CREATE_ONLY: "true",
					SCOPE:       SYSTEM,
				}),
				Volumes: []string{
					"/var/lib/rancher/conf:/var/lib/rancher/conf",
					"/var/lib/docker:/var/lib/docker",
					"/var/lib/system-docker:/var/lib/system-docker",
				},
				LogDriver: "json-file",
			},
			"all-volumes": {
				Image:      "state",
				Net:        "none",
				ReadOnly:   true,
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					CREATE_ONLY: "true",
					SCOPE:       SYSTEM,
				}),
				VolumesFrom: []string{
					"docker-volumes",
					"command-volumes",
					"user-volumes",
					"system-volumes",
				},
				LogDriver: "json-file",
			},
			"preload-system-images": {
				Image:      "preload",
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					DETACH: "false",
					SCOPE:  SYSTEM,
				}),
				VolumesFrom: []string{
					"command-volumes",
					"system-volumes",
				},
				Volumes: []string{
					"/var/run/system-docker.sock:/var/run/docker.sock",
					"/var/lib/system-docker/preload:/mnt/preload",
				},
			},
			"cloud-init-pre": {
				Image:      "cloudinit",
				Privileged: true,
				Net:        "host",
				Labels: project.NewSliceorMap(map[string]string{
					RELOAD_CONFIG: "true",
					DETACH:        "false",
					SCOPE:         SYSTEM,
				}),
				Environment: project.NewMaporslice([]string{
					"CLOUD_INIT_NETWORK=false",
				}),
				Links: []string{
					"preload-system-images",
				},
				VolumesFrom: []string{
					"command-volumes",
					"system-volumes",
				},
			},
			"network": {
				Image:      "network",
				Privileged: true,
				Net:        "host",
				Labels: project.NewSliceorMap(map[string]string{
					DETACH: "false",
					SCOPE:  SYSTEM,
				}),
				Links: []string{
					"cloud-init-pre",
				},
				VolumesFrom: []string{
					"command-volumes",
					"system-volumes",
				},
			},
			"cloud-init": {
				Image:      "cloudinit",
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					RELOAD_CONFIG: "true",
					DETACH:        "false",
					SCOPE:         SYSTEM,
				}),
				Net: "host",
				Links: []string{
					"preload-user-images",
					"cloud-init-pre",
					"network",
				},
				VolumesFrom: []string{
					"command-volumes",
					"system-volumes",
				},
			},
			"ntp": {
				Image:      "ntp",
				Restart:    "always",
				Privileged: true,
				Net:        "host",
				Labels: project.NewSliceorMap(map[string]string{
					SCOPE: SYSTEM,
				}),
				Links: []string{
					"cloud-init",
					"network",
				},
			},
			"syslog": {
				Image:      "syslog",
				Restart:    "always",
				Privileged: true,
				Net:        "host",
				Labels: project.NewSliceorMap(map[string]string{
					SCOPE: SYSTEM,
				}),
				VolumesFrom: []string{
					"system-volumes",
				},
				LogDriver: "json-file",
			},
			"docker": {
				Image:      "docker",
				Restart:    "always",
				Privileged: true,
				Pid:        "host",
				Ipc:        "host",
				Net:        "host",
				Labels: project.NewSliceorMap(map[string]string{
					SCOPE: SYSTEM,
				}),
				Links: []string{
					"network",
				},
				VolumesFrom: []string{
					"all-volumes",
				},
			},
			"dockerwait": {
				Image: "dockerwait",
				Net:   "host",
				Labels: project.NewSliceorMap(map[string]string{
					DETACH: "false",
					SCOPE:  SYSTEM,
				}),
				Links: []string{
					"docker",
				},
				VolumesFrom: []string{
					"all-volumes",
				},
			},
			"preload-user-images": {
				Image:      "preload",
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					DETACH: "false",
					SCOPE:  SYSTEM,
				}),
				Links: []string{
					"dockerwait",
				},
				VolumesFrom: []string{
					"command-volumes",
					"system-volumes",
				},
				Volumes: []string{
					"/var/run/docker.sock:/var/run/docker.sock",
					"/var/lib/docker/preload:/mnt/preload",
				},
			},
			"console": {
				Image:      "console",
				Privileged: true,
				Links: []string{
					"cloud-init",
				},
				Labels: project.NewSliceorMap(map[string]string{
					SCOPE: SYSTEM,
				}),
				VolumesFrom: []string{
					"all-volumes",
				},
				Restart: "always",
				Pid:     "host",
				Ipc:     "host",
				Net:     "host",
			},
			"acpid": {
				Image:      "acpid",
				Privileged: true,
				Labels: project.NewSliceorMap(map[string]string{
					SCOPE: SYSTEM,
				}),
				VolumesFrom: []string{
					"command-volumes",
					"system-volumes",
				},
				Net: "host",
			},
		},
		ServicesInclude: map[string]bool{
			"ubuntu-console": false,
		},
		Repositories: map[string]Repository{
			"core": Repository{
				Url: "https://raw.githubusercontent.com/rancherio/os-services/" + DEFAULT_IMAGE_VERSION,
			},
		},
		Services: map[string]*project.ServiceConfig{},
	}
}
Пример #2
0
func autoformat(cfg *config.Config) error {
	if len(cfg.State.Autoformat) == 0 || util.ResolveDevice(cfg.State.Dev) != "" {
		return nil
	}

	var format string

outer:
	for _, dev := range cfg.State.Autoformat {
		log.Infof("Checking %s to auto-format", dev)
		if _, err := os.Stat(dev); os.IsNotExist(err) {
			continue
		}

		f, err := os.Open(dev)
		if err != nil {
			return err
		}
		defer f.Close()

		buffer := make([]byte, 1048576, 1048576)
		c, err := f.Read(buffer)
		if err != nil {
			return err
		}

		if c != 1048576 {
			log.Infof("%s not right size", dev)
			continue
		}

		boot2docker := false

		if strings.HasPrefix(string(buffer[:len(boot2dockerMagic)]), boot2dockerMagic) {
			boot2docker = true
		}

		if boot2docker == false {
			for _, b := range buffer {
				if b != 0 {
					log.Infof("%s not empty", dev)
					continue outer
				}
			}
		}

		format = dev
		break
	}

	if format != "" {
		log.Infof("Auto formatting : %s", format)

		// copy
		udev := *cfg.BootstrapContainers["udev"]
		udev.Links = append(udev.Links, "autoformat")
		udev.LogDriver = "json-file"

		err := docker.RunServices("autoformat", cfg, map[string]*project.ServiceConfig{
			"autoformat": {
				Net:        "none",
				Privileged: true,
				Image:      "autoformat",
				Command:    format,
				Labels: project.NewSliceorMap(map[string]string{
					config.DETACH: "false",
					config.SCOPE:  config.SYSTEM,
				}),
				LogDriver: "json-file",
				Environment: project.NewMaporslice([]string{
					"MAGIC=" + boot2dockerMagic,
				}),
			},
			"udev": &udev,
		})

		return err
	}

	return nil
}
Пример #3
0
func TestHash2(t *testing.T) {
	assert := require.New(t)

	cfg := &config.ContainerConfig{
		Id:             "docker-volumes",
		Cmd:            "",
		MigrateVolumes: false,
		ReloadConfig:   false,
		CreateOnly:     true,
		Service:        &project.ServiceConfig{CapAdd: nil, CapDrop: nil, CpuShares: 0, Command: "", Detach: "", Dns: project.NewStringorslice(), DnsSearch: project.NewStringorslice(), DomainName: "", Entrypoint: "", EnvFile: "", Environment: project.NewMaporslice([]string{}), Hostname: "", Image: "state", Labels: project.NewSliceorMap(map[string]string{"io.rancher.os.createonly": "true", "io.rancher.os.scope": "system"}), Links: nil, LogDriver: "json-file", MemLimit: 0, Name: "", Net: "none", Pid: "", Ipc: "", Ports: nil, Privileged: true, Restart: "", ReadOnly: true, StdinOpen: false, Tty: false, User: "", Volumes: []string{"/var/lib/docker:/var/lib/docker", "/var/lib/rancher/conf:/var/lib/rancher/conf", "/var/lib/system-docker:/var/lib/system-docker"}, VolumesFrom: nil, WorkingDir: "", Expose: nil, ExternalLinks: nil},
	}

	for i := 0; i < 1000; i++ {
		assert.Equal(getHash(cfg), getHash(cfg), fmt.Sprintf("Failed at iteration: %v", i))
	}
}