forked from superfly/flyctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
launch
: add scaffolding for the new Launch command, untested
- Loading branch information
Showing
7 changed files
with
425 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package launch | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/superfly/flyctl/iostreams" | ||
"github.com/superfly/flyctl/scanner" | ||
) | ||
|
||
func familyToAppType(si *scanner.SourceInfo) string { | ||
if si == nil { | ||
return "app" | ||
} | ||
switch si.Family { | ||
case "Dockerfile": | ||
return "app" | ||
case "": | ||
return "app" | ||
} | ||
return fmt.Sprintf("%s app", si.Family) | ||
} | ||
|
||
func runUi(ctx context.Context) (err error) { | ||
|
||
io := iostreams.FromContext(ctx) | ||
|
||
// TODO: Metrics | ||
|
||
plan, srcInfo, err := v2BuildPlan(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(io.Out, "We're about to launch your %s on Fly.io. Here's what you're getting:\n\n", familyToAppType(srcInfo)) | ||
fmt.Fprintln(io.Out, plan.Summary()) | ||
|
||
confirm := false | ||
prompt := &survey.Confirm{ | ||
Message: "Do you want to tweak these settings before proceeding?", | ||
} | ||
err = survey.AskOne(prompt, &confirm) | ||
if err != nil { | ||
// TODO(allison): This should probably not just return the error | ||
return err | ||
} | ||
|
||
if confirm { | ||
plan, err = v2TweakPlan(ctx, plan) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
err = v2Launch(ctx, plan, srcInfo) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package launch | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/superfly/flyctl/scanner" | ||
) | ||
|
||
func v2Launch(ctx context.Context, plan *launchPlan, srcInfo *scanner.SourceInfo) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package launch | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/superfly/flyctl/api" | ||
) | ||
|
||
type launchPlan struct { | ||
AppName string | ||
appNameSource string | ||
|
||
Region *api.Region | ||
regionSource string | ||
|
||
Org *api.Organization | ||
orgSource string | ||
|
||
Guest *api.MachineGuest | ||
guestSource string | ||
|
||
Postgres *postgresPlan | ||
postgresSource string | ||
|
||
Redis *redisPlan | ||
redisSource string | ||
|
||
Env map[string]string | ||
} | ||
|
||
func (p *launchPlan) Summary() string { | ||
|
||
guest := p.Guest | ||
if guest == nil { | ||
guest = api.MachinePresets["shared-cpu-1x"] | ||
} | ||
|
||
rows := [][]string{ | ||
{"Organization", p.Org.Name, p.orgSource}, | ||
{"Name", p.AppName, p.appNameSource}, | ||
{"Region", p.Region.Name, p.regionSource}, | ||
{"App Machines", guest.String(), p.guestSource}, | ||
{"Postgres", p.Postgres.String(), p.postgresSource}, | ||
{"Redis", p.Redis.String(), p.redisSource}, | ||
} | ||
|
||
colLengths := []int{0, 0, 0} | ||
for _, row := range rows { | ||
for i, col := range row { | ||
if len(col) > colLengths[i] { | ||
colLengths[i] = len(col) | ||
} | ||
} | ||
} | ||
|
||
ret := "" | ||
for _, row := range rows { | ||
|
||
label := row[0] | ||
value := row[1] | ||
source := row[2] | ||
|
||
labelSpaces := strings.Repeat(" ", colLengths[0]-len(label)) | ||
valueSpaces := strings.Repeat(" ", colLengths[1]-len(value)) | ||
|
||
ret += fmt.Sprintf("%s: %s%s %s(%s)\n", label, labelSpaces, value, valueSpaces, source) | ||
} | ||
return ret | ||
} | ||
|
||
// TODO | ||
type postgresPlan struct{} | ||
|
||
func (p *postgresPlan) String() string { | ||
if p == nil { | ||
return "<none>" | ||
} | ||
return "unimplemented" | ||
} | ||
|
||
type redisPlan struct{} | ||
|
||
func (p *redisPlan) String() string { | ||
if p == nil { | ||
return "<none>" | ||
} | ||
return "unimplemented" | ||
} |
Oops, something went wrong.