mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-18 13:21:00 +02:00
Initial version of the Orchard orchestration system (#3)
* Initial version of the Orchard orchestration system * Update README.md Co-authored-by: Fedor Korotkov <fedor.korotkov@gmail.com> Co-authored-by: Fedor Korotkov <fedor.korotkov@gmail.com>
This commit is contained in:
co-authored by
Fedor Korotkov
parent
dcbbb8b8de
commit
92e8732d46
@@ -0,0 +1,29 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/cirruslabs/orchard/internal/orchardhome"
|
||||
"github.com/spf13/cobra"
|
||||
"log"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var dataDir string
|
||||
|
||||
func NewCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "controller",
|
||||
Short: "Initialize and run a controller on the local machine",
|
||||
}
|
||||
|
||||
command.AddCommand(newRunCommand())
|
||||
|
||||
orchardHome, err := orchardhome.Path()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
command.PersistentFlags().StringVar(&dataDir, "data-dir", filepath.Join(orchardHome, "controller"),
|
||||
"path to the data directory")
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/cirruslabs/orchard/internal/controller"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func newRunCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "run",
|
||||
RunE: runController,
|
||||
}
|
||||
}
|
||||
|
||||
func runController(cmd *cobra.Command, args []string) (err error) {
|
||||
// Initialize the logger
|
||||
logger, err := zap.NewProduction()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if syncErr := logger.Sync(); syncErr != nil && err == nil {
|
||||
err = syncErr
|
||||
}
|
||||
}()
|
||||
|
||||
controller, err := controller.New(controller.WithDataDir(dataDir), controller.WithLogger(logger))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return controller.Run(cmd.Context())
|
||||
}
|
||||
Reference in New Issue
Block a user