// describeEc2Instances Describes EC2 instances by container istance ID func describeEc2Instances(svc *ecs.ECS, cluster *string, containerInstances []*string) (*ec2.DescribeInstancesOutput, error) { params := &ecs.DescribeContainerInstancesInput{ Cluster: cluster, ContainerInstances: containerInstances, } ins, err := svc.DescribeContainerInstances(params) if err != nil { return nil, err } insfail := cli.Failure(ins.Failures, err) if insfail != nil { return nil, insfail } var ec2Instances = make([]*string, len(ins.ContainerInstances)) for i, v := range ins.ContainerInstances { ec2Instances[i] = v.Ec2InstanceId } ec2client := ec2.New(sess.InitSession()) ec2params := &ec2.DescribeInstancesInput{ DryRun: aws.Bool(false), InstanceIds: ec2Instances, } return ec2client.DescribeInstances(ec2params) }
// Run Main entry point, which runs a command or display a help message. func Run(command string, commands map[string]Command, args []string) ([]*string, error) { svc := ecs.New(sess.InitSession()) var input string if len(args) > 0 { input = args[0] } if cmd, ok := commands[input]; ok { if len(args) > 1 && args[1] == "help" { fmt.Fprintf(os.Stderr, "\n # "+input+"\n "+cmd.Desc+"\n\n Parameters:\n") cmd.Help(args).PrintDefaults() return nil, nil } ret, err := cmd.Cmd(svc, args[1:]) //func(*ecs.ECS, []string) ([]*string, error))(svc, args[1:]) return ret, err } PrintHelp(command, commands, args) return nil, nil }
func consulDefinition(hostname *string, serverIP *string, advertiseIP *string) *ecs.ContainerDefinition { c := ecs.ContainerDefinition{} c.Name = aws.String("kinja-consul-agent") c.Hostname = hostname c.Image = aws.String("progrium/consul") c.Cpu = aws.Int64(156) c.Memory = aws.Int64(256) c.Essential = aws.Bool(true) c.PortMappings = []*ecs.PortMapping{ &ecs.PortMapping{ ContainerPort: aws.Int64(8301), HostPort: aws.Int64(8301), Protocol: aws.String("tcp"), }, &ecs.PortMapping{ ContainerPort: aws.Int64(8301), HostPort: aws.Int64(8301), Protocol: aws.String("udp"), }, &ecs.PortMapping{ ContainerPort: aws.Int64(8400), HostPort: aws.Int64(8400), Protocol: aws.String("tcp"), }, &ecs.PortMapping{ ContainerPort: aws.Int64(8500), HostPort: aws.Int64(8500), Protocol: aws.String("tcp"), }, &ecs.PortMapping{ ContainerPort: aws.Int64(53), HostPort: aws.Int64(53), Protocol: aws.String("udp"), }, } c.MountPoints = []*ecs.MountPoint{ &ecs.MountPoint{ ContainerPath: aws.String("/data"), SourceVolume: aws.String("consul-vol"), ReadOnly: aws.Bool(false), }, &ecs.MountPoint{ ContainerPath: aws.String("/var/run/docker.sock"), SourceVolume: aws.String("consul-socket"), ReadOnly: aws.Bool(false), }, &ecs.MountPoint{ ContainerPath: aws.String("/etc/consul"), SourceVolume: aws.String("consul-config"), ReadOnly: aws.Bool(false), }, } session := sess.InitSession() c.Command = []*string{ aws.String("--join " + *serverIP), //aws.String("--advertise $(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)"), aws.String("--advertise " + *advertiseIP), aws.String("-dc " + *session.Config.Region), aws.String("--config-file /etc/consul/consul.json"), } return &c }