github.com/defang-io/defang/src@v0.0.0-20240505002154-bdf411911834/pkg/cmd/factory.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/defang-io/defang/src/pkg/clouds/aws/ecs/cfn" 8 "github.com/defang-io/defang/src/pkg/clouds/aws/region" 9 "github.com/defang-io/defang/src/pkg/docker" 10 "github.com/defang-io/defang/src/pkg/types" 11 ) 12 13 var currentUser = os.Getenv("USER") 14 15 type DriverOption func(types.Driver) error 16 17 func createDriver(reg Region, opts ...DriverOption) (types.Driver, error) { 18 var driver types.Driver 19 switch reg { 20 case "docker", "local", "": 21 driver = docker.New() 22 case 23 region.AFSouth1, // "af-south-1" 24 region.APEast1, // "ap-east-1" 25 region.APNortheast1, // "ap-northeast-1" 26 region.APNortheast2, // "ap-northeast-2" 27 region.APNortheast3, // "ap-northeast-3" 28 region.APSouth1, // "ap-south-1" 29 region.APSouth2, // "ap-south-2" 30 region.APSoutheast1, // "ap-southeast-1" 31 region.APSoutheast2, // "ap-southeast-2" 32 region.APSoutheast3, // "ap-southeast-3" 33 region.APSoutheast4, // "ap-southeast-4" 34 region.CACentral, // "ca-central-1" 35 region.CNNorth1, // "cn-north-1" 36 region.CNNorthwest1, // "cn-northwest-1" 37 region.EUCentral1, // "eu-central-1" 38 region.EUCentral2, // "eu-central-2" 39 region.EUNorth1, // "eu-north-1" 40 region.EUSouth1, // "eu-south-1" 41 region.EUSouth2, // "eu-south-2" 42 region.EUWest1, // "eu-west-1" 43 region.EUWest2, // "eu-west-2" 44 region.EUWest3, // "eu-west-3" 45 region.MECentral1, // "me-central-1" 46 region.MESouth1, // "me-south-1" 47 region.SAEast1, // "sa-east-1" 48 region.USGovEast1, // "us-gov-east-1" 49 region.USGovWest1, // "us-gov-west-1" 50 region.USEast1, // "us-east-1" 51 region.USEast2, // "us-east-2" 52 region.USWest1, // "us-west-1" 53 region.USWest2: // "us-west-2" 54 driver = cfn.New(stackName(currentUser), reg) 55 default: 56 return nil, fmt.Errorf("unsupported region: %v", reg) 57 } 58 59 for _, opt := range opts { 60 if err := opt(driver); err != nil { 61 return nil, err 62 } 63 } 64 65 return driver, nil 66 } 67 68 func stackName(stack string) string { 69 if stack == "" { 70 return types.ProjectName 71 } 72 return types.ProjectName + "-" + stack 73 }