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
10 changes: 8 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ version: '3'

vars:
BINARY_NAME: qube
BUILD_DIR: ./bin
MAIN: .
BUILD_DIR: C:/Users/admin/go/bin
MAIN: ./cmd
VERSION:
sh: git describe --tags --abbrev=0 2>/dev/null || echo "dev"

Expand All @@ -13,6 +13,12 @@ tasks:
- task: build

build:
desc: 🔧 Build Qube CLI
cmds:
- echo "🔧 Building {{.BINARY_NAME}} version {{.VERSION}}"
- go build -ldflags="-X github.com/apiqube/cli/cmd.version={{.VERSION}}" -o={{.BUILD_DIR}}/{{.BINARY_NAME}}.exe {{.MAIN}}

build-versioned:
desc: 🔧 Build Qube CLI
cmds:
- echo "🔧 Building {{.BINARY_NAME}} version {{.VERSION}}"
Expand Down
54 changes: 22 additions & 32 deletions cmd/apply.go → cmd/cli/apply.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package cmd
package cli

import (
"slices"
"time"

"github.com/apiqube/cli/internal/manifests/depends"
"github.com/apiqube/cli/internal/ui"
"github.com/apiqube/cli/internal/yaml"
"github.com/apiqube/cli/internal/core/manifests/depends"
"github.com/apiqube/cli/internal/core/manifests/loader"
"github.com/apiqube/cli/internal/core/store"
"github.com/apiqube/cli/ui"
"github.com/spf13/cobra"
)

Expand All @@ -16,57 +14,49 @@ func init() {
}

var applyCmd = &cobra.Command{
Use: "apply",
Short: "Apply resources from manifest file",
RunE: func(cmd *cobra.Command, args []string) error {
ui.Init()
defer func() {
time.Sleep(time.Millisecond * 100)
ui.Stop()
}()

Use: "apply",
Short: "Apply resources from manifest file",
SilenceErrors: true,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
file, err := cmd.Flags().GetString("file")
if err != nil {
ui.Errorf("Failed to parse --file: %s", err.Error())
return err
return
}

ui.Printf("Applying manifests from: %s", file)
ui.Spinner(true, "Loading manifests")

mans, err := yaml.LoadManifestsFromDir(file)
mans, err := loader.LoadManifestsFromDir(file)
if err != nil {
ui.Spinner(false)
ui.Errorf("Failed to load manifests: %s", err.Error())
return err
return
}

ui.Spinner(false)
ui.Printf("Loaded %d manifests", len(mans))

slices.Reverse(mans)
for i, man := range mans {
ui.Printf("#%d ID: %s", i+1, man.GetID())
var result *depends.GraphResult
if result, err = depends.BuildGraphWithPriority(mans); err != nil {
ui.Errorf("Failed to generate plan: %s", err.Error())
return
}

ui.Spinner(true, "Generating execution plan")

if err = depends.GeneratePlan("./examples/simple", mans); err != nil {
ui.Errorf("Failed to generate plan: %s", err.Error())
return err
for i, order := range result.ExecutionOrder {
ui.Printf("#Order %d %s", i+1, order)
}

ui.Spinner(false)
ui.Print("Execution plan generated successfully")
ui.Spinner(true, "Saving manifests...")

if err := yaml.SaveManifests(file, mans...); err != nil {
if err := store.SaveManifests(mans...); err != nil {
ui.Error("Failed to save manifests: " + err.Error())
return err
return
}

ui.Spinner(false)
ui.Println("Manifests applied successfully")

return nil
},
}
6 changes: 4 additions & 2 deletions cmd/root.go → cmd/cli/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd
package cli

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

var rootCmd = &cobra.Command{
Use: "qube",
Expand Down
8 changes: 5 additions & 3 deletions cmd/version.go → cmd/cli/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package cli

import (
"fmt"
Expand All @@ -9,8 +9,10 @@ import (
var version = "dev"

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number",
Use: "version",
Short: "Print the version number",
SilenceUsage: true,
SilenceErrors: true,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Qube CLI Version: ", version)
},
Expand Down
21 changes: 21 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"time"

"github.com/apiqube/cli/cmd/cli"
"github.com/apiqube/cli/internal/core/store"
"github.com/apiqube/cli/ui"
)

func main() {
ui.Init()
defer ui.Stop()

store.Init()
defer store.Stop()

cli.Execute()

time.Sleep(time.Second)
}
25 changes: 0 additions & 25 deletions core/executor/executor.go

This file was deleted.

54 changes: 0 additions & 54 deletions core/plan/plan.go

This file was deleted.

File renamed without changes.
8 changes: 0 additions & 8 deletions examples/simple/execution-plan.json

This file was deleted.

5 changes: 0 additions & 5 deletions examples/simple/http_test.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
version: 1

kind: HttpTest

metadata:
name: simple-http-test

spec:
server: simple-server
cases:
Expand Down Expand Up @@ -33,13 +30,11 @@ spec:
password: "example_password"
expected:
code: 200

- name: user-fetch
method: GET
endpoint: /users/{id}
expected:
code: 404
message: "User not found"

dependsOn:
- default.Service.simple-service
24 changes: 24 additions & 0 deletions examples/simple/http_test_second.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 1
kind: HttpTest
metadata:
name: not-simple-http-test
namespace: not-simple
spec:
server: simple-server
cases:
- name: user-login
method: GET
endpoint: /login
body:
email: "example_email"
password: "example_password"
expected:
code: 200
- name: user-fetch
method: GET
endpoint: /users/{id}
expected:
code: 404
message: "User not found"
dependsOn:
- default.Service.simple-service
11 changes: 9 additions & 2 deletions examples/simple/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ spec:
image: some_path
ports:
- 8080:8080
- 50051:50051
env:
run: run-command
clean: clean-command
db_url: postgres:5432
replicas: 3
healthPath: /health

- name: auth-service
containerName: auth
dockerfile: some_path
Expand All @@ -32,6 +30,15 @@ spec:
db_url: postgres:5432
replicas: 6
healthPath: /health
- name: lobby-service
containerName: lobby
dockerfile: some_path
image: some_path
ports:
- 8081:8081
env:
db_url: redis_url
replicas: 2

dependsOn:
- default.Server.simple-server
13 changes: 13 additions & 0 deletions examples/values/Values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 1

kind: Values
metadata:
name: values

spec:
users:
username: ["Max", "Carl", "John", "Alex"]
email:
- "email_1@gmail.com"
- "email_2@mail.com"
- "email_3@dog.io"
Loading
Loading