From 3f82b67fdee166c71f147249276b66c551aad276 Mon Sep 17 00:00:00 2001 From: vivansh12 Date: Thu, 25 Jun 2026 08:39:11 +0000 Subject: [PATCH] fix: remove deprecated brev recreate code implementation --- docs/CONTRIBUTING.md | 11 +- pkg/cmd/cmd.go | 2 - pkg/cmd/recreate/doc.md | 46 ------- pkg/cmd/recreate/recreate.go | 226 ----------------------------------- 4 files changed, 1 insertion(+), 284 deletions(-) delete mode 100644 pkg/cmd/recreate/doc.md delete mode 100644 pkg/cmd/recreate/recreate.go diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 62bf98726..60550f457 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -10,7 +10,7 @@ ``` VERSION=unknown -BREV_API_URL=http://localhost:8080 +BREV_API_URL=http://localhost:8080 # BREV_API_URL= ``` @@ -89,15 +89,6 @@ index a33540c..b03d5f2 100644 func hasHousekeepingCommands(cmd *cobra.Command) bool { ``` -test your function - -``` -make && ./brev recreate -``` - -add documentation by editing `pkg/cmd/recreate/doc.md`. Docs should fill out the -minimum fields: - ``` # diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index e22ed8dcd..a5ebc6db2 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -38,7 +38,6 @@ import ( "github.com/brevdev/brev-cli/pkg/cmd/portforward" "github.com/brevdev/brev-cli/pkg/cmd/profile" "github.com/brevdev/brev-cli/pkg/cmd/proxy" - "github.com/brevdev/brev-cli/pkg/cmd/recreate" "github.com/brevdev/brev-cli/pkg/cmd/redeem" "github.com/brevdev/brev-cli/pkg/cmd/refresh" "github.com/brevdev/brev-cli/pkg/cmd/register" @@ -340,7 +339,6 @@ func createCmdTree(cmd *cobra.Command, t *terminal.Terminal, loginCmdStore *stor cmd.AddCommand(healthcheck.NewCmdHealthcheck(t, noLoginCmdStore)) cmd.AddCommand(setupworkspace.NewCmdSetupWorkspace(noLoginCmdStore)) - cmd.AddCommand(recreate.NewCmdRecreate(t, loginCmdStore)) cmd.AddCommand(writeconnectionevent.NewCmdwriteConnectionEvent(t, loginCmdStore)) cmd.AddCommand(updatemodel.NewCmdupdatemodel(t, loginCmdStore)) cmd.AddCommand(feedback.NewCmdFeedback(t, noLoginCmdStore)) diff --git a/pkg/cmd/recreate/doc.md b/pkg/cmd/recreate/doc.md deleted file mode 100644 index da481181c..000000000 --- a/pkg/cmd/recreate/doc.md +++ /dev/null @@ -1,46 +0,0 @@ -# Re Create Workspace by name or ID. - -## SYNOPSIS - -``` - brev recreate [ Workspace Name or ID... ] -``` - -## DESCRIPTION - -recreate a workspace is equivalent to running the following commands: - -``` -brev delete payments-fronted -brev start payments-frontend -``` - -This command has the effect of updating the base image of a workspace to the -latest. If your workspace has a git remote source, the workspace will start -with a fresh copy of the remote source and run the workspace setupscript. - -## EXAMPLE - -recreate a workspace with the name `naive-pubsub` - -``` -$ brev recreate naive-pubsub -recreating 🤙 This can take a couple of minutes. - -Deleting instance - naive-pubsub. -Instance is starting. This can take up to 2 minutes the first time. -name naive-pubsub -template v7nd45zsc Admin -resource class 4x16 -workspace group brev-test-brevtenant-cluster -You can safely ctrl+c to exit -⢿ workspace is deploying -Your workspace is ready! - -SSH into your machine: - ssh naive-pubsub-uq0x -``` - -## SEE ALSO - - TODO diff --git a/pkg/cmd/recreate/recreate.go b/pkg/cmd/recreate/recreate.go deleted file mode 100644 index 64ab1ce08..000000000 --- a/pkg/cmd/recreate/recreate.go +++ /dev/null @@ -1,226 +0,0 @@ -// Package recreate is for the recreate command -package recreate - -import ( - _ "embed" - "strings" - "time" - - "github.com/spf13/cobra" - - "github.com/brevdev/brev-cli/pkg/cmd/completions" - "github.com/brevdev/brev-cli/pkg/cmd/util" - "github.com/brevdev/brev-cli/pkg/config" - "github.com/brevdev/brev-cli/pkg/entity" - breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/brevdev/brev-cli/pkg/featureflag" - "github.com/brevdev/brev-cli/pkg/store" - "github.com/brevdev/brev-cli/pkg/terminal" - stripmd "github.com/writeas/go-strip-markdown" -) - -//go:embed doc.md -var long string - -type recreateStore interface { - completions.CompletionStore - util.GetWorkspaceByNameOrIDErrStore - ResetWorkspace(workspaceID string) (*entity.Workspace, error) - GetActiveOrganizationOrDefault() (*entity.Organization, error) - GetCurrentUser() (*entity.User, error) - CreateWorkspace(organizationID string, options *store.CreateWorkspacesOptions) (*entity.Workspace, error) - GetWorkspace(id string) (*entity.Workspace, error) - DeleteWorkspace(workspaceID string) (*entity.Workspace, error) -} - -func NewCmdRecreate(t *terminal.Terminal, store recreateStore) *cobra.Command { - cmd := &cobra.Command{ - Use: "recreate", - DisableFlagsInUseLine: true, - Short: "TODO", - Long: stripmd.Strip(long), - Example: "TODO", - RunE: func(cmd *cobra.Command, args []string) error { - err := RunRecreate(t, args, store) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil - }, - } - return cmd -} - -func RunRecreate(t *terminal.Terminal, args []string, recreateStore recreateStore) error { - for _, arg := range args { - err := recreateProcess(arg, t, recreateStore) - if err != nil { - return breverrors.WrapAndTrace(err) - } - } - return nil -} - -// recreateProcess deletes an existing workspace and creates a new one -func recreateProcess(workspaceName string, t *terminal.Terminal, recreateStore recreateStore) error { - t.Vprint(t.Green("recreating 🤙 " + t.Yellow("This can take a couple of minutes.\n"))) - workspace, err := util.GetUserWorkspaceByNameOrIDErr(recreateStore, workspaceName) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - deletedWorkspace, err := recreateStore.DeleteWorkspace(workspace.ID) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - t.Vprint(t.Yellow("Deleting instance - %s.", deletedWorkspace.Name)) - time.Sleep(10 * time.Second) - - if len(deletedWorkspace.GitRepo) != 0 { - err := createWorkspaceFromRepo(t, recreateStore, deletedWorkspace) - if err != nil { - return breverrors.WrapAndTrace(err) - } - } else { - err := createEmptyWorkspace(t, recreateStore, deletedWorkspace) - if err != nil { - return breverrors.WrapAndTrace(err) - } - } - return nil -} - -// createWorkspaceFromRepo recreates a workspace from its git repo source. -func createWorkspaceFromRepo(t *terminal.Terminal, recreateStore recreateStore, workspace *entity.Workspace) error { - t.Vprint(t.Green("Instance is starting. ") + t.Yellow("This can take up to 2 minutes the first time.")) - var orgID string - activeorg, err := recreateStore.GetActiveOrganizationOrDefault() - if err != nil { - return breverrors.WrapAndTrace(err) - } - if activeorg == nil { - return breverrors.NewValidationError("no org exist") - } - orgID = activeorg.ID - clusterID := config.GlobalConfig.GetDefaultClusterID() - options := store.NewCreateWorkspacesOptions(clusterID, workspace.Name).WithGitRepo(workspace.GitRepo) - - user, err := recreateStore.GetCurrentUser() - if err != nil { - return breverrors.WrapAndTrace(err) - } - - options = resolveWorkspaceUserOptions(options, user) - - options.StartupScriptPath = workspace.StartupScriptPath - options.Execs = workspace.ExecsV0 - options.Repos = workspace.ReposV0 - options.IDEConfig = &workspace.IDEConfig - - w, err := recreateStore.CreateWorkspace(orgID, options) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - err = pollUntil(t, w.ID, entity.Running, recreateStore, true) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - t.Vprint(t.Green("\nYour instance is ready!")) - t.Vprintf("%s", t.Green("\nSSH into your machine:\n\tssh %s\n", w.GetLocalIdentifier())) - return nil -} - -// createEmptyWorkspace recreates an empty workspace (no git repo). -func createEmptyWorkspace(t *terminal.Terminal, recreateStore recreateStore, workspace *entity.Workspace) error { - t.Vprint(t.Green("Instance is starting. ") + t.Yellow("This can take up to 2 minutes the first time.\n")) - - // ensure name - if len(workspace.Name) == 0 { - return breverrors.NewValidationError("name field is required for empty instances") - } - - // ensure org - var orgID string - activeorg, err := recreateStore.GetActiveOrganizationOrDefault() - if err != nil { - return breverrors.WrapAndTrace(err) - } - if activeorg == nil { - return breverrors.NewValidationError("no org exist") - } - orgID = activeorg.ID - clusterID := config.GlobalConfig.GetDefaultClusterID() - options := store.NewCreateWorkspacesOptions(clusterID, workspace.Name) - - user, err := recreateStore.GetCurrentUser() - if err != nil { - return breverrors.WrapAndTrace(err) - } - - options = resolveWorkspaceUserOptions(options, user) - - options.StartupScriptPath = workspace.StartupScriptPath - options.Execs = workspace.ExecsV0 - options.Repos = workspace.ReposV0 - options.IDEConfig = &workspace.IDEConfig - - w, err := recreateStore.CreateWorkspace(orgID, options) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - err = pollUntil(t, w.ID, entity.Running, recreateStore, true) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - t.Vprint(t.Green("\nYour instance is ready!")) - t.Vprintf("%s", t.Green("\nSSH into your machine:\n\tssh %s\n", w.GetLocalIdentifier())) - - return nil -} - -func pollUntil(t *terminal.Terminal, wsid string, state string, recreateStore recreateStore, canSafelyExit bool) error { - s := t.NewSpinner() - isReady := false - if canSafelyExit { - t.Vprintf("You can safely ctrl+c to exit\n") - } - s.Suffix = " hang tight 🤙" - s.Start() - for !isReady { - time.Sleep(5 * time.Second) - ws, err := recreateStore.GetWorkspace(wsid) - if err != nil { - return breverrors.WrapAndTrace(err) - } - s.Suffix = " instance is " + strings.ToLower(ws.Status) - if ws.Status == state { - s.Suffix = "Instance is ready!" - s.Stop() - isReady = true - } - } - return nil -} - -func resolveWorkspaceUserOptions(options *store.CreateWorkspacesOptions, user *entity.User) *store.CreateWorkspacesOptions { - if options.WorkspaceTemplateID == "" { - if featureflag.IsAdmin(user.GlobalUserType) { - options.WorkspaceTemplateID = store.DevWorkspaceTemplateID - } else { - options.WorkspaceTemplateID = store.UserWorkspaceTemplateID - } - } - if options.WorkspaceClassID == "" { - if featureflag.IsAdmin(user.GlobalUserType) { - options.WorkspaceClassID = store.DevWorkspaceClassID - } else { - options.WorkspaceClassID = store.UserWorkspaceClassID - } - } - return options -}