github.com/defang-io/defang/src@v0.0.0-20240505002154-bdf411911834/pkg/clouds/aws/ecs/common.go (about) 1 package ecs 2 3 import ( 4 "strings" 5 6 "github.com/defang-io/defang/src/pkg/clouds/aws" 7 "github.com/defang-io/defang/src/pkg/types" 8 ) 9 10 const ( 11 ContainerName = "main" 12 DockerRegistry = "docker.io" 13 EcrPublicRegistry = "public.ecr.aws" 14 ProjectName = types.ProjectName 15 ) 16 17 type TaskArn = types.TaskID 18 19 type AwsEcs struct { 20 aws.Aws 21 BucketName string 22 ClusterName string 23 LogGroupARN string 24 SecurityGroupID string 25 Spot bool 26 SubNetID string 27 TaskDefARN string 28 VpcID string 29 } 30 31 func PlatformToArchOS(platform string) (string, string) { 32 parts := strings.SplitN(platform, "/", 3) // Can be "os/arch/variant" like "linux/arm64/v8" 33 34 if len(parts) == 1 { 35 arch := parts[0] 36 return normalizedArch(arch), "" 37 } else { 38 os := parts[0] 39 arch := parts[1] 40 os = strings.ToUpper(os) 41 return normalizedArch(arch), os 42 } 43 } 44 45 func normalizedArch(arch string) string { 46 // From https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-runtimeplatform.html#cfn-ecs-taskdefinition-runtimeplatform-cpuarchitecture 47 arch = strings.ToUpper(arch) 48 if arch == "AMD64" { 49 arch = "X86_64" 50 } 51 return arch 52 } 53 54 func (a *AwsEcs) GetVpcID() string { 55 return a.VpcID 56 } 57 58 func (a *AwsEcs) getAccountID() string { 59 return aws.GetAccountID(a.TaskDefARN) 60 } 61 62 func (a *AwsEcs) MakeARN(service, resource string) string { 63 return strings.Join([]string{ 64 "arn", 65 "aws", 66 service, 67 string(a.Region), 68 a.getAccountID(), 69 resource, 70 }, ":") 71 }