Esempio n. 1
0
func PrintPortMappings(id string, ports []string) error {
	cont, err := DockerClient.InspectContainer(id)
	if err != nil {
		return err
	}

	exposedPorts := cont.NetworkSettings.Ports

	var minimalDisplay bool
	if len(ports) == 1 {
		minimalDisplay = true
	}

	// Display everything if no port's requested.
	if len(ports) == 0 {
		for exposed := range exposedPorts {
			ports = append(ports, string(exposed))
		}
	}

	// Replace plain port numbers without suffixes with both "/tcp" and "/udp" suffixes.
	// (For example, replace ["53"] in a slice with ["53/tcp", "53/udp"].)
	normalizedPorts := []string{}
	for _, port := range ports {
		if !strings.HasSuffix(port, "/tcp") && !strings.HasSuffix(port, "/udp") {
			normalizedPorts = append(normalizedPorts, port+"/tcp", port+"/udp")
		} else {
			normalizedPorts = append(normalizedPorts, port)
		}
	}

	for _, port := range normalizedPorts {
		for _, binding := range exposedPorts[docker.Port(port)] {
			hostAndPortBinding := fmt.Sprintf("%s:%s", binding.HostIP, binding.HostPort)

			// If only one port request, display just the binding.
			if minimalDisplay {
				log.Warn(hostAndPortBinding)
			} else {
				log.Warnf("%s -> %s", port, hostAndPortBinding)
			}
		}
	}

	return nil
}
Esempio n. 2
0
func UpdateEris(branch string, checkGit bool, checkGo bool) {

	//check that git/go are installed
	hasGit, hasGo := CheckGitAndGo(checkGit, checkGo)
	if hasGo == false {
		log.Println("Go is not installed. Downloading eris-cli binary...")
		_, err := downloadLatestRelease()
		if err != nil {
			log.Println("Latest binary failed to download with error:", err)
			log.Println("Exiting...")
			os.Exit(1)
		}
	} else if hasGit == false {
		log.Println("Git is not installed. Please install git before continuing.")
		log.Println("Exiting...")
		os.Exit(1)
	}

	//checks for deprecated dir names and renames them
	err := MigrateDeprecatedDirs(common.DirsToMigrate, false) // false = no prompt
	if err != nil {
		log.Warnf("Directory migration error: %v", err)
		log.Warn("Continuing with update without migration")
	}

	//change pwd to eris/cli
	ChangeDirectory("src")

	if branch == "" {
		branch = "master"
	}

	CheckoutBranch(branch)
	PullBranch(branch)

	InstallEris()
	ver := version() //because version.Version will be in RAM.

	log.WithField("=>", ver).Warn("The marmots have updated Eris successfully")
}
Esempio n. 3
0
func MakeGenesisFile(do *def.Do) error {

	//otherwise it'll start its own keys server that won't have the key needed...
	do.Name = "keys"
	IfExit(srv.EnsureRunning(do))

	doThr := def.NowDo()
	doThr.Chain.ChainType = "throwaway" //for teardown
	doThr.Name = "default"
	doThr.Chain.Name = "default" //for teardown
	doThr.Operations.ContainerNumber = 1
	doThr.Operations.PublishAllPorts = true

	log.WithField("=>", doThr.Name).Info("Making genesis.json file. Starting chain")
	if er := NewChain(doThr); er != nil {
		return fmt.Errorf("error starting chain %v\n", er)
	}

	doThr.Operations.Args = []string{"mintgen", "known", do.Chain.Name, fmt.Sprintf("--pub=%s", do.Pubkey)}

	// pipe this output to /chains/chainName/genesis.json
	err := ExecChain(doThr)
	if err != nil {
		log.Warnf("Executing chain error: %v", err)
		log.Warn("Cleaning up")
		doThr.Rm = true
		doThr.RmD = true
		if err := CleanUp(doThr); err != nil {
			return err
		}
	}

	doThr.Rm = true
	doThr.RmD = true
	return CleanUp(doThr) // doesn't clean up keys but that's ~ ok b/c it's about to be used...
}