Skip to content

Commit d5847ca

Browse files
authored
Add closest region remapping for fly launch (#4623)
add closest region remapping for fly launch
1 parent efa6297 commit d5847ca

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

gql/generated.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gql/genqclient.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ query GetNearestRegion{
181181
code
182182
name
183183
gatewayAvailable
184+
deprecated
184185
}
185186
}
186187

internal/command/launch/plan_builder.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,48 @@ func determineOrg(ctx context.Context, config *appconfig.Config) (*fly.Organizat
690690
return &org, "specified on the command line", nil
691691
}
692692

693+
// Map of deprecated region codes and their consolidated replacements
694+
var deprecatedRegionReplacements = map[string]string{
695+
"atl": "dfw",
696+
"den": "dfw",
697+
"mia": "dfw",
698+
"gdl": "dfw",
699+
"qro": "dfw",
700+
"bos": "ewr",
701+
"phx": "lax",
702+
"sea": "sjc",
703+
"yul": "yyz",
704+
"waw": "ams",
705+
"mad": "cdg",
706+
"otp": "fra",
707+
"bog": "gru",
708+
"gig": "gru",
709+
"scl": "gru",
710+
"eze": "gru",
711+
"hkg": "sin",
712+
}
713+
714+
// Check if a region is deprecated and return the replacement region
715+
func remapDeprecatedRegion(ctx context.Context, region *fly.Region) (*fly.Region, error) {
716+
if region == nil || !region.Deprecated {
717+
return region, nil
718+
}
719+
720+
replacementCode, ok := deprecatedRegionReplacements[region.Code]
721+
if !ok {
722+
// If there's no definied replacement, return and error
723+
return nil, fmt.Errorf("region %s is deprecated. Please use a supported region.", region.Code)
724+
}
725+
726+
// Get the replacement region
727+
replacementRegion, err := getRegionByCode(ctx, replacementCode)
728+
if err != nil {
729+
return nil, fmt.Errorf("failed to get replacement region %s for deprecated region %s: %w", replacementCode, region.Code, err)
730+
}
731+
732+
return replacementRegion, nil
733+
}
734+
693735
// determineRegion returns the region to use for a new app. In order, it tries:
694736
// 1. the primary_region field of the config, if one exists
695737
// 2. the region specified on the command line, if specified
@@ -708,6 +750,15 @@ func determineRegion(ctx context.Context, config *appconfig.Config, paidPlan boo
708750
// TODO(allison): does this return paid regions for free orgs?
709751
closestRegion, closestRegionErr := client.GetNearestRegion(ctx)
710752

753+
// Remap the closest region if it's deprecated
754+
if closestRegionErr == nil && closestRegion != nil {
755+
remappedRegion, remapErr := remapDeprecatedRegion(ctx, closestRegion)
756+
if remapErr == nil {
757+
closestRegion = remappedRegion
758+
}
759+
// If remapping fails, it'll use the original region and hit the "unknown region" error
760+
}
761+
711762
if regionCode != "" {
712763
region, err := getRegionByCode(ctx, regionCode)
713764
if err != nil {

0 commit comments

Comments
 (0)