//src in container, dest on host func ExportData(cmd *cobra.Command, args []string) { IfExit(ArgCheck(3, "eq", cmd, args)) do.Name = args[0] do.Source = args[1] do.Destination = args[2] IfExit(data.ExportData(do)) }
func ExportKey(do *definitions.Do) error { do.Name = "keys" do.Operations.ContainerNumber = 1 if err := srv.EnsureRunning(do); err != nil { return err } //destination on host if do.Destination == "" { do.Destination = filepath.Join(KeysPath, "data") } //src in container do.Source = path.Join(ErisContainerRoot, "keys", "data", do.Address) if err := data.ExportData(do); err != nil { return err } return nil }
func ExportData(cmd *cobra.Command, args []string) { IfExit(ArgCheck(1, "ge", cmd, args)) do.Name = args[0] setDefaultDir() IfExit(data.ExportData(do)) }
func CleanUp(do *definitions.Do, app *definitions.Contracts) error { log.Info("Cleaning up") if do.Chain.ChainType == "throwaway" { log.WithField("=>", do.Chain.Name).Debug("Destroying throwaway chain") doRm := definitions.NowDo() doRm.Operations = do.Operations doRm.Name = do.Chain.Name doRm.Rm = true doRm.RmD = true chains.KillChain(doRm) latentDir := filepath.Join(common.DataContainersPath, do.Chain.Name) latentFile := filepath.Join(common.ChainsPath, do.Chain.Name+".toml") log.WithFields(log.Fields{ "dir": latentDir, "file": latentFile, }).Debug("Removing latent dir and file") os.RemoveAll(latentDir) os.Remove(latentFile) } else { log.Debug("No throwaway chain to destroy") } doData := definitions.NowDo() doData.Name = do.Service.Name doData.Operations = do.Operations doData.Source = common.ErisContainerRoot if do.Path != pwd { doData.Destination = do.Path } else { doData.Destination = filepath.Join(common.DataContainersPath, doData.Name) } var loca string if do.Path != pwd { loca = filepath.Join(common.DataContainersPath, doData.Name, do.Path) } else { loca = filepath.Join(common.DataContainersPath, doData.Name, "apps", app.Name) } log.WithFields(log.Fields{ "path": doData.Source, "location": loca, }).Debug("Exporting results") data.ExportData(doData) if app.AppType.Name == "epm" { files, _ := filepath.Glob(filepath.Join(loca, "*")) for _, f := range files { dest := filepath.Join(do.Path, filepath.Base(f)) log.WithFields(log.Fields{ "from": f, "to": dest, }).Debug("Moving file") common.Copy(f, dest) } } if !do.RmD { log.WithField("dir", filepath.Join(common.DataContainersPath, do.Service.Name)).Debug("Removing data dir on host") os.RemoveAll(filepath.Join(common.DataContainersPath, do.Service.Name)) } if !do.Rm { doRemove := definitions.NowDo() doRemove.Operations.SrvContainerName = do.Operations.DataContainerName log.WithField("=>", doRemove.Operations.SrvContainerName).Debug("Removing data container") if err := perform.DockerRemove(nil, doRemove.Operations, false, true); err != nil { return err } } return nil }
// MakeChain runs the `eris-cm make` command in a docker container. // It returns an error. Note that if do.Known, do.AccountTypes // or do.ChainType are not set the command will run via interactive // shell. // // do.Name - name of the chain to be created (required) // do.Known - will use the mintgen tool to parse csv's and create a genesis.json (requires do.ChainMakeVals and do.ChainMakeActs) (optional) // do.ChainMakeVals - csv file to use for validators (optional) // do.ChainMakeActs - csv file to use for accounts (optional) // do.AccountTypes - use eris-cm make account-types paradigm (example: Root:1,Participants:25,...) (optional) // do.ChainType - use eris-cm make chain-types paradigm (example: simplechain) (optional) // do.Tarball - instead of outputing raw files in directories, output packages of tarbals (optional) // do.ZipFile - similar to do.Tarball except uses zipfiles (optional) // do.Verbose - verbose output (optional) // do.Debug - debug output (optional) // func MakeChain(do *definitions.Do) error { do.Service.Name = do.Name do.Service.Image = path.Join(version.ERIS_REG_DEF, version.ERIS_IMG_CM) do.Service.User = "******" do.Service.AutoData = true do.Service.Links = []string{fmt.Sprintf("%s:%s", util.ServiceContainersName("keys", do.Operations.ContainerNumber), "keys")} do.Service.Environment = []string{ fmt.Sprintf("ERIS_KEYS_PATH=http://keys:%d", 4767), // note, needs to be made aware of keys port... fmt.Sprintf("ERIS_CHAINMANAGER_ACCOUNTTYPES=%s", strings.Join(do.AccountTypes, ",")), fmt.Sprintf("ERIS_CHAINMANAGER_CHAINTYPE=%s", do.ChainType), fmt.Sprintf("ERIS_CHAINMANAGER_TARBALLS=%v", do.Tarball), fmt.Sprintf("ERIS_CHAINMANAGER_ZIPFILES=%v", do.ZipFile), fmt.Sprintf("ERIS_CHAINMANAGER_OUTPUT=%v", do.Output), fmt.Sprintf("ERIS_CHAINMANAGER_VERBOSE=%v", do.Verbose), fmt.Sprintf("ERIS_CHAINMANAGER_DEBUG=%v", do.Debug), } do.Operations.ContainerType = "service" do.Operations.SrvContainerName = util.ServiceContainersName(do.Name, do.Operations.ContainerNumber) do.Operations.DataContainerName = util.DataContainersName(do.Name, do.Operations.ContainerNumber) if do.RmD { do.Operations.Remove = true } if do.Known { log.Debug("Using MintGen rather than eris:cm") do.Service.EntryPoint = "mintgen" do.Service.Command = fmt.Sprintf("known %s --csv=%s,%s > %s", do.Name, do.ChainMakeVals, do.ChainMakeActs, path.Join(ErisContainerRoot, "chains", do.Name, "genesis.json")) } else { log.Debug("Using eris:cm rather than MintGen") do.Service.EntryPoint = fmt.Sprintf("eris-cm make %s", do.Name) } if !do.Known && len(do.AccountTypes) == 0 && do.ChainType == "" { do.Operations.Interactive = true do.Operations.Args = strings.Split(do.Service.EntryPoint, " ") } if do.Known { do.Operations.Args = append(do.Operations.Args, strings.Split(do.Service.Command, " ")...) do.Service.WorkDir = path.Join(ErisContainerRoot, "chains", do.Name) } doData := definitions.NowDo() doData.Name = do.Name doData.Operations.ContainerNumber = do.Operations.ContainerNumber doData.Operations.DataContainerName = util.DataContainersName(do.Name, do.Operations.ContainerNumber) doData.Operations.ContainerType = "service" if !do.RmD { defer data.RmData(doData) } doData.Source = AccountsTypePath doData.Destination = path.Join(ErisContainerRoot, "chains", "account-types") if err := data.ImportData(doData); err != nil { return err } doData.Source = ChainTypePath doData.Destination = path.Join(ErisContainerRoot, "chains", "chain-types") if err := data.ImportData(doData); err != nil { return err } chnPath := filepath.Join(ChainsPath, do.Name) if _, err := os.Stat(chnPath); !os.IsNotExist(err) { doData.Operations.Args = []string{"mkdir", "--parents", path.Join(ErisContainerRoot, "chains", do.Name)} if err := data.ExecData(doData); err != nil { return err } doData.Operations.Args = []string{} doData.Source = chnPath doData.Destination = path.Join(ErisContainerRoot, "chains", do.Name) if err := data.ImportData(doData); err != nil { return err } } if err := perform.DockerExecService(do.Service, do.Operations); err != nil { return err } doData.Source = path.Join(ErisContainerRoot, "chains") doData.Destination = ErisRoot return data.ExportData(doData) }
func CleanUp(do *definitions.Do, app *definitions.Contracts) error { logger.Infof("Commensing CleanUp.\n") if do.Chain.ChainType == "throwaway" { logger.Debugf("Destroying Throwaway Chain =>\t%s\n", do.Chain.Name) doRm := definitions.NowDo() doRm.Operations = do.Operations doRm.Name = do.Chain.Name doRm.Rm = true doRm.RmD = true chains.KillChain(doRm) logger.Debugf("Removing latent files/dirs =>\t%s:%s\n", path.Join(common.DataContainersPath, do.Chain.Name), path.Join(common.ChainsPath, do.Chain.Name+".toml")) os.RemoveAll(path.Join(common.DataContainersPath, do.Chain.Name)) os.Remove(path.Join(common.ChainsPath, do.Chain.Name+".toml")) } else { logger.Debugf("No Throwaway Chain to destroy.\n") } doData := definitions.NowDo() doData.Name = do.Service.Name doData.Operations = do.Operations doData.Source = common.ErisContainerRoot if do.Path != pwd { doData.Destination = do.Path } else { doData.Destination = filepath.Join(common.DataContainersPath, doData.Name) } var loca string if do.Path != pwd { loca = path.Join(common.DataContainersPath, doData.Name, do.Path) } else { loca = path.Join(common.DataContainersPath, doData.Name, "apps", app.Name) } logger.Debugf("Exporting Results =>\t\t%s:%s\n", doData.Source, loca) data.ExportData(doData) if app.AppType.Name == "epm" { files, _ := filepath.Glob(filepath.Join(loca, "*")) for _, f := range files { dest := filepath.Join(do.Path, filepath.Base(f)) logger.Debugf("Moving file =>\t\t\t%s:%s\n", f, dest) common.Copy(f, dest) } } if !do.RmD { logger.Debugf("Removing data dir on host =>\t%s\n", path.Join(common.DataContainersPath, do.Service.Name)) os.RemoveAll(path.Join(common.DataContainersPath, do.Service.Name)) } if !do.Rm { doRemove := definitions.NowDo() doRemove.Operations.SrvContainerName = do.Operations.DataContainerName logger.Debugf("Removing data contnr =>\t\t%s\n", doRemove.Operations.SrvContainerName) if err := perform.DockerRemove(nil, doRemove.Operations, false, true); err != nil { return err } } return nil }