コード例 #1
0
ファイル: commands.go プロジェクト: takasing/ecs-formation
func createClusterPlans(controller *cluster.ClusterControler, projectDir string) []*plan.ClusterUpdatePlan {

	clusters := controller.SearchClusters(projectDir)
	plans := controller.CreateClusterUpdatePlans(clusters)

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

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

		fmt.Println(color.Green(fmt.Sprintf("\t[Update] num = %d", len(plan.UpdateServices))))
		for _, update := range plan.UpdateServices {
			fmt.Println(color.Green(fmt.Sprintf("\t\t (+) %s(%s)", *update.Before.ServiceName, *update.Before.ClusterARN)))
		}

		fmt.Println(color.Red(fmt.Sprintf("\t[Remove] num = %d", len(plan.DeleteServices))))
		for _, delete := range plan.DeleteServices {
			fmt.Println(color.Red(fmt.Sprintf("\t\t (-) %s(%s)", *delete.ServiceName, *delete.ClusterARN)))
		}
		fmt.Println()
	}

	return plans
}
コード例 #2
0
ファイル: commands.go プロジェクト: TanUkkii007/ecs-formation
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)))
		}
	}
}
コード例 #3
0
ファイル: commands.go プロジェクト: takasing/ecs-formation
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
ファイル: commands.go プロジェクト: takasing/ecs-formation
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
}
コード例 #5
0
func (self *BlueGreenController) ApplyBlueGreenDeploy(bgplan *plan.BlueGreenPlan, nodeploy bool) error {

	apias := self.Ecs.AutoscalingApi()

	targetGreen := bgplan.IsBlueWithPrimaryElb()

	var currentLabel *color.Escape
	var nextLabel *color.Escape
	var current *plan.ServiceSet
	var next *plan.ServiceSet
	primaryLb := bgplan.PrimaryElb
	standbyLb := bgplan.StandbyElb
	if targetGreen {
		current = bgplan.Blue
		next = bgplan.Green
		currentLabel = color.Cyan("blue")
		nextLabel = color.Green("green")
	} else {
		current = bgplan.Green
		next = bgplan.Blue
		currentLabel = color.Green("green")
		nextLabel = color.Cyan("blue")
	}

	logger.Main.Infof("Current status is '%s'", currentLabel)
	logger.Main.Infof("Start Blue-Green Deployment: %s to %s ...", currentLabel, nextLabel)
	if nodeploy {
		logger.Main.Infof("Without deployment. It only replaces load balancers.")
	} else {
		// deploy service
		logger.Main.Infof("Updating %s@%s service at %s ...", next.NewService.Service, next.NewService.Cluster, nextLabel)
		if err := self.ClusterController.ApplyServicePlan(next.ClusterUpdatePlan); err != nil {
			return err
		}
	}

	// attach next group to primary lb
	_, erratt := apias.AttachLoadBalancers(*next.AutoScalingGroup.AutoScalingGroupName, []string{
		primaryLb,
	})
	if erratt != nil {
		return erratt
	}
	logger.Main.Infof("Attached to attach %s group to %s(primary).", nextLabel, primaryLb)

	errwlb := self.waitLoadBalancer(*next.AutoScalingGroup.AutoScalingGroupName, primaryLb)
	if errwlb != nil {
		return errwlb
	}
	logger.Main.Infof("Added %s group to primary", nextLabel)

	// detach current group from primary lb
	_, errelbb := apias.DetachLoadBalancers(*current.AutoScalingGroup.AutoScalingGroupName, []string{
		primaryLb,
	})
	if errelbb != nil {
		return errelbb
	}
	logger.Main.Infof("Detached %s group from %s(primary).", currentLabel, primaryLb)

	// detach next group from standby lb
	_, errelbg := apias.DetachLoadBalancers(*next.AutoScalingGroup.AutoScalingGroupName, []string{
		standbyLb,
	})
	if errelbg != nil {
		return errelbg
	}
	logger.Main.Infof("Detached %s group from %s(standby).", nextLabel, standbyLb)

	// attach current group to standby lb
	_, errelba := apias.AttachLoadBalancers(*current.AutoScalingGroup.AutoScalingGroupName, []string{
		standbyLb,
	})
	if errelba != nil {
		return errelba
	}
	logger.Main.Infof("Attached %s group to %s(standby).", currentLabel, standbyLb)

	return nil
}
コード例 #6
0
ファイル: printer.go プロジェクト: TanUkkii007/ecs-formation
func PrintlnCyan(a ...interface{}) (int, error) {
	return Println(color.Cyan(fmt.Sprint(a...)))
}