예제 #1
0
파일: manage.go 프로젝트: mxjxn/eris-cli
// TODO: skip errors flag
func RmData(do *definitions.Do) (err error) {
	if len(do.Operations.Args) == 0 {
		do.Operations.Args = []string{do.Name}
	}
	for _, name := range do.Operations.Args {
		do.Name = name
		if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
			log.WithField("=>", do.Name).Info("Removing data container")

			srv := definitions.BlankServiceDefinition()
			srv.Operations.SrvContainerName = util.ContainersName("data", do.Name, do.Operations.ContainerNumber)

			if err = perform.DockerRemove(srv.Service, srv.Operations, false, do.Volumes); err != nil {
				log.Errorf("Error removing %s: %v", do.Name, err)
				return err
			}

		} else {
			err = fmt.Errorf("I cannot find that data container for %s. Please check the data container name you sent me.", do.Name)
			log.Error(err)
			return err
		}

		if do.RmHF {
			log.WithField("=>", do.Name).Warn("Removing host directory")
			if err = os.RemoveAll(filepath.Join(DataContainersPath, do.Name)); err != nil {
				return err
			}
		}
	}

	do.Result = "success"
	return err
}
예제 #2
0
func NewService(do *definitions.Do) error {
	srv := definitions.BlankServiceDefinition()
	srv.Name = do.Name
	srv.Service.Name = do.Name
	srv.Service.Image = do.Operations.Args[0]
	srv.Service.AutoData = true

	var err error
	//get maintainer info
	srv.Maintainer.Name, srv.Maintainer.Email, err = config.GitConfigUser()
	if err != nil {
		log.Debug(err.Error())
	}

	log.WithFields(log.Fields{
		"service": srv.Service.Name,
		"image":   srv.Service.Image,
	}).Debug("Creating a new service definition file")
	err = WriteServiceDefinitionFile(srv, filepath.Join(ServicesPath, do.Name+".toml"))
	if err != nil {
		return err
	}
	do.Result = "success"
	return nil
}
예제 #3
0
func NewService(do *definitions.Do) error {
	srv := definitions.BlankServiceDefinition()
	srv.Name = do.Name
	srv.Service.Name = do.Name
	srv.Service.Image = do.Args[0]
	srv.Service.AutoData = true

	//get maintainer info
	uName, err := gitconfig.Username()
	if err != nil {
		logger.Debugf("Could not find git user.name, setting service.Maintainer.Name = \"\"")
		uName = ""
	}
	email, err := gitconfig.Email()
	if err != nil {
		logger.Debugf("Could not find git user.email, setting service.Maintainer.Email = \"\"")
		email = ""
	}

	srv.Maintainer.Name = uName
	srv.Maintainer.Email = email

	logger.Debugf("Creating a new srv def file =>\t%s:%s\n", srv.Service.Name, srv.Service.Image)
	err = WriteServiceDefinitionFile(srv, path.Join(ServicesPath, do.Name+".toml"))
	if err != nil {
		return err
	}
	do.Result = "success"
	return nil
}
예제 #4
0
func RmData(do *definitions.Do) error {
	if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
		logger.Infoln("Removing data container " + do.Name)

		srv := definitions.BlankServiceDefinition()
		srv.Operations.SrvContainerName = util.ContainersName("data", do.Name, do.Operations.ContainerNumber)

		err := perform.DockerRemove(srv.Service, srv.Operations, false)
		if err != nil {
			return err
		}

	} else {
		return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.")
	}

	if do.RmHF {
		logger.Println("Removing host folder " + do.Name)
		err := os.RemoveAll(path.Join(DataContainersPath, do.Name))
		if err != nil {
			return err
		}
	}

	do.Result = "success"
	return nil
}
예제 #5
0
func MockServiceDefinition(servName string, newCont bool, cNum ...int) *definitions.ServiceDefinition {
	srv := definitions.BlankServiceDefinition()
	srv.Name = servName

	if len(cNum) == 0 {
		srv.Operations.ContainerNumber = util.AutoMagic(cNum[0], "service", newCont)
		logger.Debugf("Mocking Service Definition =>\t%s:%d (autoassigned)\n", servName, cNum[0])
	} else {
		srv.Operations.ContainerNumber = cNum[0]
		logger.Debugf("Mocking Service Definition =>\t%s:%d\n", servName, cNum[0])
	}

	ServiceFinalizeLoad(srv)
	return srv
}
예제 #6
0
파일: manage.go 프로젝트: mxjxn/eris-cli
func InspectData(do *definitions.Do) error {
	if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
		log.WithField("=>", do.Name).Info("Inspecting data container")

		srv := definitions.BlankServiceDefinition()
		srv.Operations.SrvContainerName = util.ContainersName(definitions.TypeData, do.Name, do.Operations.ContainerNumber)

		err := perform.DockerInspect(srv.Service, srv.Operations, do.Operations.Args[0])
		if err != nil {
			return err
		}
	} else {
		return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.")
	}
	do.Result = "success"
	return nil
}
예제 #7
0
파일: services.go 프로젝트: mxjxn/eris-cli
func MockServiceDefinition(servName string, newCont bool, cNum ...int) *definitions.ServiceDefinition {
	srv := definitions.BlankServiceDefinition()
	srv.Name = servName

	if len(cNum) == 0 {
		srv.Operations.ContainerNumber = util.AutoMagic(cNum[0], definitions.TypeService, newCont)
		log.WithField("=>", fmt.Sprintf("%s:%d", servName, cNum[0])).Debug("Mocking service definition (autoassigned)")
	} else {
		srv.Operations.ContainerNumber = cNum[0]
		log.WithField("=>", fmt.Sprintf("%s:%d", servName, cNum[0])).Debug("Mocking service definition")
	}

	srv.Operations.ContainerType = definitions.TypeService
	srv.Operations.Labels = util.Labels(servName, srv.Operations)

	ServiceFinalizeLoad(srv)
	return srv
}
예제 #8
0
func RenameData(do *definitions.Do) error {
	logger.Infof("Renaming Data =>\t\t%s:%s\n", do.Name, do.NewName)
	logger.Debugf("\twith ContainerNumber =>\t%d\n", do.Operations.ContainerNumber)

	if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {

		srv := definitions.BlankServiceDefinition()
		srv.Operations.SrvContainerName = util.ContainersName("data", do.Name, do.Operations.ContainerNumber)

		err := perform.DockerRename(srv.Service, srv.Operations, do.Name, do.NewName)
		if err != nil {
			return err
		}
	} else {
		return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.")
	}
	do.Result = "success"
	return nil
}
예제 #9
0
func LoadServiceDefinition(servName string, newCont bool, cNum ...int) (*definitions.ServiceDefinition, error) {
	if len(cNum) == 0 {
		cNum = append(cNum, 0)
	}

	if cNum[0] == 0 {
		cNum[0] = util.AutoMagic(0, definitions.TypeService, newCont)
		logger.Debugf("Loading Service Definition =>\t%s:%d (autoassigned)\n", servName, cNum[0])
	} else {
		logger.Debugf("Loading Service Definition =>\t%s:%d\n", servName, cNum[0])
	}

	srv := definitions.BlankServiceDefinition()
	srv.Operations.ContainerType = definitions.TypeService
	srv.Operations.ContainerNumber = cNum[0]
	srv.Operations.Labels = util.Labels(servName, srv.Operations)
	serviceConf, err := loadServiceDefinition(servName)
	if err != nil {
		return nil, err
	}

	if err = MarshalServiceDefinition(serviceConf, srv); err != nil {
		return nil, err
	}

	if srv.Service == nil {
		return nil, fmt.Errorf("No service given.")
	}

	if err = checkImage(srv.Service); err != nil {
		return nil, err
	}

	// Docker 1.6 (which eris doesn't support) had different linking mechanism.
	if ver, _ := util.DockerClientVersion(); ver >= version.DVER_MIN {
		addDependencyVolumesAndLinks(srv.Dependencies, srv.Service, srv.Operations)
	}

	ServiceFinalizeLoad(srv)
	return srv, nil
}
예제 #10
0
파일: load.go 프로젝트: kustomzone/eris-cli
func PretendToBeAService(serviceYourPretendingToBe string, cNum ...int) *def.ServiceDefinition {
	srv := def.BlankServiceDefinition()
	srv.Name = serviceYourPretendingToBe

	if len(cNum) == 0 || cNum[0] == 0 {
		logger.Debugf("Loading Service Definition =>\t%s:1 (autoassigned)\n", serviceYourPretendingToBe)
		// TODO: findNextContainerIndex => util/container_operations.go
		if len(cNum) == 0 {
			cNum = append(cNum, 1)
		} else {
			cNum[0] = 1
		}
	} else {
		logger.Debugf("Loading Service Definition =>\t%s:%d\n", serviceYourPretendingToBe, cNum[0])
	}

	srv.Operations.ContainerNumber = cNum[0]

	giveMeAllTheNames(serviceYourPretendingToBe, srv)
	return srv
}
예제 #11
0
파일: load.go 프로젝트: mxjxn/eris-cli
func PretendToBeAService(serviceYourPretendingToBe string, cNum ...int) *def.ServiceDefinition {
	srv := def.BlankServiceDefinition()
	srv.Name = serviceYourPretendingToBe

	if len(cNum) == 0 || cNum[0] == 0 {
		log.WithField("=>", fmt.Sprintf("%s:1", serviceYourPretendingToBe)).Debug("Loading service definition (autoassigned)")
		// TODO: findNextContainerIndex => util/container_operations.go
		if len(cNum) == 0 {
			cNum = append(cNum, 1)
		} else {
			cNum[0] = 1
		}
	} else {
		log.WithField("=>", fmt.Sprintf("%s:%d", serviceYourPretendingToBe, cNum[0])).Debug("Loading service definition")
	}

	srv.Operations.ContainerNumber = cNum[0]

	giveMeAllTheNames(serviceYourPretendingToBe, srv)
	return srv
}
예제 #12
0
func NewService(do *definitions.Do) error {
	srv := definitions.BlankServiceDefinition()
	srv.Name = do.Name
	srv.Service.Name = do.Name
	srv.Service.Image = do.Args[0]
	srv.Service.AutoData = true

	var err error
	//get maintainer info
	srv.Maintainer.Name, srv.Maintainer.Email, err = config.GitConfigUser()
	if err != nil {
		logger.Debugf(err.Error())
	}

	logger.Debugf("Creating a new srv def file =>\t%s:%s\n", srv.Service.Name, srv.Service.Image)
	err = WriteServiceDefinitionFile(srv, path.Join(ServicesPath, do.Name+".toml"))
	if err != nil {
		return err
	}
	do.Result = "success"
	return nil
}
예제 #13
0
func LoadServiceDefinition(servName string, newCont bool, cNum ...int) (*definitions.ServiceDefinition, error) {
	if len(cNum) == 0 {
		cNum = append(cNum, 0)
	}

	if cNum[0] == 0 {
		cNum[0] = util.AutoMagic(0, "service", newCont)
		logger.Debugf("Loading Service Definition =>\t%s:%d (autoassigned)\n", servName, cNum[0])
	} else {
		logger.Debugf("Loading Service Definition =>\t%s:%d\n", servName, cNum[0])
	}

	srv := definitions.BlankServiceDefinition()
	srv.Operations.ContainerNumber = cNum[0]
	serviceConf, err := loadServiceDefinition(servName)
	if err != nil {
		return nil, err
	}

	if err = MarshalServiceDefinition(serviceConf, srv); err != nil {
		return nil, err
	}

	if srv.Service == nil {
		return nil, fmt.Errorf("No service given.")
	}

	if err = checkImage(srv.Service); err != nil {
		return nil, err
	}

	if os.Getenv("TEST_IN_CIRCLE") != "true" { // this really should be docker version < 1.7...?
		addDependencyVolumesAndLinks(srv)
	}

	ServiceFinalizeLoad(srv)
	return srv, nil
}
예제 #14
0
// Build against Docker cli...
//   Client version: 1.6.2, 1.7
//   Client API version: 1.18, 1.19
// Verified against ...
//   Client version: 1.6.2, 1.7
//   Client API version: 1.18, 1.19
func DockerCreateDataContainer(srvName string, containerNumber int) error {
	logger.Infof("Creating Data Container for =>\t%s\n", srvName)

	srv := def.BlankServiceDefinition()
	srv.Operations.DataContainerName = util.DataContainersName(srvName, containerNumber)
	optsData, err := configureDataContainer(srv.Service, srv.Operations, nil)
	if err != nil {
		return err
	}

	srv.Operations.SrvContainerName = srv.Operations.DataContainerName // mock for the query function
	if _, exists := ContainerExists(srv.Operations); exists {
		logger.Infoln("Data container exists. Not creating.")
		return nil
	}

	cont, err := createContainer(optsData)
	if err != nil {
		return err
	}

	logger.Infof("Data Container ID =>\t\t%s\n", cont.ID)
	return nil
}
예제 #15
0
파일: operate.go 프로젝트: mxjxn/eris-cli
func DefineAppActionService(do *definitions.Do, app *definitions.Contracts) error {
	var cmd string

	switch do.Name {
	case "test":
		cmd = app.AppType.TestCmd
	case "deploy":
		cmd = app.AppType.DeployCmd
	default:
		return fmt.Errorf("I do not know how to perform that task (%s)\nPlease check what you can do with contracts by typing [eris contracts].\n", do.Name)
	}

	// if manual, set task
	if app.AppType.Name == "manual" {
		switch do.Name {
		case "test":
			cmd = app.TestTask
		case "deploy":
			cmd = app.DeployTask
		}
	}

	// task flag override
	if do.Task != "" {
		app.AppType = definitions.GulpApp()
		cmd = do.Task
	}

	if cmd == "nil" {
		return fmt.Errorf("I cannot perform that task against that app type.\n")
	}

	// build service that will run
	do.Service.Name = app.Name + "_tmp_" + do.Name
	do.Service.Image = app.AppType.BaseImage
	do.Service.AutoData = true
	do.Service.EntryPoint = app.AppType.EntryPoint
	do.Service.Command = cmd
	if do.Path != pwd {
		do.Service.WorkDir = do.Path // do.Path is actually where the workdir inside the container goes
	} else {
		do.Service.WorkDir = filepath.Join(common.ErisContainerRoot, "apps", app.Name)
	}
	do.Service.User = "******"

	srv := definitions.BlankServiceDefinition()
	srv.Service = do.Service
	srv.Operations = do.Operations
	loaders.ServiceFinalizeLoad(srv)
	do.Service = srv.Service
	do.Operations = srv.Operations
	do.Operations.Follow = true

	linkAppToChain(do, app)

	if app.AppType.Name == "epm" {
		prepareEpmAction(do, app)
	}

	// make data container and import do.Path to do.Path (if exists)
	doData := definitions.NowDo()
	doData.Name = do.Service.Name
	doData.Operations = do.Operations
	if do.Path != pwd {
		doData.Destination = do.Path
	} else {
		doData.Destination = common.ErisContainerRoot
	}

	doData.Source = 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":     do.Path,
		"location": loca,
	}).Debug("Creating app data container")
	common.Copy(do.Path, loca)
	if err := data.ImportData(doData); err != nil {
		return err
	}
	do.Operations.DataContainerName = util.DataContainersName(doData.Name, doData.Operations.ContainerNumber)

	log.Debug("App action built")
	return nil
}
예제 #16
0
func DefineDappActionService(do *definitions.Do, dapp *definitions.Contracts) error {
	var cmd string

	switch do.Name {
	case "test":
		cmd = dapp.DappType.TestCmd
	case "deploy":
		cmd = dapp.DappType.DeployCmd
	default:
		return fmt.Errorf("I do not know how to perform that task (%s)\nPlease check what you can do with contracts by typing [eris contracts].\n", do.Name)
	}

	// if manual, set task
	if dapp.DappType.Name == "manual" {
		switch do.Name {
		case "test":
			cmd = dapp.TestTask
		case "deploy":
			cmd = dapp.DeployTask
		}
	}

	// task flag override
	if do.Task != "" {
		dapp.DappType = definitions.GulpDapp()
		cmd = do.Task
	}

	if cmd == "nil" {
		return fmt.Errorf("I cannot perform that task against that dapp type.\n")
	}

	// dapp-specific tests
	if dapp.DappType.Name == "pyepm" {
		if do.ConfigFile == "" {
			return fmt.Errorf("The pyepm dapp type requires a --yaml flag for the package definition you would like to deploy.\n")
		} else {
			cmd = do.ConfigFile
		}
	}

	// build service that will run
	do.Service.Name = dapp.Name + "_tmp_" + do.Name
	do.Service.Image = dapp.DappType.BaseImage
	do.Service.AutoData = true
	do.Service.EntryPoint = dapp.DappType.EntryPoint
	do.Service.Command = cmd
	if do.NewName != "" {
		do.Service.WorkDir = do.NewName // do.NewName is actually where the workdir inside the container goes
	}
	do.Service.User = "******"

	srv := definitions.BlankServiceDefinition()
	srv.Service = do.Service
	srv.Operations = do.Operations
	loaders.ServiceFinalizeLoad(srv)
	do.Service = srv.Service
	do.Operations = srv.Operations
	do.Operations.Remove = true

	linkDappToChain(do, dapp)

	// make data container and import do.Path to do.NewName (if exists)
	doData := definitions.NowDo()
	doData.Name = do.Service.Name
	doData.Operations = do.Operations
	if do.NewName != "" {
		doData.Path = do.NewName
	}

	loca := path.Join(common.DataContainersPath, doData.Name)
	logger.Debugf("Creating Dapp Data Cont =>\t%s:%s\n", do.Path, loca)
	common.Copy(do.Path, loca)
	data.ImportData(doData)
	do.Operations.DataContainerName = util.DataContainersName(doData.Name, doData.Operations.ContainerNumber)

	logger.Debugf("DApp Action Built.\n")

	return nil
}