-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add undeploy service command (#227)
* Feat: Add undeploy cli command * Fix:undeloy service log * Fix: lint undeloy service * Fix: lint undeloy service --------- Co-authored-by: Susanth <[email protected]>
- Loading branch information
1 parent
76f1b99
commit 9fc780a
Showing
9 changed files
with
509 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package deploy | ||
|
||
import ( | ||
"github.com/dream11/odin/cmd" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var deployCmd = &cobra.Command{ | ||
Use: "deploy", | ||
Short: "Deploy resources", | ||
Long: `Deploy resources`, | ||
} | ||
|
||
func init() { | ||
cmd.RootCmd.AddCommand(deployCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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" | ||
) | ||
|
||
var env string | ||
var definitionFile string | ||
var provisioningFile string | ||
|
||
var serviceClient = service.Service{} | ||
|
||
var serviceCmd = &cobra.Command{ | ||
Use: "Deploy service", | ||
Short: "Deploy service", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
return cobra.NoArgs(cmd, args) | ||
}, | ||
Long: "Deploy service using files or service name", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
execute(cmd) | ||
}, | ||
} | ||
|
||
func init() { | ||
serviceCmd.Flags().StringVar(&env, "env", "", "environment for deploying the service") | ||
serviceCmd.Flags().StringVar(&definitionFile, "file", "", "path to the service definition file") | ||
serviceCmd.Flags().StringVar(&provisioningFile, "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) | ||
os.Exit(1) | ||
} | ||
|
||
deployCmd.AddCommand(serviceCmd) | ||
} | ||
|
||
func execute(cmd *cobra.Command) { | ||
ctx := cmd.Context() | ||
|
||
definitionData, err := readFromFile(definitionFile) | ||
if err != nil { | ||
log.Fatal("Error while reading definition file ", err) | ||
} | ||
provisioningData, err := readFromFile(provisioningFile) | ||
|
||
if err != nil { | ||
log.Fatal("Error while reading provisioning file ", err) | ||
} | ||
|
||
err = serviceClient.DeployService(&ctx, &serviceProto.DeployServiceRequest{ | ||
EnvName: env, | ||
ServiceDefinition: definitionData, | ||
ProvisioningConfig: provisioningData, | ||
}) | ||
|
||
if err != nil { | ||
log.Fatal("Failed to deploy service ", err) | ||
} | ||
} | ||
|
||
func readFromFile(filePath string) (string, error) { | ||
content, err := os.ReadFile(filePath) | ||
if err != nil { | ||
log.Println("Error reading file:", err) | ||
return "", err | ||
} | ||
|
||
var jsonData interface{} | ||
err = json.Unmarshal(content, &jsonData) | ||
if err != nil { | ||
log.Println("Error decoding JSON:", err) | ||
return "", err | ||
|
||
} | ||
|
||
jsonString, err := json.MarshalIndent(jsonData, "", " ") | ||
if err != nil { | ||
log.Println("Error converting JSON to string:", err) | ||
return "", err | ||
|
||
} | ||
|
||
return string(jsonString), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.