Skip to content

Commit

Permalink
Option to launch without creating an app (#3726)
Browse files Browse the repository at this point in the history
If --no-create is specified, it won't create an app, won't create databases, and won't deploy.

Note: you will still be prompted if you wish to tweak your settings as any changes you make there can potentially change what outputs are generated.  Furthermore, retaining this is useful for exercising the launch UI.  This can be avoided by adding a --yes flag.
  • Loading branch information
rubys committed Jul 12, 2024
1 parent f04c9c1 commit 6a6b554
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
28 changes: 17 additions & 11 deletions internal/command/launch/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func New() (cmd *cobra.Command) {
Name: "yaml",
Description: "Generate configuration in YAML format",
},
flag.Bool{
Name: "no-create",
Description: "Do not create an app, only generate configuration files",
},
)

return
Expand Down Expand Up @@ -187,20 +191,22 @@ func run(ctx context.Context) (err error) {

var state *launchState = nil

defer func() {
if err != nil {
tracing.RecordError(span, err, "launch failed")
status.Error = err.Error()
if !flag.GetBool(ctx, "no-create") {
defer func() {
if err != nil {
tracing.RecordError(span, err, "launch failed")
status.Error = err.Error()

if state != nil && state.sourceInfo != nil && state.sourceInfo.FailureCallback != nil {
err = state.sourceInfo.FailureCallback(err)
if state != nil && state.sourceInfo != nil && state.sourceInfo.FailureCallback != nil {
err = state.sourceInfo.FailureCallback(err)
}
}
}

status.TraceID = span.SpanContext().TraceID().String()
status.Duration = time.Since(startTime)
metrics.LaunchStatus(ctx, status)
}()
status.TraceID = span.SpanContext().TraceID().String()
status.Duration = time.Since(startTime)
metrics.LaunchStatus(ctx, status)
}()
}

if err := warnLegacyBehavior(ctx); err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions internal/command/launch/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (state *launchState) firstDeploy(ctx context.Context) error {
}

// TODO(Allison): Do we want to make the executive decision to just *always* deploy?
// Feedback(Sam): scanners need the abiiity to abort the deploy if they detect a problem

deployNow := true
// deployNow := false
Expand All @@ -42,6 +43,10 @@ func (state *launchState) firstDeploy(ctx context.Context) error {
// promptForDeploy = false
}

if flag.GetBool(ctx, "no-create") {
deployNow = false
}

/*
if promptForDeploy {
confirm, err := prompt.Confirm(ctx, "Would you like to deploy now?")
Expand Down
32 changes: 19 additions & 13 deletions internal/command/launch/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,33 @@ func (state *launchState) Launch(ctx context.Context) error {
state.warnedNoCcHa = true
}

app, err := state.createApp(ctx)
if err != nil {
return err
}
if !flag.GetBool(ctx, "no-create") {
app, err := state.createApp(ctx)
if err != nil {
return err
}

fmt.Fprintf(io.Out, "Created app '%s' in organization '%s'\n", app.Name, app.Organization.Slug)
fmt.Fprintf(io.Out, "Admin URL: https://fly.io/apps/%s\n", app.Name)
fmt.Fprintf(io.Out, "Hostname: %s.fly.dev\n", app.Name)
fmt.Fprintf(io.Out, "Created app '%s' in organization '%s'\n", app.Name, app.Organization.Slug)
fmt.Fprintf(io.Out, "Admin URL: https://fly.io/apps/%s\n", app.Name)
fmt.Fprintf(io.Out, "Hostname: %s.fly.dev\n", app.Name)
}

// TODO: ideally this would be passed as a part of the plan to the Launch UI
// and allow choices of what actions are desired to be make there.
if state.sourceInfo != nil && state.sourceInfo.GitHubActions.Deploy {
state.setupGitHubActions(ctx, app.Name)
state.setupGitHubActions(ctx, state.Plan.AppName)
}

if err = state.satisfyScannerBeforeDb(ctx); err != nil {
return err
}
// TODO: Return rich info about provisioned DBs, including things
// like public URLs.
err = state.createDatabases(ctx)
if err != nil {
return err

if !flag.GetBool(ctx, "no-create") {
if err = state.createDatabases(ctx); err != nil {
return err
}
}
if err = state.satisfyScannerAfterDb(ctx); err != nil {
return err
Expand All @@ -84,8 +88,10 @@ func (state *launchState) Launch(ctx context.Context) error {
}

// Sentry
if err = state.launchSentry(ctx, app.Name); err != nil {
return err
if !flag.GetBool(ctx, "no-create") {
if err = state.launchSentry(ctx, state.Plan.AppName); err != nil {
return err
}
}

// Finally write application configuration to fly.toml
Expand Down

0 comments on commit 6a6b554

Please sign in to comment.