Exemplo n.º 1
0
func (c *Container) addLink(link string) {
	if c.hasLink(link) {
		return
	}

	log.Debugf("Adding %s link to %s", link, c.Name)
	c.ContainerCfg.Service.Links = project.NewMaporColonSlice(append(c.ContainerCfg.Service.Links.Slice(), link))
}
Exemplo n.º 2
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:     project.NewCommand(),
			Detach:      "",
			Dns:         project.NewStringorslice(),
			DnsSearch:   project.NewStringorslice(),
			DomainName:  "",
			Entrypoint:  project.NewCommand(),
			EnvFile:     project.NewStringorslice(),
			Environment: project.NewMaporEqualSlice([]string{}),
			Hostname:    "",
			Image:       "state",
			Labels: project.NewSliceorMap(map[string]string{
				"io.rancher.os.createonly": "true",
				"io.rancher.os.scope":      "system"}),
			Links:      project.NewMaporColonSlice(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))
	}
}
Exemplo n.º 3
0
func (s *Sidekick) Config() *project.ServiceConfig {
	links := []string{}

	for _, primary := range s.primaries() {
		links = append(links, primary)
	}

	config := *s.serviceConfig
	config.Links = project.NewMaporColonSlice(links)
	config.VolumesFrom = []string{}

	return &config
}
Exemplo n.º 4
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 = project.NewMaporColonSlice(append(udev.Links.Slice(), "autoformat"))
		udev.LogDriver = "json-file"

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

		return err
	}

	return nil
}