Skip to content

Commit 04a9f1a

Browse files
authored
Merge pull request #4 from apiqube/dev
Dev
2 parents a5a30ae + 2e9f18c commit 04a9f1a

29 files changed

Lines changed: 1688 additions & 116 deletions

cmd/apply.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package cmd
2+
3+
import (
4+
"slices"
5+
"time"
6+
7+
"github.com/apiqube/cli/internal/manifests/depends"
8+
"github.com/apiqube/cli/internal/ui"
9+
"github.com/apiqube/cli/internal/yaml"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
func init() {
14+
applyCmd.Flags().StringP("file", "f", ".", "Path to manifest file")
15+
rootCmd.AddCommand(applyCmd)
16+
}
17+
18+
var applyCmd = &cobra.Command{
19+
Use: "apply",
20+
Short: "Apply resources from manifest file",
21+
RunE: func(cmd *cobra.Command, args []string) error {
22+
ui.Init()
23+
defer func() {
24+
time.Sleep(time.Millisecond * 100)
25+
ui.Stop()
26+
}()
27+
28+
file, err := cmd.Flags().GetString("file")
29+
if err != nil {
30+
ui.Errorf("Failed to parse --file: %s", err.Error())
31+
return err
32+
}
33+
34+
ui.Printf("Applying manifests from: %s", file)
35+
ui.Spinner(true, "Loading manifests")
36+
37+
mans, err := yaml.LoadManifestsFromDir(file)
38+
if err != nil {
39+
ui.Errorf("Failed to load manifests: %s", err.Error())
40+
return err
41+
}
42+
43+
ui.Spinner(false)
44+
ui.Printf("Loaded %d manifests", len(mans))
45+
46+
slices.Reverse(mans)
47+
for i, man := range mans {
48+
ui.Printf("#%d ID: %s", i+1, man.GetID())
49+
}
50+
51+
ui.Spinner(true, "Generating execution plan")
52+
53+
if err = depends.GeneratePlan("./examples/simple", mans); err != nil {
54+
ui.Errorf("Failed to generate plan: %s", err.Error())
55+
return err
56+
}
57+
58+
ui.Spinner(false)
59+
ui.Print("Execution plan generated successfully")
60+
ui.Spinner(true, "Saving manifests...")
61+
62+
if err := yaml.SaveManifests(file, mans...); err != nil {
63+
ui.Error("Failed to save manifests: " + err.Error())
64+
return err
65+
}
66+
67+
ui.Spinner(false)
68+
ui.Println("Manifests applied successfully")
69+
70+
return nil
71+
},
72+
}

cmd/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ func Execute() {
1313

1414
func init() {
1515
rootCmd.AddCommand(versionCmd)
16-
rootCmd.AddCommand(runCmd)
1716
}

cmd/run.go

Lines changed: 0 additions & 108 deletions
This file was deleted.

examples/simple/combined.yaml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
version: 1
2+
kind: Service
3+
metadata:
4+
name: simple-service
5+
namespace: default
6+
dependsOn:
7+
- default.Server.simple-server
8+
spec:
9+
containers:
10+
- name: users-service
11+
containerName: users
12+
dockerfile: some_path
13+
image: some_path
14+
ports:
15+
- 8080:8080
16+
- 50051:50051
17+
env:
18+
clean: clean-command
19+
db_url: postgres:5432
20+
run: run-command
21+
replicas: 3
22+
healthPath: /health
23+
- name: auth-service
24+
containerName: auth
25+
dockerfile: some_path
26+
image: some_path
27+
ports:
28+
- 8081:8081
29+
- 50052:50052
30+
env:
31+
db_url: postgres:5432
32+
replicas: 6
33+
healthPath: /health
34+
---
35+
version: 1
36+
kind: Server
37+
metadata:
38+
name: simple-server
39+
namespace: default
40+
spec:
41+
baseUrl: http://localhost:8080
42+
headers:
43+
Content-Type: application/json
44+
---
45+
version: 1
46+
kind: HttpTest
47+
metadata:
48+
name: simple-http-test
49+
namespace: default
50+
dependsOn:
51+
- default.Service.simple-service
52+
spec:
53+
server: simple-server
54+
cases:
55+
- name: user-register
56+
method: POST
57+
endpoint: /register
58+
headers:
59+
Authorization: some_jwt_token
60+
type: some_data
61+
body:
62+
email: example_email
63+
password: example_password
64+
username: example_username
65+
expected:
66+
code: 201
67+
message: User successfully registered
68+
timeout: 1s
69+
async: true
70+
repeats: 20
71+
- name: user-login
72+
method: GET
73+
endpoint: /login
74+
body:
75+
email: example_email
76+
password: example_password
77+
expected:
78+
code: 200
79+
- name: user-fetch
80+
method: GET
81+
endpoint: /users/{id}
82+
expected:
83+
code: 404
84+
message: User not found
85+
---
86+
version: 1
87+
kind: HttpLoadTest
88+
metadata:
89+
name: simple-http-load-test
90+
namespace: default
91+
dependsOn:
92+
- default.HttpTest.simple-http-test
93+
spec:
94+
cases:
95+
- name: user-login
96+
method: GET
97+
endpoint: /login
98+
body:
99+
email: example_email
100+
password: example_password
101+
expected:
102+
code: 200
103+
- name: user-fetch
104+
method: GET
105+
endpoint: /users/{id}
106+
expected:
107+
code: 404
108+
message: User not found
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"order": [
3+
"default.Server.simple-server",
4+
"default.Service.simple-service",
5+
"default.HttpTest.simple-http-test",
6+
"default.HttpLoadTest.simple-http-load-test"
7+
]
8+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: 1
2+
3+
kind: HttpLoadTest
4+
5+
metadata:
6+
name: simple-http-load-test
7+
8+
spec:
9+
cases:
10+
- name: user-login
11+
method: GET
12+
endpoint: /login
13+
body:
14+
email: "example_email"
15+
password: "example_password"
16+
expected:
17+
code: 200
18+
19+
- name: user-fetch
20+
method: GET
21+
endpoint: /users/{id}
22+
expected:
23+
code: 404
24+
message: "User not found"
25+
26+
dependsOn:
27+
- default.HttpTest.simple-http-test

examples/simple/http_test.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: 1
2+
3+
kind: HttpTest
4+
5+
metadata:
6+
name: simple-http-test
7+
8+
spec:
9+
server: simple-server
10+
cases:
11+
- name: user-register
12+
method: POST
13+
endpoint: /register
14+
headers:
15+
type: some_data
16+
Authorization: some_jwt_token
17+
body:
18+
username: "example_username"
19+
email: "example_email"
20+
password: "example_password"
21+
expected:
22+
code: 201
23+
message: "User successfully registered"
24+
timeout: 1s
25+
async: true
26+
repeats: 20
27+
28+
- name: user-login
29+
method: GET
30+
endpoint: /login
31+
body:
32+
email: "example_email"
33+
password: "example_password"
34+
expected:
35+
code: 200
36+
37+
- name: user-fetch
38+
method: GET
39+
endpoint: /users/{id}
40+
expected:
41+
code: 404
42+
message: "User not found"
43+
44+
dependsOn:
45+
- default.Service.simple-service

examples/simple/server.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 1
2+
3+
kind: Server
4+
5+
metadata:
6+
name: simple-server
7+
8+
spec:
9+
baseUrl: "http://localhost:8080"
10+
headers:
11+
Content-Type: application/json

0 commit comments

Comments
 (0)