Пример #1
0
// GetTaskConfig returns a new task for the action
func GetTaskConfig(name, action string, conf *config.JobConfig) (types.TaskConfig, error) {
	switch action {
	case "", "run":
		return types.NewTaskConfig(
			task.NewDefaultName(name, action),
			conf,
			deps(conf),
			newRunTask), nil
	case "remove", "rm":
		return types.NewTaskConfig(
			task.NewName(name, action),
			conf,
			task.NoDependencies,
			newRemoveTask), nil
	}
	if strings.HasPrefix(action, "capture") {
		variable, err := parseCapture(action)
		if err != nil {
			return nil, err
		}
		return types.NewTaskConfig(
			task.NewName(name, action),
			conf,
			deps(conf),
			newCaptureTask(variable)), nil
	}
	return nil, fmt.Errorf("invalid run action %q for task %q", action, name)
}
Пример #2
0
func getAction(name string, resname string, conf *config.ComposeConfig) (action, error) {
	switch name {
	case "", "up":
		return newAction(
			task.NewDefaultName(resname, "up"), RunUp, StopUp, deps(conf))
	case "remove", "rm", "down":
		return newAction(task.NewName(resname, "down"), RunDown, nil, noDeps)
	case "attach":
		return newAction(
			task.NewName(resname, "attach"), RunUpAttached, nil, deps(conf))
	default:
		return action{}, fmt.Errorf("invalid compose action %q for task %q", name, resname)
	}
}
Пример #3
0
func imageDeps(name string, actions ...string) []string {
	deps := []string{}
	for _, action := range actions {
		deps = append(deps, task.NewName(name, action).Name())
	}
	return deps
}
Пример #4
0
// GetTaskConfig returns a new task for the action
func GetTaskConfig(name, action string, conf *config.EnvConfig) (types.TaskConfig, error) {
	switch action {
	case "", "set":
		return types.NewTaskConfig(
			task.NewDefaultName(name, "set"), conf, task.NoDependencies, newTask), nil
	case "rm":
		return types.NewTaskConfig(
			task.NewName(name, "rm"), conf, task.NoDependencies, newRemoveTask), nil
	default:
		return nil, fmt.Errorf("invalid env action %q for task %q", action, name)
	}
}
Пример #5
0
// GetTaskConfig returns a new TaskConfig for the action
func GetTaskConfig(name, act string, conf *config.AliasConfig) (types.TaskConfig, error) {
	switch act {
	case "", "run":
		return types.NewTaskConfig(
			task.NewDefaultName(name, "run"), conf, RunDeps(conf), NewTask), nil
	case "remove", "rm":
		return types.NewTaskConfig(
			task.NewName(name, "rm"), conf, RemoveDeps(conf), NewTask), nil
	default:
		return nil, fmt.Errorf("invalid alias action %q for task %q", act, name)
	}
}
Пример #6
0
// GetTaskConfig returns a new task for the action
func GetTaskConfig(name, action string, conf *config.MountConfig) (types.TaskConfig, error) {

	newTaskConfig := func(name task.Name, builder types.TaskBuilder) (types.TaskConfig, error) {
		return types.NewTaskConfig(name, conf, task.NoDependencies, builder), nil
	}
	switch action {
	case "", "create":
		return newTaskConfig(task.NewDefaultName(name, action), NewTask(runCreate))
	case "remove", "rm":
		return newTaskConfig(task.NewName(name, action), NewTask(remove))
	default:
		return nil, fmt.Errorf("invalid mount action %q for task %q", action, name)
	}
}
Пример #7
0
func (s *CreateTaskSuite) SetupTest() {
	var err error
	s.path, err = ioutil.TempDir("", "mount-task-test")
	s.Require().Nil(err)

	s.task = &Task{
		name: task.NewName("resource", "action"),
		config: &config.MountConfig{
			Bind:     filepath.Join("a", "b", "c"),
			Path:     "/target",
			ReadOnly: false,
		},
		run: runCreate,
	}
	s.action = &createAction{task: s.task}

	s.ctx = context.NewExecuteContext(
		&config.Config{WorkingDir: s.path}, nil, nil, false)
}
Пример #8
0
// GetTaskConfig returns a new TaskConfig for the action
func GetTaskConfig(name, action string, conf *config.ImageConfig) (types.TaskConfig, error) {
	var taskName task.Name

	if action == "" {
		action = defaultAction(conf)
		taskName = task.NewDefaultName(name, action)
	} else {
		taskName = task.NewName(name, action)
	}
	imageAction, err := getAction(action, name)
	if err != nil {
		return nil, err
	}
	return types.NewTaskConfig(
		taskName,
		conf,
		deps(conf, imageAction.dependencies),
		NewTask(imageAction.run),
	), nil
}