Пример #1
0
func doTask(c *cli.Context) {

	ecsManager, err := buildECSManager()

	if err != nil {
		logger.Main.Error(color.Red(err.Error()))
		os.Exit(1)
	}

	operation, errSubCommand := createOperation(c.Args())

	if errSubCommand != nil {
		logger.Main.Error(color.Red(errSubCommand.Error()))
		os.Exit(1)
	}

	projectDir, err := os.Getwd()
	if err != nil {
		logger.Main.Error(color.Red(err.Error()))
		os.Exit(1)
	}

	taskController, err := task.NewTaskDefinitionController(ecsManager, projectDir, operation.TargetResource)
	if err != nil {
		logger.Main.Error(color.Red(err.Error()))
		os.Exit(1)
	}

	plans := createTaskPlans(taskController, projectDir)

	if operation.SubCommand == "apply" {
		results, errapp := taskController.ApplyTaskDefinitionPlans(plans)

		if errapp != nil {
			logger.Main.Error(color.Red(errapp.Error()))
			os.Exit(1)
		}

		for _, output := range results {
			logger.Main.Infof("Registered Task Definition '%s'", *output.TaskDefinition.Family)
			logger.Main.Info(color.Cyan(util.StringValueWithIndent(output.TaskDefinition, 1)))
		}
	}
}
Пример #2
0
func createTaskPlans(controller *task.TaskDefinitionController, projectDir string) []*plan.TaskUpdatePlan {

	taskDefs := controller.GetTaskDefinitionMap()
	plans := controller.CreateTaskUpdatePlans(taskDefs)

	for _, plan := range plans {
		logger.Main.Infof("Task Definition '%s'", plan.Name)

		for _, add := range plan.NewContainers {
			util.PrintlnCyan(fmt.Sprintf("    (+) %s", add.Name))
			util.PrintlnCyan(fmt.Sprintf("      image: %s", add.Image))
			util.PrintlnCyan(fmt.Sprintf("      ports: %s", add.Ports))
			util.PrintlnCyan(fmt.Sprintf("      environment:\n%s", util.StringValueWithIndent(add.Environment, 4)))
			util.PrintlnCyan(fmt.Sprintf("      links: %s", add.Links))
			util.PrintlnCyan(fmt.Sprintf("      volumes: %s", add.Volumes))
		}

		util.Println()
	}

	return plans
}
Пример #3
0
func doTask(c *cli.Context) {

	ecsManager, err := buildECSManager()

	if err != nil {
		fmt.Fprintf(os.Stderr, "[ERROR]%s\n", color.Red(err.Error()))
		os.Exit(1)
	}

	operation, errSubCommand := createOperation(c.Args())

	if errSubCommand != nil {
		fmt.Fprintf(os.Stderr, "[ERROR]%s\n", color.Red(errSubCommand.Error()))
		os.Exit(1)
	}

	projectDir, err := os.Getwd()
	if err != nil {
		panic(err)
	}

	// plan
	taskController := &task.TaskDefinitionController{
		Ecs:            ecsManager,
		TargetResource: operation.TargetResource,
	}

	plans := createTaskPlans(taskController, projectDir)

	if operation.SubCommand == "apply" {
		results := taskController.ApplyTaskDefinitionPlans(plans)

		for _, output := range results {
			fmt.Printf("Registered Task Definition '%s'", *output.TaskDefinition.Family)
			fmt.Print(color.Cyan(util.StringValueWithIndent(output.TaskDefinition, 1)))
		}
	}
}
Пример #4
0
func createTaskPlans(controller *task.TaskDefinitionController, projectDir string) []*plan.TaskUpdatePlan {

	taskDefs := controller.SearchTaskDefinitions(projectDir)
	plans := controller.CreateTaskUpdatePlans(taskDefs)

	for _, plan := range plans {
		fmt.Printf("Task Definition '%s'\n", plan.Name)

		fmt.Println(color.Cyan(fmt.Sprintf("  [Add] num = %d", len(plan.NewContainers))))
		for _, add := range plan.NewContainers {
			fmt.Println(color.Cyan(fmt.Sprintf("    (+) %s", add.Name)))

			fmt.Println(color.Cyan(fmt.Sprintf("      image: %s", add.Image)))
			fmt.Println(color.Cyan(fmt.Sprintf("      ports: %s", add.Ports)))
			fmt.Println(color.Cyan(fmt.Sprintf("      environment:\n%s", util.StringValueWithIndent(add.Environment, 4))))
			fmt.Println(color.Cyan(fmt.Sprintf("      links: %s", add.Links)))
			fmt.Println(color.Cyan(fmt.Sprintf("      volumes: %s", add.Volumes)))
		}

		fmt.Println()
	}

	return plans
}