예제 #1
0
파일: swarm.go 프로젝트: zanhsieh/pipes
func (sw Swarm) agent(server string, eng docker.Docker) (*engine.Container, error) {
	log.Debugf("Installing Swarm agent on node %s...\n", server)

	// Image
	img := engine.Image{Name: IMAGE}

	// Run
	name := "swarm_agent"
	port := "2375"
	ip := utils.AddrToIP(server)
	cmd := []string{
		"join",
		"--addr", fmt.Sprintf("%s:%s", ip, port),
		fmt.Sprintf("etcd://%s/cluster", utils.SplitAddr(sw.Store.Addr())),
	}
	container := &engine.Container{
		Name:     name,
		Hostname: name,
		Image:    img,
		IP:       ip,
		Cmd:      cmd,
	}
	if _, err := eng.GetImg(img.Name); err != nil {
		if _, err = eng.PullImg(img.Name); err != nil {
			return nil, err
		}
	}
	err := eng.Run(container)
	fmt.Println("Swarm agent running on node:", server)
	return container, err
}
예제 #2
0
파일: swarm.go 프로젝트: zanhsieh/pipes
func (sw Swarm) manager(server string, eng docker.Docker) (*engine.Container, error) {
	log.Debugf("Installing Swarm manager on node %s...\n", server)

	img := engine.Image{Name: IMAGE}
	name := "swarm_manager"
	port := "2375"
	ip := utils.AddrToIP(server)
	cmd := []string{
		"-l", "debug",
		"manage",
		"-H", fmt.Sprintf("tcp://%s:%s", "0.0.0.0", port),
		"--addr", fmt.Sprintf("%s:%s", ip, port),
	}
	cmd = append(cmd, fmt.Sprintf("etcd://%s/cluster", utils.SplitAddr(sw.Store.Addr())))
	container := &engine.Container{
		Name:     name,
		Hostname: name,
		Image:    img,
		IP:       ip,
		Cmd:      cmd,
		Ports: []map[string]string{
			map[string]string{port: ""},
		},
	}
	err := eng.Run(container)
	fmt.Println("Swarm manager running on node:", server)
	return container, err
}