diff --git a/Dockerfile b/Dockerfile index 01bb2133f..dde5315ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,11 @@ RUN adduser \ --uid 10001 \ codefresh +ARG GITHUB_TOKEN +RUN git config \ + --global \ + url."https://github:${GITHUB_TOKEN}@github.com".insteadOf \ + "https://github.com" COPY go.mod . COPY go.sum . diff --git a/Makefile b/Makefile index 5dbe020d7..a1d21b080 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=v0.0.21 +VERSION=v0.0.23 OUT_DIR=dist YEAR?=$(shell date +"%Y") diff --git a/cmd/commands/runtime.go b/cmd/commands/runtime.go index a28a784ec..8b14d6bc2 100644 --- a/cmd/commands/runtime.go +++ b/cmd/commands/runtime.go @@ -17,6 +17,7 @@ package commands import ( "context" "fmt" + "os" "time" "github.com/codefresh-io/cli-v2/pkg/cdUtils" @@ -24,6 +25,7 @@ import ( "github.com/codefresh-io/cli-v2/pkg/log" "github.com/codefresh-io/cli-v2/pkg/store" "github.com/codefresh-io/cli-v2/pkg/util" + "github.com/juju/ansiterm" appset "github.com/argoproj-labs/applicationset/api/v1alpha1" apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands" @@ -74,6 +76,7 @@ func NewRuntimeCommand() *cobra.Command { } cmd.AddCommand(NewRuntimeCreateCommand()) + cmd.AddCommand(NewRuntimeListCommand()) cmd.AddCommand(NewRuntimeDeleteCommand()) return cmd @@ -195,6 +198,65 @@ func RunRuntimeCreate(ctx context.Context, opts *RuntimeCreateOptions) error { return nil } +func NewRuntimeListCommand() *cobra.Command { + + + cmd := &cobra.Command{ + Use: "list ", + Short: "List all Codefresh runtimes", + Example: util.Doc(` runtime list`), + RunE: func(cmd *cobra.Command, args []string) error { + return listRuntimes(cmd.Context()) + }, + } + return cmd +} + +func listRuntimes(ctx context.Context) error { + runtimes, err := cfConfig.NewClient().ArgoRuntime().List() + if err != nil { + return err + } + tb := ansiterm.NewTabWriter(os.Stdout, 0, 0, 4, ' ', 0) + _, err = fmt.Fprintln(tb, "NAME\tNAMESPACE\tCLUSTER\tSTATUS\tVERSION") + if err != nil { + return err + } + for _, rt := range runtimes { + status := "N/A" + namespace:= "N/A" + name := "N/A" + cluster := "N/A" + version := "N/A" + if rt.Status != nil { + status = rt.Status.String() + } + if rt.Namespace != nil { + namespace = *rt.Namespace + } + if rt.ObjectMeta != nil && rt.ObjectMeta.Name != nil { + name = *rt.ObjectMeta.Name + } + if rt.Cluster != nil { + cluster = *rt.Cluster + } + if rt.Version != nil { + version = *rt.Version + } + _, err = fmt.Fprintf(tb, "%s\t%s\t%s\t%s\t%s\n", + name, + namespace, + cluster, + status, + version, + ) + if err != nil { + return err + } + } + return tb.Flush() +} + func NewRuntimeDeleteCommand() *cobra.Command { var ( f kube.Factory diff --git a/docs/commands/cli-v2_runtime.md b/docs/commands/cli-v2_runtime.md index edd892bc0..a6f13c29e 100644 --- a/docs/commands/cli-v2_runtime.md +++ b/docs/commands/cli-v2_runtime.md @@ -26,4 +26,5 @@ cli-v2 runtime [flags] * [cli-v2](cli-v2.md) - cli-v2 is used for installing and managing codefresh installations using gitops * [cli-v2 runtime create](cli-v2_runtime_create.md) - Create a new Codefresh runtime * [cli-v2 runtime delete](cli-v2_runtime_delete.md) - Deletes a Codefresh runtime +* [cli-v2 runtime list](cli-v2_runtime_list.md) - List all Codefresh runtimes diff --git a/docs/commands/cli-v2_runtime_list.md b/docs/commands/cli-v2_runtime_list.md new file mode 100644 index 000000000..4fcd2cc71 --- /dev/null +++ b/docs/commands/cli-v2_runtime_list.md @@ -0,0 +1,33 @@ +## cli-v2 runtime list + +List all Codefresh runtimes + +``` +cli-v2 runtime list [flags] +``` + +### Examples + +``` +cli-v2 runtime list +``` + +### Options + +``` + -h, --help help for list +``` + +### Options inherited from parent commands + +``` + --auth-context string Run the next command using a specific authentication context + --cfconfig string Custom path for authentication contexts config file (default "/home/user") + --insecure Disable certificate validation for TLS connections (e.g. to g.codefresh.io) + --request-timeout duration Request timeout (default 30s) +``` + +### SEE ALSO + +* [cli-v2 runtime](cli-v2_runtime.md) - Manage Codefresh runtimes + diff --git a/go.mod b/go.mod index d292dadf2..e21daa906 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/argoproj/argo-events v1.3.1 github.com/argoproj/argo-workflows/v3 v3.1.0 github.com/briandowns/spinner v1.13.0 - github.com/codefresh-io/go-sdk v0.26.2 + github.com/codefresh-io/go-sdk v0.26.5 github.com/fatih/color v1.12.0 github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/go-git/go-billy/v5 v5.3.1 diff --git a/go.sum b/go.sum index 155bbacbc..ba8e64b0a 100644 --- a/go.sum +++ b/go.sum @@ -257,8 +257,10 @@ github.com/clusterhq/flocker-go v0.0.0-20160920122132-2b8b7259d313/go.mod h1:P1w github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/codefresh-io/go-sdk v0.26.2 h1:nGiLEOXaYGd7DbwKpqeTm1XXVCATayQm/pU3DwA6wqc= -github.com/codefresh-io/go-sdk v0.26.2/go.mod h1:0m0ATMmbFzvrc3CwUTB10MGO6hydsZdzLeHCAOyAvyM= +github.com/codefresh-io/argo-platform v1.13.0 h1:eWAWkxtO0nGZuekrQJsfFT5KfBMdWby0cOucy4yTExs= +github.com/codefresh-io/argo-platform v1.13.0/go.mod h1:u/eLWAySJ1nRzNWnB5baeyIc5vqINghwYJvydU+EC3c= +github.com/codefresh-io/go-sdk v0.26.5 h1:3apUfIyE4BSGWAwTGwO0yeP0XF4P3VKh7sOqwlDyRSs= +github.com/codefresh-io/go-sdk v0.26.5/go.mod h1:WxoYUrd9ZF7yvBohEdQfANEhD59a7eq6DNOkbpLP7Lw= github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I= github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4= github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4= diff --git a/out.txt b/out.txt new file mode 100644 index 000000000..e69de29bb