Example #1
0
func (g *Godspeed) LoadPlugins() {
	// Load Configuration
	var err error
	var confLoader *plugo.ConfigLoader
	c := &PluginConfig{}
	if g.config.ConfigFile != "" {
		confLoader = &plugo.ConfigLoader{}
		err = confLoader.LoadFromFile(g.config.ConfigFile, &c)
		if err != nil {
			log.Fatalf("Unable to read configuration file: %s", err.Error())
		}
	} else {
		log.Fatal("No config file provided")
	}

	log.SetLevel(log.LogLevel(c.LogLevel))

	// Load all plugins
	g.DeploymentStrategies = make([]DeploymentStrategy, len(c.Deployment))
	plugins := plugo.LoadPluginsWithConfig(confLoader, c.Deployment)
	for i, p := range plugins {
		log.Debug("Loading plugin\t" + log.Colorize(log.YELLOW, c.Deployment[i].Name))
		g.DeploymentStrategies[i] = p.(DeploymentStrategy)
	}
}
Example #2
0
func (s *ECSDeploymentStrategy) createOrUpdateService() {
	exists := s.serviceExists(s.Service.Name)

	// If service does not exist...
	if !exists {
		log.Info(fmt.Sprintf("Service %s not created, creating...", s.Service.Name))
		params := &ecs.CreateServiceInput{
			DesiredCount:   aws.Int64(1),               // Required
			ServiceName:    aws.String(s.Service.Name), // Required
			TaskDefinition: aws.String(s.taskDefinitionARN),
			Cluster:        aws.String(s.ClusterName),
			LoadBalancers: []*ecs.LoadBalancer{
				{ // Required
					ContainerName:    aws.String(s.Service.Application),
					ContainerPort:    aws.Int64(80),
					LoadBalancerName: aws.String(s.ElbId),
				},
			},
			Role: aws.String("ecsServiceRole"),
		}
		_, err := s.ecs.CreateService(params)

		if err != nil {
			log.Fatal(err.Error())
			return
		}

	} else {
		log.Info(fmt.Sprintf("Service %s already created, updating...", s.Service.Name))
		params := &ecs.UpdateServiceInput{
			DesiredCount:   aws.Int64(1),               // Required
			Service:        aws.String(s.Service.Name), // Required
			TaskDefinition: aws.String(s.taskDefinitionARN),
			Cluster:        aws.String(s.ClusterName),
		}
		_, err := s.ecs.UpdateService(params)

		if err != nil {
			log.Fatal(err.Error())
			return
		}

	}
}
Example #3
0
func (s ShellDeploymentStrategy) runCommand(c string) error {

	// Create command string
	cmd := s.createCommand(c)
	log.Info(" --> Running command: %s", c)

	// Create command string
	out, err := cmd.Output()
	if err != nil {
		log.Fatal(fmt.Sprintf("Script '%s' with args '%v' not found or is not executable: %v", cmd.Path, cmd.Args, err))
		return err
	}
	log.Info(log.Colorize(log.CYAN, fmt.Sprintf("%s", out)))
	return nil
}
Example #4
0
func (s *ECSDeploymentStrategy) serviceExists(service string) bool {
	params := &ecs.DescribeServicesInput{
		Services: []*string{
			aws.String(service),
		},
		Cluster: aws.String(s.ClusterName),
	}
	resp, err := s.ecs.DescribeServices(params)

	if err != nil {
		log.Fatal(err.Error())
		return false
	}

	if len(resp.Services) > 0 && *resp.Services[0].Status == "ACTIVE" {
		return true

	}
	return false

}