Skip to content
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

Release/v3.0.0 #53

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ builds:
- CGO_ENABLED=0
goos:
- linux
- windows
# - windows
- darwin
archives:
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
format_overrides:
- goos: windows
format: zip
# format_overrides:
# - goos: windows
# format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
72 changes: 51 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,34 +159,64 @@ Kubero CLI currently supports the following cloud providers:
```plaintext
kubero
├── install # Create a Kubernetes cluster and install Kubero with all required components
├── list # List all running clusters
├── login # Log in to Kubero and save credentials
├── logout # Log out from Kubero and remove saved credentials
├── create # Create new app and pipeline configurations
│ ├── app
│ └── pipeline
├── up # Deploy apps and pipelines
│ ├── app
│ └── pipeline
├── down # Remove apps and pipelines
│ ├── app
│ └── pipeline
├── fetch # Sync configurations to local files
│ ├── app
│ └── pipeline
├── dashboard # Open the Kubero dashboard
├── tunnel # Open a tunnel to a NAT-ed cluster
├── instance # Manage Kubero instances
│ ├── create # Create an instance configuration
│ ├── delete # Delete an instance configuration
│ └── select # Select an active instance
| # Can also be used to install Kubero on an existing cluster
├── login (li) # Log in to Kubero and save credentials
├── logout (lo) # Log out from Kubero and remove saved credentials
├── remote (r) # List Kubero cluster
│ ├── create # Create a cluster configuration
│ ├── delete # Delete a cluster configuration
│ └── select # Select a cluster
├── app (a) # List Kubero apps
│ ├── create # Create an app
│ └── delete # Delete an app
├── pipeline (p) # List Kubero pipelines
│ ├── create # Create a pipeline
│ └── delete # Delete a pipeline
├── config # View available configurations
│ ├── addons # List addons
│ ├── buildpacks # List buildpacks
│ └── podsizes # List pod size configurations
├── dashboard (db) # Open the Kubero dashboard
├── debug # Gather debug information
├── tunnel (t) # Open a tunnel to a NAT-ed cluster
└── help # Display help for commands
```

### Usage with most common commands
Create a new cluster and install Kubero:

```shell
kubero install
```

Create a new app configuration:
```shell
kubero app create
```

Destroy an app:
```shell
kubero app delete
```

List all running pipelines:
```shell
kubero pipelines
```

Open the Kubero dashboard:

```shell
kubero dashboard
```

For more information, use the `--help` flag with any command:

```shell
kubero --help
```


---

## Provider Credentials
Expand Down
28 changes: 27 additions & 1 deletion cmd/kuberoCli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,50 @@ package kuberoCli

import (
"encoding/json"
"fmt"
"kubero/pkg/kuberoApi"
"log"
"os"
"strings"

"github.com/i582/cfmt/cmd/cfmt"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var AppCmd = &cobra.Command{
Use: "app",
Aliases: []string{"apps", "application", "applications", "a"},
Short: "List apps in a Pipeline",
Long: `Create a new app in a Pipeline.

If called without arguments, it will ask for all the required information`,
Run: func(cmd *cobra.Command, args []string) {

pipelinesList := getAllRemotePipelines()
fmt.Println(pipelinesList)
ensurePipelineIsSet(pipelinesList)
//ensureStageNameIsSet()
//ensureAppNameIsSet()
appsList()

},
}

func init() {
rootCmd.AddCommand(AppCmd)
AppCmd.PersistentFlags().StringVarP(&pipelineName, "pipeline", "p", "", "name of the pipeline")
}

func appsList() {

pipelineResp, _ := api.GetPipelineApps(pipelineName)

var pl Pipeline
jsonUnmarshalErr := json.Unmarshal(pipelineResp.Body(), &pl)
if jsonUnmarshalErr != nil {
log.Fatal(jsonUnmarshalErr)
log.Fatal("appsList ", jsonUnmarshalErr)
return
}

Expand Down
121 changes: 121 additions & 0 deletions cmd/kuberoCli/appCreate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package kuberoCli

import (
"fmt"
"kubero/pkg/kuberoApi"
"os"
"strconv"

"github.com/i582/cfmt/cmd/cfmt"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)

var createAppCmd = &cobra.Command{
Use: "create",
Short: "Create a new app in a Pipeline",
Long: `Create a new app in a Pipeline.

If called without arguments, it will ask for all the required information`,
Run: func(cmd *cobra.Command, args []string) {

pipelinesList := getAllRemotePipelines()
ensurePipelineIsSet(pipelinesList)
ensureStageNameIsSet()
ensureAppNameIsSet()
createRemoteApp()

},
}

func init() {
AppCmd.AddCommand(createAppCmd)
createAppCmd.Flags().StringVarP(&pipelineName, "pipeline", "p", "", "Name of the pipeline")
createAppCmd.Flags().StringVarP(&stageName, "stage", "s", "", "Name of the stage")
createAppCmd.Flags().StringVarP(&appName, "app", "a", "", "Name of the app")
}

func appForm() kuberoApi.AppCRD {

var appCRD kuberoApi.AppCRD

pipelineConfig := loadPipelineConfig(pipelineName, false)

appCRD.APIVersion = "application.kubero.dev/v1alpha1"
appCRD.Kind = "KuberoApp"

appCRD.Spec.Name = appName
appCRD.Spec.Pipeline = pipelineName
appCRD.Spec.Phase = stageName

appCRD.Spec.Domain = promptLine("Domain", "", "")
gitURL := pipelineConfig.Spec.Git.Repository.SshUrl
if gitURL != "" {
appCRD.Spec.Branch = promptLine("Branch", gitURL+":", "main")
} else {
appCRD.Spec.Branch = promptLine("Branch", "", "main")
}

appCRD.Spec.Buildpack = pipelineConfig.Spec.Buildpack.Name

autodeploy := promptLine("Autodeploy", "[y,n]", "n")
if autodeploy == "Y" {
appCRD.Spec.Autodeploy = true
} else {
appCRD.Spec.Autodeploy = false
}

envCount, _ := strconv.Atoi(promptLine("Number of Env Vars", "", "0"))
appCRD.Spec.EnvVars = []string{}
for i := 0; i < envCount; i++ {
appCRD.Spec.EnvVars = append(appCRD.Spec.EnvVars, promptLine("Env Var", "", ""))
}

appCRD.Spec.Image.ContainerPort, _ = strconv.Atoi(promptLine("Container Port", "8080", "8080"))

appCRD.Spec.Web = kuberoApi.Web{}
appCRD.Spec.Web.ReplicaCount, _ = strconv.Atoi(promptLine("Web Pods", "1", "1"))

appCRD.Spec.Worker = kuberoApi.Worker{}
appCRD.Spec.Worker.ReplicaCount, _ = strconv.Atoi(promptLine("Worker Pods", "0", "0"))

return appCRD
}

func createRemoteApp() {
appCRD := appForm()

_, err := api.DeployApp(pipelineName, stageName, appName, appCRD)
if err != nil {
fmt.Println(err)
return
} else {
_, _ = cfmt.Print("\n{{Created appCRD}}::green\n\n")
}

}

func creatIacApp() {

appCRD := appForm()

writeAppYaml(appCRD)

_, _ = cfmt.Println("\n\n{{Created appCRD.yaml}}::green")
}

func writeAppYaml(appCRD kuberoApi.AppCRD) {
// write pipeline.yaml
yamlData, err := yaml.Marshal(&appCRD)

if err != nil || appCRD.Spec.Name == "" {
panic("Unable to write data into the file")
}

fileName := ".kubero/" + appCRD.Spec.Pipeline + "/" + appCRD.Spec.Phase + "/" + appCRD.Spec.Name + ".yaml"

err = os.WriteFile(fileName, yamlData, 0644)
if err != nil {
panic("Unable to write data into the file")
}
}
45 changes: 45 additions & 0 deletions cmd/kuberoCli/appDelete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package kuberoCli

/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/

import (
"github.com/spf13/cobra"
)

// appCmd represents the app command
var deleteAppCmd = &cobra.Command{
Use: "delete",
Aliases: []string{"d"},
Short: "Deletes an app from the cluster",
Long: `Use the app subcommand to undeploy your apps from the cluster`,
Run: func(cmd *cobra.Command, args []string) {
downApp()
},
}

func init() {
AppCmd.AddCommand(deleteAppCmd)
deleteAppCmd.Flags().StringVarP(&pipelineName, "pipeline", "p", "", "name of the pipeline")
deleteAppCmd.Flags().StringVarP(&stageName, "stage", "s", "", "Name of the stage [test|stage|production]")
deleteAppCmd.Flags().StringVarP(&appName, "app", "a", "", "name of the app")
}

func downApp() {

pipelinesList := getAllRemotePipelines()
ensurePipelineIsSet(pipelinesList)

ensureStageNameIsSet()

appsList := getAllRemoteApps()
ensureAppNameIsSelected(appsList)

confirmationLine("Are you sure you want to undeploy the app "+appName+" from "+stageName+" in "+pipelineName+"?", "y")

_, err := api.DeleteApp(pipelineName, stageName, appName)
if err != nil {
panic("Unable to undeploy App")
}
}
Loading