Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,36 @@ eds repo delete <id-or-name> [--force] delete a repository
eds repo clone <id-or-name> [dir] [--ssh] clone via local git CLI
eds repo remote-add <id-or-name> [--name N] [--ssh] wire an existing local checkout to it (git remote add)

eds wf app create <name> --repository R|--repository-url URL --branch B create and auto-deploy a Workflow Studio application
eds wf app list list applications
eds wf app create <name> --repository R|--repository-url URL --branch B [--space-id S] [--port N] create and auto-deploy a Workflow Studio application
eds wf app list [--space-id S] list applications
eds wf app show <id> show application details
eds wf app update <id> --branch B [--name N] update name/branch
eds wf app update <id> --branch B [--name N] [--space-id S] [--port N] update name/branch/space/port
eds wf app delete <id> [--force] delete an application
eds wf app deploy <id> run the pipeline and publish
eds wf app deployments <id> list publish history

eds wf run show <id> show a run's status, stages and jobs
eds wf run stop <id> stop a running run
eds wf pipeline list list pipelines
eds wf pipeline show <id> show pipeline details

eds wf job logs <id> get logs for a job
eds wf run list [--pipeline-id ID] [--limit N] [--with-config] list pipeline runs
eds wf run show <id> show a run's status, stages and jobs
eds wf run stop <id> stop a running run

eds wf space list list application spaces
eds wf space create --name <name> create an application space
eds wf space show <id> show an application space
eds wf space update <id> --name <name> update an application space
eds wf space delete <id> delete an application space

eds wf variable list --pipeline-id <id> list variables for a pipeline
eds wf variable create <name> <value> --pipeline-id create a variable
eds wf variable update <name> <value> --pipeline-id update a variable
eds wf variable delete <name> --pipeline-id delete a variable

eds wf job list --run-id <id> list jobs for a run
eds wf job show <id> show job details
eds wf job stop <id> stop a running job
eds wf job logs <id> get logs for a job
```

### Login
Expand Down
38 changes: 30 additions & 8 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func newAppCreateCmd() *cobra.Command {
repository string
repositoryURL string
branch string
spaceID string
port int
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -83,6 +85,12 @@ accepts either its id or its name) or an external git URL (--repository-url).`,
if repositoryURL != "" {
req.RepositoryUrl = &repositoryURL
}
if spaceID != "" {
req.SpaceId = &spaceID
}
if port != 0 {
req.Port = &port
}
app, _, err := ctx.WorkflowClient.ServicesAPI.ProjectProjectIdApplicationPost(cmd.Context(), ctx.ProjectID).
Request(req).Execute()
if err != nil {
Expand All @@ -96,15 +104,18 @@ accepts either its id or its name) or an external git URL (--repository-url).`,
cmd.Flags().StringVar(&repository, "repository", "", "id or name of an existing `eds repo` repository")
cmd.Flags().StringVar(&repositoryURL, "repository-url", "", "external git repository URL (alternative to --repository)")
cmd.Flags().StringVar(&branch, "branch", "main", "branch to deploy from")
cmd.Flags().StringVar(&spaceID, "space-id", "", "application space ID to place the app in (default space if omitted)")
cmd.Flags().IntVar(&port, "port", 0, "container port the app listens on (server default if omitted)")
return cmd
}

func newAppListCmd() *cobra.Command {
var (
search string
sort string
limit int
offset int
search string
sort string
limit int
offset int
spaceID string
)

cmd := &cobra.Command{
Expand All @@ -127,6 +138,7 @@ func newAppListCmd() *cobra.Command {
Limit(limit).
Offset(offset).
Search(search).
SpaceId(spaceID).
Execute()
if err != nil {
return fmt.Errorf("workflow client application list: %w", err)
Expand All @@ -140,6 +152,7 @@ func newAppListCmd() *cobra.Command {
cmd.Flags().StringVar(&sort, "sort", "created_at_desc", "sort order: created_at_asc, created_at_desc")
cmd.Flags().IntVar(&limit, "limit", 50, "page size")
cmd.Flags().IntVar(&offset, "offset", 0, "offset")
cmd.Flags().StringVar(&spaceID, "space-id", "", "filter by application space ID")
return cmd
}

Expand Down Expand Up @@ -171,8 +184,10 @@ func newAppShowCmd() *cobra.Command {

func newAppUpdateCmd() *cobra.Command {
var (
name string
branch string
name string
branch string
spaceID string
port int
)

cmd := &cobra.Command{
Expand All @@ -194,12 +209,17 @@ func newAppUpdateCmd() *cobra.Command {
}

req := workflowclient.GitSbercloudTechDsworksServicesPipelineSrcInternalApplicationRequestApplicationUpdate{
Branch: branch,
SpaceId: "",
Branch: branch,
}
if name != "" {
req.Name = &name
}
if spaceID != "" {
req.SpaceId = &spaceID
}
if port != 0 {
req.Port = &port
}
_, err = ctx.WorkflowClient.ServicesAPI.ProjectProjectIdApplicationApplicationIdPatch(cmd.Context(), ctx.ProjectID, args[0]).
Request(req).
Execute()
Expand All @@ -212,6 +232,8 @@ func newAppUpdateCmd() *cobra.Command {

cmd.Flags().StringVar(&name, "name", "", "new application name")
cmd.Flags().StringVar(&branch, "branch", "", "new branch to deploy from")
cmd.Flags().StringVar(&spaceID, "space-id", "", "move the app to this application space ID")
cmd.Flags().IntVar(&port, "port", 0, "container port the app listens on")
return cmd
}

Expand Down
98 changes: 98 additions & 0 deletions cmd/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,109 @@ func newJobCmd() *cobra.Command {
Short: "Inspect and control Workflow Studio jobs",
}

cmd.AddCommand(newJobListCmd())
cmd.AddCommand(newJobShowCmd())
cmd.AddCommand(newJobStopCmd())
cmd.AddCommand(newJobLogsCmd())

return cmd
}

func newJobListCmd() *cobra.Command {
var (
runID string
limit int
offset int
)

cmd := &cobra.Command{
Use: "list",
Short: "List jobs for a run",
Example: ` eds wf job list --run-id my-run-id
eds wf job list --run-id my-run-id --limit 20`,
RunE: func(cmd *cobra.Command, _ []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}
if runID == "" {
return fmt.Errorf("--run-id is required")
}

resp, _, err := ctx.WorkflowClient.PipelinesAPI.ListJobs(cmd.Context(), ctx.ProjectID).
RunId(runID).
Limit(limit).
Offset(offset).
Execute()
if err != nil {
return fmt.Errorf("workflow client job list: %w", err)
}

return ctx.Printer.Print(resp)
},
}

cmd.Flags().StringVar(&runID, "run-id", "", "run ID to list jobs for (required)")
cmd.Flags().IntVar(&limit, "limit", 50, "page size")
cmd.Flags().IntVar(&offset, "offset", 0, "offset")
return cmd
}

func newJobShowCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "show <job-id>",
Short: "Show job details",
Args: cobra.ExactArgs(1),
Example: ` eds wf job show my-job-id`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}

job, _, err := ctx.WorkflowClient.WorkflowsAPI.GetJob(cmd.Context(), ctx.ProjectID, args[0]).
Execute()
if err != nil {
return fmt.Errorf("workflow client get job: %w", err)
}

return ctx.Printer.Print(job)
},
}
return cmd
}

func newJobStopCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "stop <job-id>",
Short: "Stop a running job",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}

_, _, err = ctx.WorkflowClient.WorkflowsAPI.StopJob(cmd.Context(), ctx.ProjectID, args[0]).Execute()
if err != nil {
return fmt.Errorf("stop job: %w", err)
}

return ctx.Printer.Print("job has been stopped")
},
}
return cmd
}

func newJobLogsCmd() *cobra.Command {
var (
limit int
Expand Down
88 changes: 88 additions & 0 deletions cmd/pipeline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// newPipelineCmd creates the parent `eds wf pipeline` command.
func newPipelineCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "pipeline",
Short: "Manage Workflow Studio pipelines",
}
cmd.AddCommand(newPipelineListCmd())
cmd.AddCommand(newPipelineShowCmd())
return cmd
}

func newPipelineListCmd() *cobra.Command {
var (
search string
sort string
limit int
offset int
)

cmd := &cobra.Command{
Use: "list",
Short: "List pipelines in the configured project",
Example: ` eds wf pipeline list
eds wf pipeline list --search my-pipeline --limit 10`,
RunE: func(cmd *cobra.Command, _ []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}

resp, _, err := ctx.WorkflowClient.PipelinesAPI.ListPipelines(cmd.Context(), ctx.ProjectID).
Search(search).
Sort(sort).
Limit(limit).
Offset(offset).
Execute()
if err != nil {
return fmt.Errorf("workflow client pipeline list: %w", err)
}

return ctx.Printer.Print(resp)
},
}

cmd.Flags().StringVar(&search, "search", "", "search term (default: all)")
cmd.Flags().StringVar(&sort, "sort", "", "sort order: created_at_asc, created_at_desc")
cmd.Flags().IntVar(&limit, "limit", 50, "page size")
cmd.Flags().IntVar(&offset, "offset", 0, "offset")
return cmd
}

func newPipelineShowCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "show <pipeline-id>",
Short: "Show pipeline details",
Args: cobra.ExactArgs(1),
Example: ` eds wf pipeline show my-pipeline-id`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}

pipe, _, err := ctx.WorkflowClient.PipelinesAPI.GetPipeline(cmd.Context(), ctx.ProjectID, args[0]).
Execute()
if err != nil {
return fmt.Errorf("workflow client get pipeline: %w", err)
}

return ctx.Printer.Print(pipe)
},
}
return cmd
}
4 changes: 2 additions & 2 deletions cmd/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func newRepoDeleteCmd() *cobra.Command {
if err := ctx.API.DeleteRepository(cmd.Context(), id); err != nil {
return fmt.Errorf("api delete repository: %w", err)
}
fmt.Fprintf(cmd.OutOrStdout(), "Deleted repository %s\n", args[0])
return nil

return ctx.Printer.Print("repository has been deleted")
},
}

Expand Down
Loading
Loading