Skip to content

Commit dcaf15c

Browse files
authored
Merge pull request #53 from kubero-dev/release/v3.0.0
Release/v3.0.0
2 parents a5907cf + 0393de5 commit dcaf15c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1039
-813
lines changed

.goreleaser.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ builds:
1212
- CGO_ENABLED=0
1313
goos:
1414
- linux
15-
- windows
15+
# - windows
1616
- darwin
1717
archives:
1818
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
19-
format_overrides:
20-
- goos: windows
21-
format: zip
19+
# format_overrides:
20+
# - goos: windows
21+
# format: zip
2222
checksum:
2323
name_template: 'checksums.txt'
2424
snapshot:

README.md

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,34 +165,64 @@ Kubero CLI currently supports the following cloud providers:
165165
```plaintext
166166
kubero
167167
├── install # Create a Kubernetes cluster and install Kubero with all required components
168-
├── list # List all running clusters
169-
├── login # Log in to Kubero and save credentials
170-
├── logout # Log out from Kubero and remove saved credentials
171-
├── create # Create new app and pipeline configurations
172-
│ ├── app
173-
│ └── pipeline
174-
├── up # Deploy apps and pipelines
175-
│ ├── app
176-
│ └── pipeline
177-
├── down # Remove apps and pipelines
178-
│ ├── app
179-
│ └── pipeline
180-
├── fetch # Sync configurations to local files
181-
│ ├── app
182-
│ └── pipeline
183-
├── dashboard # Open the Kubero dashboard
184-
├── tunnel # Open a tunnel to a NAT-ed cluster
185-
├── instance # Manage Kubero instances
186-
│ ├── create # Create an instance configuration
187-
│ ├── delete # Delete an instance configuration
188-
│ └── select # Select an active instance
168+
| # Can also be used to install Kubero on an existing cluster
169+
├── login (li) # Log in to Kubero and save credentials
170+
├── logout (lo) # Log out from Kubero and remove saved credentials
171+
├── remote (r) # List Kubero cluster
172+
│ ├── create # Create a cluster configuration
173+
│ ├── delete # Delete a cluster configuration
174+
│ └── select # Select a cluster
175+
├── app (a) # List Kubero apps
176+
│ ├── create # Create an app
177+
│ └── delete # Delete an app
178+
├── pipeline (p) # List Kubero pipelines
179+
│ ├── create # Create a pipeline
180+
│ └── delete # Delete a pipeline
189181
├── config # View available configurations
190182
│ ├── addons # List addons
191-
│ ├── buildpacks # List buildpacks
183+
│ ├── runpacks # List runpacks
192184
│ └── podsizes # List pod size configurations
185+
├── dashboard (db) # Open the Kubero dashboard
186+
├── debug # Gather debug information
187+
├── tunnel (t) # Open a tunnel to a NAT-ed cluster
193188
└── help # Display help for commands
194189
```
195190

191+
### Usage with most common commands
192+
Create a new cluster and install Kubero:
193+
194+
```shell
195+
kubero install
196+
```
197+
198+
Create a new app configuration:
199+
```shell
200+
kubero app create
201+
```
202+
203+
Destroy an app:
204+
```shell
205+
kubero app delete
206+
```
207+
208+
List all running pipelines:
209+
```shell
210+
kubero pipelines
211+
```
212+
213+
Open the Kubero dashboard:
214+
215+
```shell
216+
kubero dashboard
217+
```
218+
219+
For more information, use the `--help` flag with any command:
220+
221+
```shell
222+
kubero --help
223+
```
224+
225+
196226
---
197227

198228
## Provider Credentials

cmd/kuberoCli/app.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,50 @@ package kuberoCli
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"kubero/pkg/kuberoApi"
67
"log"
78
"os"
89
"strings"
910

1011
"github.com/i582/cfmt/cmd/cfmt"
1112
"github.com/olekukonko/tablewriter"
13+
"github.com/spf13/cobra"
1214
"github.com/spf13/viper"
1315
)
1416

17+
var AppCmd = &cobra.Command{
18+
Use: "app",
19+
Aliases: []string{"apps", "application", "applications", "a"},
20+
Short: "List apps in a Pipeline",
21+
Long: `Create a new app in a Pipeline.
22+
23+
If called without arguments, it will ask for all the required information`,
24+
Run: func(cmd *cobra.Command, args []string) {
25+
26+
pipelinesList := getAllRemotePipelines()
27+
fmt.Println(pipelinesList)
28+
ensurePipelineIsSet(pipelinesList)
29+
//ensureStageNameIsSet()
30+
//ensureAppNameIsSet()
31+
appsList()
32+
33+
},
34+
}
35+
36+
func init() {
37+
rootCmd.AddCommand(AppCmd)
38+
AppCmd.PersistentFlags().StringVarP(&pipelineName, "pipeline", "p", "", "name of the pipeline")
39+
}
40+
1541
func appsList() {
1642

1743
pipelineResp, _ := api.GetPipelineApps(pipelineName)
1844

1945
var pl Pipeline
2046
jsonUnmarshalErr := json.Unmarshal(pipelineResp.Body(), &pl)
2147
if jsonUnmarshalErr != nil {
22-
log.Fatal(jsonUnmarshalErr)
48+
log.Fatal("appsList ", jsonUnmarshalErr)
2349
return
2450
}
2551

cmd/kuberoCli/appCreate.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package kuberoCli
2+
3+
import (
4+
"fmt"
5+
"kubero/pkg/kuberoApi"
6+
"os"
7+
"strconv"
8+
9+
"github.com/i582/cfmt/cmd/cfmt"
10+
"github.com/spf13/cobra"
11+
"gopkg.in/yaml.v3"
12+
)
13+
14+
var createAppCmd = &cobra.Command{
15+
Use: "create",
16+
Short: "Create a new app in a Pipeline",
17+
Long: `Create a new app in a Pipeline.
18+
19+
If called without arguments, it will ask for all the required information`,
20+
Run: func(cmd *cobra.Command, args []string) {
21+
22+
pipelinesList := getAllRemotePipelines()
23+
ensurePipelineIsSet(pipelinesList)
24+
ensureStageNameIsSet()
25+
ensureAppNameIsSet()
26+
createRemoteApp()
27+
28+
},
29+
}
30+
31+
func init() {
32+
AppCmd.AddCommand(createAppCmd)
33+
createAppCmd.Flags().StringVarP(&pipelineName, "pipeline", "p", "", "Name of the pipeline")
34+
createAppCmd.Flags().StringVarP(&stageName, "stage", "s", "", "Name of the stage")
35+
createAppCmd.Flags().StringVarP(&appName, "app", "a", "", "Name of the app")
36+
}
37+
38+
func appForm() kuberoApi.AppCRD {
39+
40+
var appCRD kuberoApi.AppCRD
41+
42+
pipelineConfig := loadPipelineConfig(pipelineName, false)
43+
44+
appCRD.APIVersion = "application.kubero.dev/v1alpha1"
45+
appCRD.Kind = "KuberoApp"
46+
47+
appCRD.Spec.Name = appName
48+
appCRD.Spec.Pipeline = pipelineName
49+
appCRD.Spec.Phase = stageName
50+
51+
appCRD.Spec.Domain = promptLine("Domain", "", "")
52+
gitURL := pipelineConfig.Spec.Git.Repository.SshUrl
53+
if gitURL != "" {
54+
appCRD.Spec.Branch = promptLine("Branch", gitURL+":", "main")
55+
} else {
56+
appCRD.Spec.Branch = promptLine("Branch", "", "main")
57+
}
58+
59+
appCRD.Spec.Buildpack = pipelineConfig.Spec.Buildpack.Name
60+
61+
autodeploy := promptLine("Autodeploy", "[y,n]", "n")
62+
if autodeploy == "Y" {
63+
appCRD.Spec.Autodeploy = true
64+
} else {
65+
appCRD.Spec.Autodeploy = false
66+
}
67+
68+
envCount, _ := strconv.Atoi(promptLine("Number of Env Vars", "", "0"))
69+
appCRD.Spec.EnvVars = []string{}
70+
for i := 0; i < envCount; i++ {
71+
appCRD.Spec.EnvVars = append(appCRD.Spec.EnvVars, promptLine("Env Var", "", ""))
72+
}
73+
74+
appCRD.Spec.Image.ContainerPort, _ = strconv.Atoi(promptLine("Container Port", "8080", "8080"))
75+
76+
appCRD.Spec.Web = kuberoApi.Web{}
77+
appCRD.Spec.Web.ReplicaCount, _ = strconv.Atoi(promptLine("Web Pods", "1", "1"))
78+
79+
appCRD.Spec.Worker = kuberoApi.Worker{}
80+
appCRD.Spec.Worker.ReplicaCount, _ = strconv.Atoi(promptLine("Worker Pods", "0", "0"))
81+
82+
return appCRD
83+
}
84+
85+
func createRemoteApp() {
86+
appCRD := appForm()
87+
88+
_, err := api.DeployApp(pipelineName, stageName, appName, appCRD)
89+
if err != nil {
90+
fmt.Println(err)
91+
return
92+
} else {
93+
_, _ = cfmt.Print("\n{{Created appCRD}}::green\n\n")
94+
}
95+
96+
}
97+
98+
func creatIacApp() {
99+
100+
appCRD := appForm()
101+
102+
writeAppYaml(appCRD)
103+
104+
_, _ = cfmt.Println("\n\n{{Created appCRD.yaml}}::green")
105+
}
106+
107+
func writeAppYaml(appCRD kuberoApi.AppCRD) {
108+
// write pipeline.yaml
109+
yamlData, err := yaml.Marshal(&appCRD)
110+
111+
if err != nil || appCRD.Spec.Name == "" {
112+
panic("Unable to write data into the file")
113+
}
114+
115+
fileName := ".kubero/" + appCRD.Spec.Pipeline + "/" + appCRD.Spec.Phase + "/" + appCRD.Spec.Name + ".yaml"
116+
117+
err = os.WriteFile(fileName, yamlData, 0644)
118+
if err != nil {
119+
panic("Unable to write data into the file")
120+
}
121+
}

cmd/kuberoCli/appDelete.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package kuberoCli
2+
3+
/*
4+
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
5+
*/
6+
7+
import (
8+
"github.com/spf13/cobra"
9+
)
10+
11+
// appCmd represents the app command
12+
var deleteAppCmd = &cobra.Command{
13+
Use: "delete",
14+
Aliases: []string{"d"},
15+
Short: "Deletes an app from the cluster",
16+
Long: `Use the app subcommand to undeploy your apps from the cluster`,
17+
Run: func(cmd *cobra.Command, args []string) {
18+
downApp()
19+
},
20+
}
21+
22+
func init() {
23+
AppCmd.AddCommand(deleteAppCmd)
24+
deleteAppCmd.Flags().StringVarP(&pipelineName, "pipeline", "p", "", "name of the pipeline")
25+
deleteAppCmd.Flags().StringVarP(&stageName, "stage", "s", "", "Name of the stage [test|stage|production]")
26+
deleteAppCmd.Flags().StringVarP(&appName, "app", "a", "", "name of the app")
27+
}
28+
29+
func downApp() {
30+
31+
pipelinesList := getAllRemotePipelines()
32+
ensurePipelineIsSet(pipelinesList)
33+
34+
ensureStageNameIsSet()
35+
36+
appsList := getAllRemoteApps()
37+
ensureAppNameIsSelected(appsList)
38+
39+
confirmationLine("Are you sure you want to undeploy the app "+appName+" from "+stageName+" in "+pipelineName+"?", "y")
40+
41+
_, err := api.DeleteApp(pipelineName, stageName, appName)
42+
if err != nil {
43+
panic("Unable to undeploy App")
44+
}
45+
}

0 commit comments

Comments
 (0)