diff --git a/api/controller.go b/api/controller.go index 4c6965f..7c2789c 100644 --- a/api/controller.go +++ b/api/controller.go @@ -534,12 +534,16 @@ func (c *Controller) runTask(serviceName string, runTask service.RunTask) (strin if err != nil { return taskArn, err } + dd, err := s.GetLastDeploy() + if err != nil { + return taskArn, err + } e := ecs.ECS{} taskDefinition, err := e.GetTaskDefinition(clusterName, serviceName) if err != nil { return taskArn, err } - taskArn, err = e.RunTask(clusterName, taskDefinition, runTask) + taskArn, err = e.RunTask(clusterName, taskDefinition, runTask, *dd.DeployData) if err != nil { return taskArn, err } diff --git a/provider/ecs/ecs.go b/provider/ecs/ecs.go index 73c3cd4..4df7561 100644 --- a/provider/ecs/ecs.go +++ b/provider/ecs/ecs.go @@ -537,25 +537,7 @@ func (e *ECS) CreateService(d service.Deploy) error { if strings.ToUpper(d.LaunchType) == "FARGATE" { input.SetLaunchType("FARGATE") } - var sns []*string - var sgs []*string - var aIp string - nc := &ecs.NetworkConfiguration{AwsvpcConfiguration: &ecs.AwsVpcConfiguration{}} - for i, _ := range d.NetworkConfiguration.Subnets { - sns = append(sns, &d.NetworkConfiguration.Subnets[i]) - } - nc.AwsvpcConfiguration.SetSubnets(sns) - for i, _ := range d.NetworkConfiguration.SecurityGroups { - sgs = append(sgs, &d.NetworkConfiguration.SecurityGroups[i]) - } - nc.AwsvpcConfiguration.SetSecurityGroups(sgs) - if d.NetworkConfiguration.AssignPublicIp == "" { - aIp = "DISABLED" - } else { - aIp = d.NetworkConfiguration.AssignPublicIp - } - nc.AwsvpcConfiguration.SetAssignPublicIp(aIp) - input.SetNetworkConfiguration(nc) + input.SetNetworkConfiguration(e.getNetworkConfiguration(d)) } else { // only set role if network mode is not awsvpc (it will be set automatically) if strings.ToLower(d.ServiceProtocol) != "none" { // only set the role if there's a loadbalancer necessary @@ -1092,8 +1074,30 @@ func (e *ECS) ManualScaleService(clusterName, serviceName string, desiredCount i return nil } +func (e *ECS) getNetworkConfiguration(d service.Deploy) *ecs.NetworkConfiguration { + var sns []*string + var sgs []*string + var aIp string + nc := &ecs.NetworkConfiguration{AwsvpcConfiguration: &ecs.AwsVpcConfiguration{}} + for i, _ := range d.NetworkConfiguration.Subnets { + sns = append(sns, &d.NetworkConfiguration.Subnets[i]) + } + nc.AwsvpcConfiguration.SetSubnets(sns) + for i, _ := range d.NetworkConfiguration.SecurityGroups { + sgs = append(sgs, &d.NetworkConfiguration.SecurityGroups[i]) + } + nc.AwsvpcConfiguration.SetSecurityGroups(sgs) + if d.NetworkConfiguration.AssignPublicIp == "" { + aIp = "DISABLED" + } else { + aIp = d.NetworkConfiguration.AssignPublicIp + } + nc.AwsvpcConfiguration.SetAssignPublicIp(aIp) + return nc +} + // run one-off task -func (e *ECS) RunTask(clusterName, taskDefinition string, runTask service.RunTask) (string, error) { +func (e *ECS) RunTask(clusterName, taskDefinition string, runTask service.RunTask, d service.Deploy) (string, error) { var taskArn string svc := ecs.New(session.New()) input := &ecs.RunTaskInput{ @@ -1113,6 +1117,14 @@ func (e *ECS) RunTask(clusterName, taskDefinition string, runTask service.RunTas taskOverride.SetContainerOverrides(containerOverrides) input.SetOverrides(taskOverride) + // network configuration + if d.NetworkMode == "awsvpc" && len(d.NetworkConfiguration.Subnets) > 0 { + if strings.ToUpper(d.LaunchType) == "FARGATE" { + input.SetLaunchType("FARGATE") + } + input.SetNetworkConfiguration(e.getNetworkConfiguration(d)) + } + ecsLogger.Debugf("Running ad-hoc task using taskdef %s and taskoverride: %+v", taskDefinition, taskOverride) result, err := svc.RunTask(input)