Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/build/imgsrc/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/superfly/flyctl/internal/metrics"
"github.com/superfly/flyctl/internal/sentry"
"github.com/superfly/flyctl/internal/tracing"
"github.com/superfly/flyctl/internal/uiex"
"github.com/superfly/flyctl/internal/uiexutil"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/terminal"
Expand Down Expand Up @@ -780,13 +781,13 @@ func ResolveDockerfile(cwd string) string {
return ""
}

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

provisioner := NewProvisioner(org)
provisioner := NewProvisionerUiexOrg(org)
_, app, err := provisioner.EnsureBuilder(ctx, os.Getenv("FLY_REMOTE_BUILDER_REGION"), recreateBuilder)
if err != nil {
terminal.Debugf("error ensuring remote builder for organization: %s", err)
Expand Down
15 changes: 3 additions & 12 deletions internal/build/imgsrc/ensure_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,19 @@ import (
type Provisioner struct {
orgID string
orgSlug string
orgTrial bool
orgPaidPlan bool
orgRemoteBuilderImage string
useVolume bool
buildkitAddr string
buildkitImage string
}

// NewProvisioner is deprecated and will be replaced by NewProvisionerUiexOrg
func NewProvisioner(org *fly.Organization) *Provisioner {
return &Provisioner{
orgID: org.ID,
orgSlug: org.Slug,
orgPaidPlan: org.PaidPlan,
orgRemoteBuilderImage: org.RemoteBuilderImage,
useVolume: true,
}
}

func NewProvisionerUiexOrg(org *uiex.Organization) *Provisioner {
return &Provisioner{
orgID: org.ID,
orgSlug: org.Slug,
orgTrial: org.BillingStatus == uiex.BillingStatusTrialActive,
orgPaidPlan: org.PaidPlan,
orgRemoteBuilderImage: org.RemoteBuilderImage,
useVolume: true,
Expand Down Expand Up @@ -397,7 +388,7 @@ func (p *Provisioner) createBuilder(ctx context.Context, region, builderName str
CPUs: 4,
MemoryMB: 4096,
}
if p.orgPaidPlan {
if p.orgPaidPlan && !p.orgTrial {
guest = fly.MachineGuest{
CPUKind: "shared",
CPUs: 8,
Expand Down
11 changes: 6 additions & 5 deletions internal/build/imgsrc/ensure_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/superfly/flyctl/internal/flyutil"
"github.com/superfly/flyctl/internal/mock"
"github.com/superfly/flyctl/internal/state"
"github.com/superfly/flyctl/internal/uiex"
"go.uber.org/mock/gomock"
)

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

func TestValidateBuilder(t *testing.T) {
ctx := testingContext(t)
p := NewProvisioner(&fly.Organization{})
p := NewProvisionerUiexOrg(&uiex.Organization{})

hasVolumes := false
hasMachines := false
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestValidateBuilder(t *testing.T) {

func TestValidateBuilderAPIErrors(t *testing.T) {
ctx := testingContext(t)
p := NewProvisioner(&fly.Organization{})
p := NewProvisionerUiexOrg(&uiex.Organization{})

maxVolumeRetries := 3
volumeRetries := 0
Expand Down Expand Up @@ -166,7 +167,7 @@ func TestValidateBuilderNotStarted(t *testing.T) {
ctx := testingContext(t)
ctx = flapsutil.NewContextWithClient(ctx, client)

provisioner := NewProvisioner(&fly.Organization{})
provisioner := NewProvisionerUiexOrg(&uiex.Organization{})
provisioner.useVolume = false

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

func TestCreateBuilder(t *testing.T) {
ctx := testingContext(t)
org := &fly.Organization{
org := &uiex.Organization{
Slug: "bigorg",
}
p := NewProvisioner(org)
p := NewProvisionerUiexOrg(org)

createAppShouldFail := false
allocateIPAddressShouldFail := false
Expand Down
11 changes: 7 additions & 4 deletions internal/command/command_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/superfly/flyctl/internal/flyutil"
"github.com/superfly/flyctl/internal/launchdarkly"
"github.com/superfly/flyctl/internal/state"
"github.com/superfly/flyctl/internal/uiexutil"
)

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

appCompact, err := client.GetAppCompact(ctx, appName)
flapsClient := flapsutil.ClientFromContext(ctx)
app, err := flapsClient.GetApp(ctx, appName)
if err != nil {
return nil, err
}

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

org, err := client.GetOrganizationByApp(ctx, appName)
uiexClient := uiexutil.ClientFromContext(ctx)
org, err := uiexClient.GetOrganization(ctx, app.Organization.Slug)
if err != nil {
return nil, err
}
Expand All @@ -64,7 +67,7 @@ func DetermineImage(ctx context.Context, appName string, imageOrPath string) (im
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)
resolver := imgsrc.NewResolver(
daemonType, client, appName, io, flag.GetWireguard(ctx), false,
imgsrc.WithProvisioner(imgsrc.NewProvisioner(org)),
imgsrc.WithProvisioner(imgsrc.NewProvisionerUiexOrg(org)),
)

// build if relative or absolute path
Expand Down
11 changes: 5 additions & 6 deletions internal/command/launch/plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/superfly/flyctl/internal/haikunator"
"github.com/superfly/flyctl/internal/launchdarkly"
"github.com/superfly/flyctl/internal/prompt"
"github.com/superfly/flyctl/internal/uiexutil"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/scanner"
)
Expand Down Expand Up @@ -325,20 +326,18 @@ func nudgeTowardsDeploy(ctx context.Context, appName string) (bool, error) {
}

func stateFromManifest(ctx context.Context, m LaunchManifest, optionalCache *planBuildCache, recoverableErrors *recoverableErrorBuilder) (*launchState, error) {
var (
io = iostreams.FromContext(ctx)
client = flyutil.ClientFromContext(ctx)
)
io := iostreams.FromContext(ctx)

org, err := client.GetOrganizationRemoteBuilderBySlug(ctx, m.Plan.OrgSlug)
uiexClient := uiexutil.ClientFromContext(ctx)
org, err := uiexClient.GetOrganization(ctx, m.Plan.OrgSlug)
if err != nil {
return nil, err
}

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

var (
Expand Down
Loading