-
Notifications
You must be signed in to change notification settings - Fork 0
feat(deployServer): add commands, cli, and sdk #86
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
Open
Dav-14
wants to merge
13
commits into
main
Choose a base branch
from
feat/add_deploy_server_client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5dc44a5
feat: add speakeasy client generator
Dav-14 ce94b39
feat: add deploy server client
Dav-14 6aac73b
feat: update client
Dav-14 fcc7414
feat: add apps crud
Dav-14 f3a8526
feat: add runs read, list
Dav-14 1f82714
feat(runs): retrieve logs
Dav-14 290d5b8
feat(apps): display state
Dav-14 f8fc7e2
feat(versions): add read archive, manifest and versions metadata
Dav-14 acf00e0
feat(variables): add list, create, delete
Dav-14 ab7d015
feat(deploy): add waitflag display the proper state
Dav-14 35f70de
fix: json output on manifets command
Dav-14 d2eff0f
wip: return err
Dav-14 6ade4f5
wip: deploy by default
Dav-14 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
Some comments aren't visible on the classic Files Changed page.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package apps | ||
|
||
import ( | ||
"github.com/formancehq/fctl/internal/deployserverclient/models/components" | ||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type Create struct { | ||
components.App | ||
} | ||
|
||
type CreateCtrl struct { | ||
store *Create | ||
} | ||
|
||
var _ fctl.Controller[*Create] = (*CreateCtrl)(nil) | ||
|
||
func newCreateStore() *Create { | ||
return &Create{ | ||
App: components.App{}, | ||
} | ||
} | ||
|
||
func NewCreateCtrl() *CreateCtrl { | ||
return &CreateCtrl{ | ||
store: newCreateStore(), | ||
} | ||
} | ||
|
||
func NewCreate() *cobra.Command { | ||
return fctl.NewCommand("create", | ||
fctl.WithShortDescription("Create apps"), | ||
fctl.WithController(NewCreateCtrl()), | ||
) | ||
} | ||
|
||
func (c *CreateCtrl) GetStore() *Create { | ||
return c.store | ||
} | ||
|
||
func (c *CreateCtrl) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { | ||
cfg, err := fctl.GetConfig(cmd) | ||
membershipStore := fctl.GetMembershipStore(cmd.Context()) | ||
organizationID, err := fctl.ResolveOrganizationID(cmd, cfg, membershipStore.Client()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
store := fctl.GetDeployServerStore(cmd.Context()) | ||
Dav-14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
apps, err := store.Cli.CreateApp(cmd.Context(), components.CreateAppRequest{ | ||
Dav-14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
OrganizationID: organizationID, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c.store.App = apps.AppResponse.Data | ||
|
||
return c, nil | ||
} | ||
|
||
func (c *CreateCtrl) Render(cmd *cobra.Command, args []string) error { | ||
if err := pterm. | ||
DefaultTable. | ||
WithHasHeader(). | ||
WithData([][]string{ | ||
{"ID", "Name"}, | ||
{c.store.App.ID, c.store.App.Name}, | ||
}). | ||
Render(); err != nil { | ||
return err | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package apps | ||
|
||
import ( | ||
"fmt" | ||
|
||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type Delete struct { | ||
ID string | ||
} | ||
|
||
type DeleteCtrl struct { | ||
store *Delete | ||
} | ||
|
||
var _ fctl.Controller[*Delete] = (*DeleteCtrl)(nil) | ||
|
||
func newDeleteStore() *Delete { | ||
return &Delete{} | ||
} | ||
|
||
func NewDeleteCtrl() *DeleteCtrl { | ||
return &DeleteCtrl{ | ||
store: newDeleteStore(), | ||
} | ||
} | ||
|
||
func NewDelete() *cobra.Command { | ||
return fctl.NewCommand("delete", | ||
fctl.WithShortDescription("Delete apps"), | ||
fctl.WithStringFlag("id", "", "App ID"), | ||
fctl.WithController(NewDeleteCtrl()), | ||
) | ||
} | ||
|
||
func (c *DeleteCtrl) GetStore() *Delete { | ||
return c.store | ||
} | ||
|
||
func (c *DeleteCtrl) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { | ||
store := fctl.GetDeployServerStore(cmd.Context()) | ||
id := fctl.GetString(cmd, "id") | ||
if id == "" { | ||
return nil, fmt.Errorf("id is required") | ||
} | ||
_, err := store.Cli.DeleteApp(cmd.Context(), id) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c.store.ID = id | ||
|
||
return c, nil | ||
} | ||
|
||
func (c *DeleteCtrl) Render(cmd *cobra.Command, args []string) error { | ||
pterm.Success.Println("App deleted", c.store.ID) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package apps | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/formancehq/fctl/cmd/cloud/apps/printer" | ||
"github.com/formancehq/fctl/internal/deployserverclient/models/components" | ||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type Deploy struct { | ||
*components.Run | ||
} | ||
|
||
type DeployCtrl struct { | ||
store *Deploy | ||
} | ||
|
||
var _ fctl.Controller[*Deploy] = (*DeployCtrl)(nil) | ||
|
||
func newDeployStore() *Deploy { | ||
return &Deploy{} | ||
} | ||
|
||
func NewDeployCtrl() *DeployCtrl { | ||
return &DeployCtrl{ | ||
store: newDeployStore(), | ||
} | ||
} | ||
|
||
const ( | ||
IdFlag = "id" | ||
PathFlag = "path" | ||
) | ||
|
||
func NewDeploy() *cobra.Command { | ||
return fctl.NewCommand("deploy", | ||
fctl.WithShortDescription("Deploy apps"), | ||
fctl.WithStringFlag("id", "", "App ID"), | ||
fctl.WithStringFlag("path", "", "Path to the manifest file"), | ||
fctl.WithBoolFlag("wait", true, "Wait for the deployment to complete"), | ||
fctl.WithController(NewDeployCtrl()), | ||
) | ||
} | ||
|
||
func (c *DeployCtrl) GetStore() *Deploy { | ||
return c.store | ||
} | ||
|
||
func (c *DeployCtrl) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { | ||
store := fctl.GetDeployServerStore(cmd.Context()) | ||
id := fctl.GetString(cmd, "id") | ||
if id == "" { | ||
return nil, fmt.Errorf("id is required") | ||
} | ||
path := fctl.GetString(cmd, "path") | ||
if path == "" { | ||
return nil, fmt.Errorf("path is required") | ||
} | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cmd.SilenceUsage = true | ||
deployment, err := store.Cli.DeployAppConfigurationRaw(cmd.Context(), id, data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
c.store.Run = &deployment.RunResponse.Data | ||
return c, nil | ||
} | ||
|
||
func (c *DeployCtrl) waitRunCompletion(cmd *cobra.Command) error { | ||
store := fctl.GetDeployServerStore(cmd.Context()) | ||
s, err := pterm.DefaultSpinner.Start("Waiting for deployment to complete...") | ||
if err != nil { | ||
return err | ||
} | ||
defer s.Stop() | ||
for { | ||
select { | ||
case <-cmd.Context().Done(): | ||
return cmd.Context().Err() | ||
case <-time.After(2 * time.Second): | ||
r, err := store.Cli.ReadRun(cmd.Context(), c.store.ID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s.InfoPrinter.Printf("\033[1A\033[K") | ||
s.InfoPrinter.Printfln("Deployment status: %s", r.RunResponse.Data.Status) | ||
switch r.RunResponse.Data.Status { | ||
case "applied": | ||
s.Success("Deployment completed successfully") | ||
return nil | ||
case "planned_and_finished": | ||
s.Success("Deployment completed successfully, no changes to apply") | ||
return nil | ||
case "errored": // TOFix: change it to show pro | ||
l, err := store.Cli.ReadRunLogs(cmd.Context(), c.store.ID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := printer.RenderLogs(cmd.ErrOrStderr(), l.ReadLogsResponse.Data); err != nil { | ||
return err | ||
} | ||
return fmt.Errorf("deployment failed: %s", c.store.ID) | ||
default: | ||
continue | ||
} | ||
} | ||
Dav-14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
func (c *DeployCtrl) Render(cmd *cobra.Command, args []string) error { | ||
pterm.Info.Println("App Deployment accepted", c.store.ID) | ||
wait := fctl.GetBool(cmd, "wait") | ||
if !wait { | ||
return nil | ||
} | ||
if err := c.waitRunCompletion(cmd); err != nil { | ||
return err | ||
} | ||
|
||
store := fctl.GetDeployServerStore(cmd.Context()) | ||
id := fctl.GetString(cmd, "id") | ||
currentStateRes, err := store.Cli.ReadAppCurrentStateVersion(cmd.Context(), id) | ||
if err != nil { | ||
return err | ||
} | ||
if state := currentStateRes.GetReadStateResponse().Data.Stack; state != nil { | ||
cfg, err := fctl.GetConfig(cmd) | ||
membershipStore := fctl.GetMembershipStore(cmd.Context()) | ||
organizationID, err := fctl.ResolveOrganizationID(cmd, cfg, membershipStore.Client()) | ||
if err != nil { | ||
return nil | ||
} | ||
info, _, err := membershipStore.Client().GetServerInfo(cmd.Context()).Execute() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if info.ConsoleURL != nil { | ||
pterm.Success.Printfln("View stack in console: %s/%s/%s?region=%s", *info.ConsoleURL, organizationID, state["id"], state["region_id"]) | ||
} | ||
} | ||
Dav-14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil | ||
} |
Oops, something went wrong.
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.