| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 | 
							- /*
 
-    Copyright 2020 Docker Compose CLI authors
 
-    Licensed under the Apache License, Version 2.0 (the "License");
 
-    you may not use this file except in compliance with the License.
 
-    You may obtain a copy of the License at
 
-        http://www.apache.org/licenses/LICENSE-2.0
 
-    Unless required by applicable law or agreed to in writing, software
 
-    distributed under the License is distributed on an "AS IS" BASIS,
 
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
-    See the License for the specific language governing permissions and
 
-    limitations under the License.
 
- */
 
- package ecs
 
- import (
 
- 	"context"
 
- 	"encoding/base64"
 
- 	"fmt"
 
- 	"github.com/awslabs/goformation/v4/cloudformation"
 
- 	"github.com/awslabs/goformation/v4/cloudformation/autoscaling"
 
- 	"github.com/awslabs/goformation/v4/cloudformation/ecs"
 
- 	"github.com/awslabs/goformation/v4/cloudformation/iam"
 
- 	"github.com/compose-spec/compose-go/types"
 
- )
 
- func (b *ecsAPIService) createCapacityProvider(ctx context.Context, project *types.Project, networks map[string]string, template *cloudformation.Template) error {
 
- 	var ec2 bool
 
- 	for _, s := range project.Services {
 
- 		if requireEC2(s) {
 
- 			ec2 = true
 
- 			break
 
- 		}
 
- 	}
 
- 	if !ec2 {
 
- 		return nil
 
- 	}
 
- 	ami, err := b.SDK.GetParameter(ctx, "/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended")
 
- 	if err != nil {
 
- 		return err
 
- 	}
 
- 	machineType := "g4dn.xlarge" // FIXME https://github.com/docker/compose-cli/pull/628
 
- 	var securityGroups []string
 
- 	for _, r := range networks {
 
- 		securityGroups = append(securityGroups, r)
 
- 	}
 
- 	template.Resources["CapacityProvider"] = &ecs.CapacityProvider{
 
- 		AutoScalingGroupProvider: &ecs.CapacityProvider_AutoScalingGroupProvider{
 
- 			AutoScalingGroupArn: cloudformation.Ref("AutoscalingGroup"),
 
- 			ManagedScaling: &ecs.CapacityProvider_ManagedScaling{
 
- 				TargetCapacity: 100,
 
- 			},
 
- 		},
 
- 		Tags:                       projectTags(project),
 
- 		AWSCloudFormationCondition: "CreateCluster",
 
- 	}
 
- 	template.Resources["AutoscalingGroup"] = &autoscaling.AutoScalingGroup{
 
- 		LaunchConfigurationName: cloudformation.Ref("LaunchConfiguration"),
 
- 		MaxSize:                 "10", //TODO
 
- 		MinSize:                 "1",
 
- 		VPCZoneIdentifier: []string{
 
- 			cloudformation.Ref(parameterSubnet1Id),
 
- 			cloudformation.Ref(parameterSubnet2Id),
 
- 		},
 
- 		AWSCloudFormationCondition: "CreateCluster",
 
- 	}
 
- 	userData := base64.StdEncoding.EncodeToString([]byte(
 
- 		fmt.Sprintf("#!/bin/bash\necho ECS_CLUSTER=%s >> /etc/ecs/ecs.config", project.Name)))
 
- 	template.Resources["LaunchConfiguration"] = &autoscaling.LaunchConfiguration{
 
- 		ImageId:                    ami,
 
- 		InstanceType:               machineType,
 
- 		SecurityGroups:             securityGroups,
 
- 		IamInstanceProfile:         cloudformation.Ref("EC2InstanceProfile"),
 
- 		UserData:                   userData,
 
- 		AWSCloudFormationCondition: "CreateCluster",
 
- 	}
 
- 	template.Resources["EC2InstanceProfile"] = &iam.InstanceProfile{
 
- 		Roles:                      []string{cloudformation.Ref("EC2InstanceRole")},
 
- 		AWSCloudFormationCondition: "CreateCluster",
 
- 	}
 
- 	template.Resources["EC2InstanceRole"] = &iam.Role{
 
- 		AssumeRolePolicyDocument: ec2InstanceAssumeRolePolicyDocument,
 
- 		ManagedPolicyArns: []string{
 
- 			ecsEC2InstanceRole,
 
- 		},
 
- 		Tags:                       projectTags(project),
 
- 		AWSCloudFormationCondition: "CreateCluster",
 
- 	}
 
- 	cluster := template.Resources["Cluster"].(*ecs.Cluster)
 
- 	cluster.CapacityProviders = []string{
 
- 		cloudformation.Ref("CapacityProvider"),
 
- 	}
 
- 	return nil
 
- }
 
 
  |