-
Notifications
You must be signed in to change notification settings - Fork 21
feat(cli): add gram redeploy command
#1721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4e3c872
feat: add Redeploy wrapper method to DeploymentsClient
simplesagar b321258
feat: add RedeployDeployment chainable workflow method
simplesagar f4c7e68
feat: add `gram redeploy` CLI command
simplesagar e06bca1
refactor: remove dead --latest flag, reuse printDeploymentStatusJSON
simplesagar 71fc688
fix(dashboard): show redeploy button on deployment detail page for fa…
simplesagar 0b2befb
fix(dashboard): make Deployments button visible on sources page with …
simplesagar 6e878c4
fix(dashboard): show redeploy button on every deployment page
simplesagar 624ef7b
fix(dashboard): fix DeploymentsButton not rendering in Page.Section slot
simplesagar b53f25d
fix(dashboard): remove unused failedDeployment hook call, add changeset
simplesagar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,132 @@ | ||
| package app | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log/slog" | ||
| "os" | ||
| "os/signal" | ||
| "syscall" | ||
|
|
||
| "github.com/speakeasy-api/gram/cli/internal/app/logging" | ||
| "github.com/speakeasy-api/gram/cli/internal/flags" | ||
| "github.com/speakeasy-api/gram/cli/internal/profile" | ||
| "github.com/speakeasy-api/gram/cli/internal/workflow" | ||
| "github.com/urfave/cli/v2" | ||
| ) | ||
|
|
||
| func newRedeployCommand() *cli.Command { | ||
| return &cli.Command{ | ||
| Name: "redeploy", | ||
| Usage: "Redeploy an existing deployment", | ||
| Description: ` | ||
| Redeploy an existing deployment by cloning it with the same assets. | ||
|
|
||
| If no deployment ID is provided, redeploys the latest deployment.`, | ||
| Flags: []cli.Flag{ | ||
| flags.APIEndpoint(), | ||
| flags.APIKey(), | ||
| flags.Project(), | ||
| flags.Org(), | ||
| &cli.StringFlag{ | ||
| Name: "id", | ||
| Usage: "The deployment ID to redeploy (if not provided, redeploys the latest deployment)", | ||
| }, | ||
| &cli.BoolFlag{ | ||
| Name: "skip-poll", | ||
| Usage: "Skip polling for deployment completion and return immediately", | ||
| Value: false, | ||
| }, | ||
| flags.JSON(), | ||
| }, | ||
| Action: func(c *cli.Context) error { | ||
| ctx, cancel := signal.NotifyContext(c.Context, os.Interrupt, syscall.SIGTERM) | ||
| defer cancel() | ||
|
|
||
| logger := logging.PullLogger(ctx) | ||
| prof := profile.FromContext(ctx) | ||
| deploymentID := c.String("id") | ||
| skipPoll := c.Bool("skip-poll") | ||
| jsonOutput := c.Bool("json") | ||
|
|
||
| workflowParams, err := workflow.ResolveParams(c, prof) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to resolve workflow params: %w", err) | ||
| } | ||
|
|
||
| wf := workflow.New(ctx, logger, workflowParams) | ||
|
|
||
| // Load the target deployment | ||
| if deploymentID != "" { | ||
| wf.LoadDeploymentByID(ctx, deploymentID) | ||
| } else { | ||
| wf.LoadLatestDeployment(ctx) | ||
| } | ||
| if wf.Failed() { | ||
| return fmt.Errorf("failed to load deployment: %w", wf.Err) | ||
| } | ||
|
|
||
| originalID := wf.Deployment.ID | ||
| logger.InfoContext(ctx, "Redeploying deployment", slog.String("deployment_id", originalID)) | ||
|
|
||
| // Trigger the redeploy | ||
| wf.RedeployDeployment(ctx) | ||
| if wf.Failed() { | ||
| return fmt.Errorf("failed to redeploy: %w", wf.Err) | ||
| } | ||
|
|
||
| newID := wf.Deployment.ID | ||
| logger.InfoContext(ctx, | ||
| "New deployment created", | ||
| slog.String("deployment_id", newID), | ||
| slog.String("cloned_from", originalID), | ||
| ) | ||
|
|
||
| // Poll for completion | ||
| if !skipPoll { | ||
| wf.Poll(ctx) | ||
| if wf.Failed() { | ||
| return fmt.Errorf("deployment polling failed: %w", wf.Err) | ||
| } | ||
| } | ||
|
|
||
| // Output result | ||
| if jsonOutput { | ||
| return printDeploymentStatusJSON(wf.Deployment) | ||
| } | ||
|
|
||
| logsURL := fmt.Sprintf("%s://%s/%s/%s/deployments/%s", | ||
| workflowParams.APIURL.Scheme, | ||
| workflowParams.APIURL.Host, | ||
| workflowParams.OrgSlug, | ||
| workflowParams.ProjectSlug, | ||
| newID, | ||
| ) | ||
|
|
||
| switch wf.Deployment.Status { | ||
| case "completed": | ||
| logger.InfoContext(ctx, "Deployment succeeded", | ||
| slog.String("deployment_id", newID), | ||
| slog.String("logs_url", logsURL), | ||
| ) | ||
| fmt.Printf("\nView deployment: %s\n", logsURL) | ||
| openDeploymentURL(logger, ctx, logsURL) | ||
| case "failed": | ||
| logger.ErrorContext(ctx, "Deployment failed", | ||
| slog.String("deployment_id", newID), | ||
| slog.String("logs_url", logsURL), | ||
| ) | ||
| fmt.Printf("\nView deployment logs: %s\n", logsURL) | ||
| openDeploymentURL(logger, ctx, logsURL) | ||
| return fmt.Errorf("deployment failed") | ||
| default: | ||
| logger.InfoContext(ctx, "Deployment is still in progress", | ||
| slog.String("deployment_id", newID), | ||
| slog.String("status", wf.Deployment.Status), | ||
| ) | ||
| fmt.Printf("\nView deployment: %s\n", logsURL) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.