本文整理匯總了Golang中github.com/eris-ltd/eris-cli/perform.DockerRun函數的典型用法代碼示例。如果您正苦於以下問題:Golang DockerRun函數的具體用法?Golang DockerRun怎麽用?Golang DockerRun使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DockerRun函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: bootDependencies
// boot chain dependencies
// TODO: this currently only supports simple services (with no further dependencies)
func bootDependencies(chain *definitions.Chain, do *definitions.Do) error {
if chain.Dependencies != nil {
name := do.Name
logger.Infoln("Booting chain dependencies", chain.Dependencies.Services, chain.Dependencies.Chains)
for _, srvName := range chain.Dependencies.Services {
do.Name = srvName
srv, err := loaders.LoadServiceDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if !services.IsServiceRunning(srv.Service, srv.Operations) {
name := strings.ToUpper(do.Name)
logger.Infof("%s is not running. Starting now. Waiting for %s to become available \n", name, name)
if _, err = perform.DockerRun(srv.Service, srv.Operations); err != nil {
return err
}
}
}
do.Name = name // undo side effects
for _, chainName := range chain.Dependencies.Chains {
chn, err := loaders.LoadChainDefinition(chainName, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if !IsChainRunning(chn) {
return fmt.Errorf("chain %s depends on chain %s but %s is not running", chain.Name, chainName, chainName)
}
}
}
return nil
}
示例2: StartChain
func StartChain(do *definitions.Do) error {
logger.Infoln("Ensuring Key Server is Started.")
//should it take a flag? keys server may be running another cNum
// XXX: currently we don't use or need a key server.
// plus this should be specified in a service def anyways
keysService, err := loaders.LoadServiceDefinition("keys", false, 1)
if err != nil {
return err
}
err = perform.DockerRun(keysService.Service, keysService.Operations)
if err != nil {
return err
}
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
logger.Infoln("Cannot start a chain I cannot find.")
do.Result = "no file"
return nil
}
if chain.Name == "" {
logger.Infoln("Cannot start a chain without a name.")
do.Result = "no name"
return nil
}
chain.Service.Command = loaders.ErisChainStart
if do.Run {
chain.Service.Command = loaders.ErisChainStartApi
}
util.OverWriteOperations(chain.Operations, do.Operations)
chain.Service.Environment = append(chain.Service.Environment, "CHAIN_ID="+chain.ChainID)
logger.Infof("StartChainRaw to DockerRun =>\t%s\n", chain.Service.Name)
logger.Debugf("\twith ChainID =>\t\t%v\n", chain.ChainID)
logger.Debugf("\twith Environment =>\t%v\n", chain.Service.Environment)
logger.Debugf("\twith AllPortsPublshd =>\t%v\n", chain.Operations.PublishAllPorts)
if err := perform.DockerRun(chain.Service, chain.Operations); err != nil {
do.Result = "error"
return err
}
return nil
}
示例3: StartGroup
// start a group of chains or services. catch errors on a channel so we can stop as soon as something goes wrong
func StartGroup(group []*definitions.ServiceDefinition) error {
logger.Debugf("Starting services group =>\t%d Services\n", len(group))
for _, srv := range group {
logger.Debugf("Telling Docker to start srv =>\t%s\n", srv.Name)
if _, err := perform.DockerRun(srv.Service, srv.Operations); err != nil {
return fmt.Errorf("StartGroup. Err starting srv =>\t%s:%v\n", srv.Name, err)
}
}
return nil
}
示例4: PerformDappActionService
func PerformDappActionService(do *definitions.Do, dapp *definitions.Contracts) error {
logger.Infof("Performing DAPP Action =>\t%s:%s:%s\n", do.Service.Name, do.Service.Image, do.Service.Command)
if _, err := perform.DockerRun(do.Service, do.Operations); err != nil {
do.Result = "could not perform dapp action"
return err
}
logger.Infof("Finished performing DAPP Action.\n")
return nil
}
示例5: EnsureRunning
// EnsureRunning checks if a service is running and starts it if not
// TODO: ping all exposed ports until at least one is available (issue #149)
// NOTE: does not accept ENV vars
func EnsureRunning(do *definitions.Do) error {
srv, err := loaders.LoadServiceDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
var id string
if !IsServiceRunning(srv.Service, srv.Operations) {
name := strings.ToUpper(do.Name)
logger.Infof("%s is not running. Starting now. Waiting for %s to become available \n", name, name)
if id, err = perform.DockerRun(srv.Service, srv.Operations); err != nil {
return err
}
// TODO: to do this right we have to get the bound port
// which might be randomly assigned!
cont, err := util.DockerClient.InspectContainer(id)
if err != nil {
return err
}
exposedPorts := cont.NetworkSettings.Ports
MAIN_LOOP:
for {
// give it a half second and then try all the ports
var endpoint string
time.Sleep(500 * time.Millisecond)
for _, ep := range exposedPorts {
for _, p := range ep {
endpoint = fmt.Sprintf("%s:%s", p.HostIP, p.HostPort)
if _, err := net.Dial("tcp", endpoint); err != nil {
time.Sleep(500 * time.Millisecond)
}
}
if _, err := http.Post(endpoint, "", nil); err != nil {
time.Sleep(500 * time.Millisecond)
}
if _, err := http.Get(endpoint); err != nil {
time.Sleep(500 * time.Millisecond)
}
}
time.Sleep(500 * time.Millisecond)
break MAIN_LOOP
}
} else {
logger.Infof("%s is running.\n", strings.ToUpper(do.Name))
}
return nil
}
示例6: StartGroup
// start a group of chains or services. catch errors on a channel so we can stop as soon as something goes wrong
// TODO: Add ONE Chain
func StartGroup(ch chan error, wg *sync.WaitGroup, group []*definitions.ServiceDefinition) {
logger.Debugf("Starting services group =>\t%d Services\n", len(group))
for _, srv := range group {
wg.Add(1)
go func(s *definitions.ServiceDefinition) {
logger.Debugf("Telling Docker to start srv =>\t%s\n", s.Name)
if err := perform.DockerRun(s.Service, s.Operations); err != nil {
ch <- fmt.Errorf("StartGroup. Err starting srv =>\t%s:%v\n", s.Name, err)
}
wg.Done()
}(srv)
}
}
示例7: ImportAction
func ImportAction(do *definitions.Do) error {
if do.Name == "" {
do.Name = strings.Join(do.Args, "_")
}
fileName := filepath.Join(ActionsPath, strings.Join(do.Args, " "))
if filepath.Ext(fileName) == "" {
fileName = fileName + ".toml"
}
s := strings.Split(do.Path, ":")
if s[0] == "ipfs" {
var err error
//unset 1 as default ContainerNumber, let it take flag?
ipfsService, err := loaders.LoadServiceDefinition("ipfs", false, 1)
if err != nil {
return err
}
err = perform.DockerRun(ipfsService.Service, ipfsService.Operations)
if err != nil {
return err
}
if logger.Level > 0 {
err = ipfs.GetFromIPFS(s[1], fileName, "", logger.Writer)
} else {
err = ipfs.GetFromIPFS(s[1], fileName, "", bytes.NewBuffer([]byte{}))
}
if err != nil {
return err
}
return nil
}
if strings.Contains(s[0], "github") {
logger.Println("https://twitter.com/ryaneshea/status/595957712040628224")
return nil
}
fmt.Println("I do not know how to get that file. Sorry.")
return nil
}
示例8: EnsureRunning
func EnsureRunning(do *definitions.Do) error {
srv, err := loaders.LoadServiceDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if !IsServiceRunning(srv.Service, srv.Operations) {
logger.Infof("%s is not running. Starting now. Waiting for %s to become available \n", strings.ToUpper(do.Name))
time.Sleep(time.Second * 5) // this is dirty
err := perform.DockerRun(srv.Service, srv.Operations)
if err != nil {
return err
}
} else {
logger.Infof("%s is running.\n", strings.ToUpper(do.Name))
}
return nil
}
示例9: StartChain
func StartChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
logger.Infoln("Cannot start a chain I cannot find.")
do.Result = "no file"
return nil
}
if chain.Name == "" {
logger.Infoln("Cannot start a chain without a name.")
do.Result = "no name"
return nil
}
// boot the dependencies (eg. keys)
if err := bootDependencies(chain, do); err != nil {
return err
}
chain.Service.Command = loaders.ErisChainStart
util.OverWriteOperations(chain.Operations, do.Operations)
chain.Service.Environment = append(chain.Service.Environment, "CHAIN_ID="+chain.ChainID)
chain.Service.Environment = append(chain.Service.Environment, do.Env...)
if do.Run {
chain.Service.Environment = append(chain.Service.Environment, "ERISDB_API=true")
}
chain.Service.Links = append(chain.Service.Links, do.Links...)
logger.Infof("StartChainRaw to DockerRun =>\t%s\n", chain.Service.Name)
logger.Debugf("\twith ChainID =>\t\t%v\n", chain.ChainID)
logger.Debugf("\twith Environment =>\t%v\n", chain.Service.Environment)
logger.Debugf("\twith AllPortsPublshd =>\t%v\n", chain.Operations.PublishAllPorts)
if _, err := perform.DockerRun(chain.Service, chain.Operations); err != nil {
do.Result = "error"
return err
}
return nil
}
示例10: ExportAction
func ExportAction(do *definitions.Do) error {
_, _, err := LoadActionDefinition(do.Name)
if err != nil {
return err
}
//unset 1 as default ContainerNumber, let it take flag?
ipfsService, err := loaders.LoadServiceDefinition("ipfs", false, 1)
if err != nil {
return err
}
err = perform.DockerRun(ipfsService.Service, ipfsService.Operations)
if err != nil {
return err
}
hash, err := exportFile(do.Name)
if err != nil {
return err
}
do.Result = hash
logger.Println(hash)
return nil
}
示例11: StartServiceByService
func StartServiceByService(srvMain *definitions.Service, ops *definitions.Operation) error {
return perform.DockerRun(srvMain, ops)
}
示例12: setupChain
//.........這裏部分代碼省略.........
filesToCopy := []stringPair{
{do.Path, ""},
{do.GenesisFile, "genesis.json"},
{do.ConfigFile, "config.toml"},
{do.Priv, "priv_validator.json"},
}
if len(csvFiles) == 1 {
filesToCopy = append(filesToCopy, stringPair{csvFiles[0], "genesis.csv"})
} else if len(csvFiles) > 1 {
filesToCopy = append(filesToCopy, stringPair{csvFiles[0], "validators.csv"})
filesToCopy = append(filesToCopy, stringPair{csvFiles[1], "accounts.csv"})
}
if err := copyFiles(dst, filesToCopy); err != nil {
return err
}
// copy from host to container
logger.Debugf("Copying Files into DataCont =>\t%s:%s\n", dst, containerDst)
importDo := definitions.NowDo()
importDo.Name = do.Name
importDo.Operations = do.Operations
if err = data.ImportData(importDo); err != nil {
return err
}
chain := loaders.MockChainDefinition(do.Name, do.ChainID, false, do.Operations.ContainerNumber)
//set maintainer info
chain.Maintainer.Name, chain.Maintainer.Email, err = config.GitConfigUser()
if err != nil {
logger.Debugf(err.Error())
}
// write the chain definition file ...
fileName := filepath.Join(BlockchainsPath, do.Name) + ".toml"
if _, err = os.Stat(fileName); err != nil {
if err = WriteChainDefinitionFile(chain, fileName); err != nil {
return fmt.Errorf("error writing chain definition to file: %v", err)
}
}
chain, err = loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
logger.Debugf("Chain Loaded. Image =>\t\t%v\n", chain.Service.Image)
chain.Operations.PublishAllPorts = do.Operations.PublishAllPorts // TODO: remove this and marshall into struct from cli directly
// cmd should be "new" or "install"
chain.Service.Command = cmd
// write the list of <key>:<value> config options as flags
buf := new(bytes.Buffer)
for _, cv := range do.ConfigOpts {
spl := strings.Split(cv, "=")
if len(spl) != 2 {
return fmt.Errorf("Config options should be <key>=<value> pairs. Got %s", cv)
}
buf.WriteString(fmt.Sprintf(" --%s=%s", spl[0], spl[1]))
}
configOpts := buf.String()
// set chainid and other vars
envVars := []string{
fmt.Sprintf("CHAIN_ID=%s", do.ChainID),
fmt.Sprintf("CONTAINER_NAME=%s", containerName),
fmt.Sprintf("CSV=%v", csvPaths), // for mintgen
fmt.Sprintf("CONFIG_OPTS=%s", configOpts), // config.toml
fmt.Sprintf("REGISTER_PUBKEY=%s", do.Address), // use to sign registration txs for etcb
}
envVars = append(envVars, do.Env...)
if do.Run {
// run erisdb instead of tendermint
envVars = append(envVars, "ERISDB_API=true")
}
logger.Debugf("Set env vars from setupChain =>\t%v\n", envVars)
chain.Service.Environment = append(chain.Service.Environment, envVars...)
logger.Debugf("Set links from setupChain =>\t%v\n", do.Links)
chain.Service.Links = append(chain.Service.Links, do.Links...)
// TODO: if do.N > 1 ...
chain.Operations.DataContainerName = util.DataContainersName(do.Name, do.Operations.ContainerNumber)
if err := bootDependencies(chain, do); err != nil {
return err
}
logger.Debugf("Starting chain via Docker =>\t%s\n", chain.Service.Name)
logger.Debugf("\twith Image =>\t\t%s\n", chain.Service.Image)
_, err = perform.DockerRun(chain.Service, chain.Operations)
// this err is caught in the defer above
return
}
示例13: setupChain
//.........這裏部分代碼省略.........
if err = os.MkdirAll(dst, 0700); err != nil {
return fmt.Errorf("Error making data directory: %v", err)
}
if do.Path != "" {
if err = Copy(do.Path, dst); err != nil {
return err
}
}
if do.GenesisFile != "" {
if err = Copy(do.GenesisFile, path.Join(dst, "genesis.json")); err != nil {
return err
}
} else {
// TODO: do.Run mintgen and open the do.GenesisFile in editor
}
if do.ConfigFile != "" {
if err = Copy(do.ConfigFile, path.Join(dst, "config."+path.Ext(do.ConfigFile))); err != nil {
return err
}
}
// copy from host to container
logger.Debugf("Copying Files into DataCont =>\t%s:%s\n", dst, containerDst)
importDo := definitions.NowDo()
importDo.Name = do.Name
importDo.Operations = do.Operations
if err = data.ImportData(importDo); err != nil {
return err
}
chain := loaders.MockChainDefinition(do.Name, do.ChainID, false, do.Operations.ContainerNumber)
//get maintainer info
uName, err := gitconfig.Username()
if err != nil {
logger.Debugf("Could not find git user.name, setting chain.Maintainer.Name = \"\"")
uName = ""
}
email, err := gitconfig.Email()
if err != nil {
logger.Debugf("Could not find git user.email, setting chain.Maintainer.Email = \"\"")
email = ""
}
chain.Maintainer.Name = uName
chain.Maintainer.Email = email
// write the chain definition file ...
fileName := filepath.Join(BlockchainsPath, do.Name) + ".toml"
if _, err = os.Stat(fileName); err != nil {
if err = WriteChainDefinitionFile(chain, fileName); err != nil {
return fmt.Errorf("error writing chain definition to file: %v", err)
}
}
chain, err = loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
logger.Debugf("Chain Loaded. Image =>\t\t%v\n", chain.Service.Image)
chain.Operations.PublishAllPorts = do.Operations.PublishAllPorts // TODO: remove this and marshall into struct from cli directly
// cmd should be "new" or "install"
chain.Service.Command = cmd
// do we need to create our own do.GenesisFile?
var genGen bool
if do.GenesisFile == "" {
genGen = true
}
// set chainid and other vars
envVars := []string{
"CHAIN_ID=" + do.ChainID,
"CONTAINER_NAME=" + containerName,
fmt.Sprintf("RUN=%v", do.Run),
fmt.Sprintf("GENERATE_GENESIS=%v", genGen),
}
logger.Debugf("Set env vars from setupChain =>\t%v\n", envVars)
for _, eV := range envVars {
chain.Service.Environment = append(chain.Service.Environment, eV)
}
// TODO mint vs. erisdb (in terms of rpc)
chain.Operations.DataContainerName = util.DataContainersName(do.Name, do.Operations.ContainerNumber)
if os.Getenv("TEST_IN_CIRCLE") != "true" {
chain.Operations.Remove = true
}
logger.Debugf("Starting chain via Docker =>\t%s\n", chain.Service.Name)
logger.Debugf("\twith Image =>\t\t%s\n", chain.Service.Image)
err = perform.DockerRun(chain.Service, chain.Operations)
// this err is caught in the defer above
return
}
示例14: setupChain
//.........這裏部分代碼省略.........
}
var csvFile, csvPath string
if do.CSV != "" {
csvFile = "genesis.csv"
csvPath = fmt.Sprintf("/home/eris/.eris/blockchains/%s/%s", do.ChainID, csvFile)
}
if err := copyFiles(dst, []stringPair{
{do.Path, ""},
{do.GenesisFile, "genesis.json"},
{do.ConfigFile, "config.toml"},
{do.Priv, "priv_validator.json"},
{do.CSV, csvFile},
}); err != nil {
return err
}
// copy from host to container
logger.Debugf("Copying Files into DataCont =>\t%s:%s\n", dst, containerDst)
importDo := definitions.NowDo()
importDo.Name = do.Name
importDo.Operations = do.Operations
if err = data.ImportData(importDo); err != nil {
return err
}
chain := loaders.MockChainDefinition(do.Name, do.ChainID, false, do.Operations.ContainerNumber)
//set maintainer info
chain.Maintainer.Name, chain.Maintainer.Email, err = config.GitConfigUser()
if err != nil {
logger.Debugf(err.Error())
}
// write the chain definition file ...
fileName := filepath.Join(BlockchainsPath, do.Name) + ".toml"
if _, err = os.Stat(fileName); err != nil {
if err = WriteChainDefinitionFile(chain, fileName); err != nil {
return fmt.Errorf("error writing chain definition to file: %v", err)
}
}
chain, err = loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
logger.Debugf("Chain Loaded. Image =>\t\t%v\n", chain.Service.Image)
chain.Operations.PublishAllPorts = do.Operations.PublishAllPorts // TODO: remove this and marshall into struct from cli directly
// cmd should be "new" or "install"
chain.Service.Command = cmd
// do we need to create our own do.GenesisFile?
var genGen bool
if do.GenesisFile == "" {
genGen = true
}
// write the list of <key>:<value> config options as flags
buf := new(bytes.Buffer)
for _, cv := range do.ConfigOpts {
spl := strings.Split(cv, "=")
if len(spl) != 2 {
return fmt.Errorf("Config options should be <key>=<value> pairs. Got %s", cv)
}
buf.WriteString(fmt.Sprintf(" --%s=%s", spl[0], spl[1]))
}
configOpts := buf.String()
// set chainid and other vars
envVars := []string{
fmt.Sprintf("CHAIN_ID=%s", do.ChainID),
fmt.Sprintf("CONTAINER_NAME=%s", containerName),
fmt.Sprintf("RUN=%v", do.Run),
fmt.Sprintf("GENERATE_GENESIS=%v", genGen),
fmt.Sprintf("CSV=%v", csvPath),
fmt.Sprintf("CONFIG_OPTS=%s", configOpts),
}
logger.Debugf("Set env vars from setupChain =>\t%v\n", envVars)
for _, eV := range envVars {
chain.Service.Environment = append(chain.Service.Environment, eV)
}
// TODO: if do.N > 1 ...
chain.Operations.DataContainerName = util.DataContainersName(do.Name, do.Operations.ContainerNumber)
if os.Getenv("TEST_IN_CIRCLE") != "true" {
chain.Operations.Remove = true
}
logger.Debugf("Starting chain via Docker =>\t%s\n", chain.Service.Name)
logger.Debugf("\twith Image =>\t\t%s\n", chain.Service.Image)
err = perform.DockerRun(chain.Service, chain.Operations)
// this err is caught in the defer above
return
}