Skip to content

Commit 7f0ff1f

Browse files
authored
Use smaller builder machine when trial is active (#4725)
* Remove GraphQL from machines run command * Use smaller builder machine when trial is active Currently, trial users are unable to use Fly-managed builders as the default machine configuration exceeds their max allowed size. flyctl previously used a smaller builder for free users, but this was never updated after the removal of plans.
1 parent f58ce93 commit 7f0ff1f

File tree

5 files changed

+24
-29
lines changed

5 files changed

+24
-29
lines changed

internal/build/imgsrc/docker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/superfly/flyctl/internal/metrics"
3939
"github.com/superfly/flyctl/internal/sentry"
4040
"github.com/superfly/flyctl/internal/tracing"
41+
"github.com/superfly/flyctl/internal/uiex"
4142
"github.com/superfly/flyctl/internal/uiexutil"
4243
"github.com/superfly/flyctl/iostreams"
4344
"github.com/superfly/flyctl/terminal"
@@ -780,13 +781,13 @@ func ResolveDockerfile(cwd string) string {
780781
return ""
781782
}
782783

783-
func EagerlyEnsureRemoteBuilder(ctx context.Context, apiClient flyutil.Client, org *fly.Organization, recreateBuilder bool) {
784+
func EagerlyEnsureRemoteBuilder(ctx context.Context, org *uiex.Organization, recreateBuilder bool) {
784785
// skip if local docker is available
785786
if _, err := NewLocalDockerClient(); err == nil {
786787
return
787788
}
788789

789-
provisioner := NewProvisioner(org)
790+
provisioner := NewProvisionerUiexOrg(org)
790791
_, app, err := provisioner.EnsureBuilder(ctx, os.Getenv("FLY_REMOTE_BUILDER_REGION"), recreateBuilder)
791792
if err != nil {
792793
terminal.Debugf("error ensuring remote builder for organization: %s", err)

internal/build/imgsrc/ensure_builder.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,19 @@ import (
2323
type Provisioner struct {
2424
orgID string
2525
orgSlug string
26+
orgTrial bool
2627
orgPaidPlan bool
2728
orgRemoteBuilderImage string
2829
useVolume bool
2930
buildkitAddr string
3031
buildkitImage string
3132
}
3233

33-
// NewProvisioner is deprecated and will be replaced by NewProvisionerUiexOrg
34-
func NewProvisioner(org *fly.Organization) *Provisioner {
35-
return &Provisioner{
36-
orgID: org.ID,
37-
orgSlug: org.Slug,
38-
orgPaidPlan: org.PaidPlan,
39-
orgRemoteBuilderImage: org.RemoteBuilderImage,
40-
useVolume: true,
41-
}
42-
}
43-
4434
func NewProvisionerUiexOrg(org *uiex.Organization) *Provisioner {
4535
return &Provisioner{
4636
orgID: org.ID,
4737
orgSlug: org.Slug,
38+
orgTrial: org.BillingStatus == uiex.BillingStatusTrialActive,
4839
orgPaidPlan: org.PaidPlan,
4940
orgRemoteBuilderImage: org.RemoteBuilderImage,
5041
useVolume: true,
@@ -397,7 +388,7 @@ func (p *Provisioner) createBuilder(ctx context.Context, region, builderName str
397388
CPUs: 4,
398389
MemoryMB: 4096,
399390
}
400-
if p.orgPaidPlan {
391+
if p.orgPaidPlan && !p.orgTrial {
401392
guest = fly.MachineGuest{
402393
CPUKind: "shared",
403394
CPUs: 8,

internal/build/imgsrc/ensure_builder_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/superfly/flyctl/internal/flyutil"
1515
"github.com/superfly/flyctl/internal/mock"
1616
"github.com/superfly/flyctl/internal/state"
17+
"github.com/superfly/flyctl/internal/uiex"
1718
"go.uber.org/mock/gomock"
1819
)
1920

@@ -27,7 +28,7 @@ func testingContext(t *testing.T) context.Context {
2728

2829
func TestValidateBuilder(t *testing.T) {
2930
ctx := testingContext(t)
30-
p := NewProvisioner(&fly.Organization{})
31+
p := NewProvisionerUiexOrg(&uiex.Organization{})
3132

3233
hasVolumes := false
3334
hasMachines := false
@@ -71,7 +72,7 @@ func TestValidateBuilder(t *testing.T) {
7172

7273
func TestValidateBuilderAPIErrors(t *testing.T) {
7374
ctx := testingContext(t)
74-
p := NewProvisioner(&fly.Organization{})
75+
p := NewProvisionerUiexOrg(&uiex.Organization{})
7576

7677
maxVolumeRetries := 3
7778
volumeRetries := 0
@@ -166,7 +167,7 @@ func TestValidateBuilderNotStarted(t *testing.T) {
166167
ctx := testingContext(t)
167168
ctx = flapsutil.NewContextWithClient(ctx, client)
168169

169-
provisioner := NewProvisioner(&fly.Organization{})
170+
provisioner := NewProvisionerUiexOrg(&uiex.Organization{})
170171
provisioner.useVolume = false
171172

172173
client.EXPECT().List(gomock.Any(), gomock.Eq(""), gomock.Any()).Return([]*fly.Machine{
@@ -179,10 +180,10 @@ func TestValidateBuilderNotStarted(t *testing.T) {
179180

180181
func TestCreateBuilder(t *testing.T) {
181182
ctx := testingContext(t)
182-
org := &fly.Organization{
183+
org := &uiex.Organization{
183184
Slug: "bigorg",
184185
}
185-
p := NewProvisioner(org)
186+
p := NewProvisionerUiexOrg(org)
186187

187188
createAppShouldFail := false
188189
allocateIPAddressShouldFail := false

internal/command/command_run.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/superfly/flyctl/internal/flyutil"
2929
"github.com/superfly/flyctl/internal/launchdarkly"
3030
"github.com/superfly/flyctl/internal/state"
31+
"github.com/superfly/flyctl/internal/uiexutil"
3132
)
3233

3334
func DetermineImage(ctx context.Context, appName string, imageOrPath string) (img *imgsrc.DeploymentImage, err error) {
@@ -37,15 +38,16 @@ func DetermineImage(ctx context.Context, appName string, imageOrPath string) (im
3738
cfg = appconfig.ConfigFromContext(ctx)
3839
)
3940

40-
appCompact, err := client.GetAppCompact(ctx, appName)
41+
flapsClient := flapsutil.ClientFromContext(ctx)
42+
app, err := flapsClient.GetApp(ctx, appName)
4143
if err != nil {
4244
return nil, err
4345
}
4446

4547
// Start the feature flag client, if we haven't already
4648
if launchdarkly.ClientFromContext(ctx) == nil {
4749
ffClient, err := launchdarkly.NewClient(ctx, launchdarkly.UserInfo{
48-
OrganizationID: appCompact.Organization.InternalNumericID,
50+
OrganizationID: fmt.Sprint(app.Organization.InternalNumericID),
4951
UserID: 0,
5052
})
5153
if err != nil {
@@ -54,7 +56,8 @@ func DetermineImage(ctx context.Context, appName string, imageOrPath string) (im
5456
ctx = launchdarkly.NewContextWithClient(ctx, ffClient)
5557
}
5658

57-
org, err := client.GetOrganizationByApp(ctx, appName)
59+
uiexClient := uiexutil.ClientFromContext(ctx)
60+
org, err := uiexClient.GetOrganization(ctx, app.Organization.Slug)
5861
if err != nil {
5962
return nil, err
6063
}
@@ -64,7 +67,7 @@ func DetermineImage(ctx context.Context, appName string, imageOrPath string) (im
6467
daemonType := imgsrc.NewDockerDaemonType(!flag.GetBool(ctx, "build-remote-only"), !flag.GetBool(ctx, "build-local-only"), env.IsCI(), flag.GetBool(ctx, "build-depot"), flag.GetBool(ctx, "build-nixpacks"), useManagedBuilder)
6568
resolver := imgsrc.NewResolver(
6669
daemonType, client, appName, io, flag.GetWireguard(ctx), false,
67-
imgsrc.WithProvisioner(imgsrc.NewProvisioner(org)),
70+
imgsrc.WithProvisioner(imgsrc.NewProvisionerUiexOrg(org)),
6871
)
6972

7073
// build if relative or absolute path

internal/command/launch/plan_builder.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/superfly/flyctl/internal/haikunator"
2626
"github.com/superfly/flyctl/internal/launchdarkly"
2727
"github.com/superfly/flyctl/internal/prompt"
28+
"github.com/superfly/flyctl/internal/uiexutil"
2829
"github.com/superfly/flyctl/iostreams"
2930
"github.com/superfly/flyctl/scanner"
3031
)
@@ -325,20 +326,18 @@ func nudgeTowardsDeploy(ctx context.Context, appName string) (bool, error) {
325326
}
326327

327328
func stateFromManifest(ctx context.Context, m LaunchManifest, optionalCache *planBuildCache, recoverableErrors *recoverableErrorBuilder) (*launchState, error) {
328-
var (
329-
io = iostreams.FromContext(ctx)
330-
client = flyutil.ClientFromContext(ctx)
331-
)
329+
io := iostreams.FromContext(ctx)
332330

333-
org, err := client.GetOrganizationRemoteBuilderBySlug(ctx, m.Plan.OrgSlug)
331+
uiexClient := uiexutil.ClientFromContext(ctx)
332+
org, err := uiexClient.GetOrganization(ctx, m.Plan.OrgSlug)
334333
if err != nil {
335334
return nil, err
336335
}
337336

338337
// If we potentially are deploying, launch a remote builder to prepare for deployment.
339338
if !flag.GetBool(ctx, "no-deploy") {
340339
// TODO: determine if eager remote builder is still required here
341-
go imgsrc.EagerlyEnsureRemoteBuilder(ctx, client, org, flag.GetRecreateBuilder(ctx))
340+
go imgsrc.EagerlyEnsureRemoteBuilder(ctx, org, flag.GetRecreateBuilder(ctx))
342341
}
343342

344343
var (

0 commit comments

Comments
 (0)