Skip to content

Commit bc7b445

Browse files
authored
Merge pull request #65 from Phillezi/tests
Added some tests and docs
2 parents 368956e + eff4605 commit bc7b445

48 files changed

Lines changed: 1217 additions & 10 deletions

Some content is hidden

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

.github/workflows/go.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- README.md
88
- .gitignore
99
- .github/**
10+
- docs/*
1011
- LICENSE
1112

1213
jobs:

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BUILDTIMESTAMP=$(shell date -u +%Y%m%d%H%M%S)
66
EXT=$(if $(filter windows,$(GOOS)),.exe,)
77

88
# Targets
9-
.PHONY: all build run test release install all-platforms clean lint
9+
.PHONY: all build run test release install all-platforms clean lint docs
1010

1111
all: build
1212

@@ -54,3 +54,6 @@ clean:
5454

5555
lint:
5656
@./scripts/util/check-lint.sh
57+
58+
docs:
59+
@go run ./cmd/docs

cmd/cli_build.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import (
1111
var buildCmd = &cobra.Command{
1212
Use: "build",
1313
Short: "Build and push to the deployment specified in .kthcloud/DEPLOYMENT",
14+
Long: `
15+
Allows you to build and push your custom deployment locally using docker.
16+
17+
It uses the file ".kthcloud/DEPLOYMENT" to figure out which deployment your cwd maps to. This file contains the UUID of the deployment.
18+
19+
[!NOTE]: Requires you to have docker with buildx installed.`,
1420
Run: func(cmd *cobra.Command, args []string) {
1521
if err := build.New(build.CommandOpts{
1622
Client: options.DefaultClient(),

cmd/cli_cicd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
var cicdCmd = &cobra.Command{
1111
Use: "cicd",
1212
Short: "Generate CICD for gh repo",
13+
Long: `
14+
This command allows you to setup cicd for your git repo, it creates a custom deployments and adds a workflow for building and pushing to the kthcloud registry on push / merge to main ".github/workflows/".`,
1315
Run: func(cmd *cobra.Command, args []string) {
1416
save, err := cmd.Flags().GetBool("save-secrets")
1517
if err != nil {

cmd/cli_compose.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@ import (
1919
var composeCmd = &cobra.Command{
2020
Use: "compose",
2121
Short: "Deploy and manage Docker Compose projects on the cloud",
22+
Long: `
23+
Compose lets you describe multiple deployments in yaml files similary to how you would do it with docker compose.
24+
25+
The services described in the yaml files can be brought up on the cloud, you can bring them down, stop them or see logs from them.`,
2226
}
2327

2428
var composeParseCmd = &cobra.Command{
2529
Use: "parse",
2630
Short: "Parse a docker-compose.yaml or docker-compose.yml file",
31+
Long: `
32+
A simple command that parses a compose file into kthclouds create deployment json format.
33+
34+
The compose file can be specified with the --file flag.
35+
36+
Adding the --json flag will return pure json as response.`,
37+
Example: "kthcloud compose parse",
2738
Run: func(cmd *cobra.Command, args []string) {
2839
json, err := cmd.Flags().GetBool("json")
2940
if err != nil {
@@ -48,6 +59,20 @@ var composeParseCmd = &cobra.Command{
4859
var composeUpCmd = &cobra.Command{
4960
Use: "up",
5061
Short: "Deploy compose configuration to cloud",
62+
Long: `
63+
This command allows you to bring up a local compose definition to kthcloud.
64+
65+
It will automatically detect if you have custom deployments in your config that needs to be built.
66+
[!NOTE]: To keep track of custom deployments a file in "./.kthcloud/DEPLOYMENT" is made (relative to the build context of the service). This file contains the UUID of the deployment that the service maps to.
67+
68+
To rebuild services you can apply the --build flag to rebuild all services, or specify the ones you want to rebuild.
69+
70+
Volumes can be defined and managed, but it is done in a hacky way. Since the storage (filebrowser) instance that gets deployed for your user is behind a oauth2 proxy that only uses cookies for authentication. The current solution is as mention very hacky as it will try to scrape your browser for these cookies to authenticate. This only works on Linux and MacOS, but it can be unreliable since browser companies dont want you to be able too scrape stuff like this.
71+
72+
Default behaviour of this command will after creating all the deployments setup SSE log streams from all created deployments to your terminal. This can be skipped by adding the -d flag.`,
73+
Example: `kthcloud compose up \
74+
--file ./somesubdir/example.compose.yml \
75+
--try-volumes`,
5176
Run: func(cmd *cobra.Command, args []string) {
5277
detached, _ := cmd.Flags().GetBool("detached")
5378
tryToCreateVolumes, _ := cmd.Flags().GetBool("try-volumes")
@@ -82,6 +107,9 @@ var composeUpCmd = &cobra.Command{
82107
var composeDownCmd = &cobra.Command{
83108
Use: "down",
84109
Short: "Bring down compose configuration to cloud",
110+
Long: `
111+
This command will bring down all services specified in the compose file. By default custom deployments wont be brought down, this can be changed with the -a flag.`,
112+
Example: "kthcloud compose --file ./compose.yaml down -a",
85113
Run: func(cmd *cobra.Command, args []string) {
86114
all, err := cmd.Flags().GetBool("all")
87115
if err != nil {
@@ -105,6 +133,10 @@ var composeDownCmd = &cobra.Command{
105133
var composeStopCmd = &cobra.Command{
106134
Use: "stop",
107135
Short: "Stop compose configuration to cloud",
136+
Long: `
137+
This command will disable all services specified in the compose file. This is done my setting their replicas to zero.
138+
139+
[!NOTE]: At the time of writing this there is currently a but that when trying to re-enable these services later requires you to change more than just setting replicas back to 1 or whatever value it was before.`,
108140
Run: func(cmd *cobra.Command, args []string) {
109141
compose, err := parser.GetCompose()
110142
if err != nil {
@@ -123,6 +155,8 @@ var composeStopCmd = &cobra.Command{
123155
var composeLogsCmd = &cobra.Command{
124156
Use: "logs",
125157
Short: "Get logs from deployments in the compose file",
158+
Long: `
159+
This command allows you to get all logs from the services specified in the compose file.`,
126160
Run: func(cmd *cobra.Command, args []string) {
127161
compose, err := parser.GetCompose()
128162
if err != nil {

cmd/cli_login.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import (
99
var loginCmd = &cobra.Command{
1010
Use: "login",
1111
Short: "Log in to kthcloud using Keycloak and retrieve the authentication token",
12+
Long: `
13+
Lets you log in to kthcloud by opening a local server on ":3000" and opening your browser to kthclouds keycloak server with the redirect uri set to the local http server so the accesstoken can be retrieved.
14+
15+
On Linux make sure you have "xdg-open" (should be included by default in most distros) and a browser for this to work.`,
16+
Example: "kthcloud login",
1217
Run: func(cmd *cobra.Command, args []string) {
1318
c := options.DefaultClient()
1419
_, err := c.Login()

cmd/cli_logout.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
var logoutCmd = &cobra.Command{
1010
Use: "logout",
1111
Short: "Logout from kthcloud",
12+
Long: `
13+
Removes your current session.`,
14+
Example: "kthcloud logout",
1215
Run: func(cmd *cobra.Command, args []string) {
1316
if err := options.DefaultClient().Auth().Logout(); err != nil {
1417
logrus.Errorln(err)

cmd/cli_ps.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import (
1212
var psCmd = &cobra.Command{
1313
Use: "ps",
1414
Short: "List deployments",
15+
Long: `
16+
This command lets you list your deploymentss that are running, adding the -a or --all flag will list all deploymentss and wont filter to only the ones with resourceRunning status.
17+
18+
For VMs you can use the "kthcloud vm ps" command instead.`,
19+
Example: "kthcloud ps -a",
1520
Run: func(cmd *cobra.Command, args []string) {
1621
all, err := cmd.Flags().GetBool("all")
1722
if err != nil {

cmd/cli_root.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ var rootCmd = &cobra.Command{
3737
}
3838

3939
var versionCmd = &cobra.Command{
40-
Use: "version",
41-
Short: "See the version of the binary",
40+
Use: "version",
41+
Aliases: []string{"v"},
42+
Short: "See the version of the binary",
43+
Long: `
44+
Prints out the version of the binary that you are running. The version uses the build timestamp but in the future this might change to semantic versioning since it is more supported with gos versioning of packages.`,
45+
Example: "kthcloud version",
4246
Run: func(cmd *cobra.Command, args []string) {
4347
fmt.Println("version: " + viper.GetString("release"))
4448
},
@@ -47,6 +51,9 @@ var versionCmd = &cobra.Command{
4751
var whoamiCmd = &cobra.Command{
4852
Use: "whoami",
4953
Short: "See who you are",
54+
Long: `
55+
Prints out your user information from your current session, if not logged in you will get "I dont know...".`,
56+
Example: "kthcloud whoami",
5057
Run: func(cmd *cobra.Command, args []string) {
5158
c := options.DefaultClient()
5259
if !c.HasValidSession() {

cmd/cli_run.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import (
1212
var runCmd = &cobra.Command{
1313
Use: "run",
1414
Short: "Run a container",
15-
Args: cobra.MinimumNArgs(1),
15+
Long: `
16+
This command allows you to start up containers similarly to dockers run command. It has options to remove it when you exit (with ctrl + c), get logs and more.
17+
18+
Ports can be added with the -p or --p flag, you can just like docker add multiple ports, but in this case only the first port is used for the ingress (the one you can reach from outside the cluster) the rest of the ports are added as "internal" ports and are only exposed internally to the cluster.`,
19+
Example: "kthcloud run --rm -it -p 80 nginx:latest",
20+
Args: cobra.MinimumNArgs(1),
1621
Run: func(cmd *cobra.Command, args []string) {
1722
i, err := cmd.Flags().GetBool("interactive")
1823
if err != nil {

0 commit comments

Comments
 (0)