Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
boppanasusanth committed Apr 29, 2024
1 parent a64fe47 commit 258a75f
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 469 deletions.
2 changes: 1 addition & 1 deletion cmd/delete/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func init() {
if err != nil {
log.Fatal("Error marking 'name' flag as required:", err)
}

deleteCmd.AddCommand(environmentCmd)
}

Expand Down
27 changes: 9 additions & 18 deletions cmd/deploy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package deploy

import (
"encoding/json"
"os"

"github.com/dream11/odin/internal/service"
serviceProto "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"io/ioutil"
"os"
)

var env string
var provisioning string
var file string
var definitionFile string
var provisioningFile string

var serviceClient = service.Service{}

Expand All @@ -30,8 +30,8 @@ var serviceCmd = &cobra.Command{

func init() {
serviceCmd.Flags().StringVar(&env, "env", "", "environment for deploying the service")
serviceCmd.Flags().StringVar(&file, "file", "", "path to the service definition file")
serviceCmd.Flags().StringVar(&provisioning, "provisioning", "", "path to the provisioning file")
serviceCmd.Flags().StringVar(&definitionFile, "file", "", "path to the service definition file")
serviceCmd.Flags().StringVar(&provisioningFile, "provisioning", "", "path to the provisioning file")
err := serviceCmd.MarkFlagRequired("env")
if err != nil {
log.Println("Error marking 'env' flag as required:", err)
Expand All @@ -44,11 +44,11 @@ func init() {
func execute(cmd *cobra.Command) {
ctx := cmd.Context()

definitionData, err := readFromFile(file)
definitionData, err := readFromFile(definitionFile)
if err != nil {
log.Fatal("Error while reading definition file ", err)
}
provisioningData, err := readFromFile(provisioning)
provisioningData, err := readFromFile(provisioningFile)

if err != nil {
log.Fatal("Error while reading provisioning file ", err)
Expand All @@ -63,22 +63,15 @@ func execute(cmd *cobra.Command) {
if err != nil {
log.Fatal("Failed to deploy service ", err)
}

//outputFormat, err := cmd.Flags().GetString("output")
//if err != nil {
// log.Fatal(err)
//}
}

func readFromFile(filePath string) (string, error) {
// Read the file
content, err := ioutil.ReadFile(filePath)
content, err := os.ReadFile(filePath)
if err != nil {
log.Println("Error reading file:", err)
return "", err
}

// Validate if the contents are valid JSON
var jsonData interface{}
err = json.Unmarshal(content, &jsonData)
if err != nil {
Expand All @@ -87,14 +80,12 @@ func readFromFile(filePath string) (string, error) {

}

// Convert the JSON content to a string
jsonString, err := json.MarshalIndent(jsonData, "", " ")
if err != nil {
log.Println("Error converting JSON to string:", err)
return "", err

}

// Print the resulting string
return string(jsonString), nil
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ go 1.17

require github.com/olekukonko/tablewriter v0.0.5

require github.com/briandowns/spinner v1.23.0

require (
github.com/briandowns/spinner v1.23.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
Expand All @@ -25,7 +26,6 @@ require (
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -38,5 +38,5 @@ require (
golang.org/x/net v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
google.golang.org/protobuf v1.33.0
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@ github.com/lyft/protoc-gen-star/v2 v2.0.1/go.mod h1:RcCdONR2ScXaYnQC5tUzxzlpA3WV
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand All @@ -1065,9 +1066,9 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
Expand Down Expand Up @@ -1898,8 +1899,6 @@ google.golang.org/grpc v1.56.2/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpX
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand All @@ -1917,8 +1916,9 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
2 changes: 1 addition & 1 deletion internal/service/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (e *Environment) CreateEnvironment(ctx *context.Context, request *environme
return err
}

// DeleteEnvironment : Delete environment
// DeleteEnvironment deletes environment
func (e *Environment) DeleteEnvironment(ctx *context.Context, request *environment.DeleteEnvironmentRequest) error {
conn, requestCtx, err := grpcClient(ctx)
if err != nil {
Expand Down
29 changes: 22 additions & 7 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package service

import (
"context"
"errors"
"fmt"
"io"

"github.com/briandowns/spinner"
"github.com/dream11/odin/pkg/constant"
service "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1"
log "github.com/sirupsen/logrus"
)
Expand All @@ -22,21 +27,31 @@ func (e *Service) DeployService(ctx *context.Context, request *service.DeploySer
return err
}

// Receive and process streaming responses
log.Info("Deploying Service...")
spinner := spinner.New(spinner.CharSets[constant.SpinnerType], constant.SpinnerDelay)
err = spinner.Color(constant.SpinnerColor, constant.SpinnerStyle)
if err != nil {
return err
}

var message string
for {
response, err := stream.Recv()
spinner.Stop()
if err != nil {
// Check for the end of the stream
if err == context.Canceled {
if errors.Is(err, context.Canceled) || err == io.EOF {
break
}

log.Fatalf("Error receiving stream: %v", err)
return err
}

// Process the received stream
fmt.Println("Received DeployServiceResponse:", response)
if response != nil {
message = response.Message
spinner.Prefix = fmt.Sprintf(" %s ", response.Message)
spinner.Start()
}
}

log.Info(message)
return err
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
_ "github.com/dream11/odin/cmd/configure"
_ "github.com/dream11/odin/cmd/create"
_ "github.com/dream11/odin/cmd/delete"
_ "github.com/dream11/odin/cmd/deploy"
_ "github.com/dream11/odin/cmd/list"
_ "github.com/dream11/odin/internal/ui"
)
Expand Down
8 changes: 7 additions & 1 deletion proto/dream11/od/dto/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ message ComponentDefinition {
string name = 1;
string version = 2;
string type = 3;
google.protobuf.Struct config = 4;
repeated string depends_on = 4;
google.protobuf.Struct config = 5;
optional google.protobuf.Struct metadata = 6;
}

message ServiceDefinition {
Expand All @@ -24,3 +26,7 @@ message ComponentProvisioningConfig {
string deployment_type = 2;
google.protobuf.Struct params = 3;
}

message ProvisioningConfig {
repeated ComponentProvisioningConfig component_provisioning_config = 1;
}
42 changes: 11 additions & 31 deletions proto/dream11/od/service/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dream11.od.service.v1;

option go_package = "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1";


service ServiceService {
rpc DeployService(DeployServiceRequest) returns (stream DeployServiceResponse) {}
}
Expand All @@ -15,39 +14,20 @@ message DeployServiceRequest {
}

message DeployServiceResponse {
enum TYPE{
INFO = 0;
STATUS = 1;
}
TYPE type = 2;
Body body = 3;
}

message Body{
oneof response_body{
StatusBody status_body = 1;
InfoBody info_body = 2;
}
ServiceStatus service_status = 1;
repeated ComponentStatus components_status = 2;
string message = 3;
}

message StatusBody {
int64 id = 1;
string status = 2;
string action = 3;
repeated ComponentStatus component_status = 4;
message ServiceStatus {
string service_status = 1;
string service_action = 2;
string error = 3;
}

message ComponentStatus {
int64 component_id = 1;
string status = 2;
string action = 3;
string response = 4;
string component_name = 1;
string component_status = 2;
string component_action = 3;
string error = 4;
}

message InfoBody {
int64 id = 1;
string status = 2;
string action = 3;
string info_message = 4;
}

Loading

0 comments on commit 258a75f

Please sign in to comment.