Skip to content

Commit

Permalink
Introduce the manager
Browse files Browse the repository at this point in the history
  • Loading branch information
nlewo committed Jan 30, 2024
1 parent 196b4e9 commit 91826c5
Show file tree
Hide file tree
Showing 34 changed files with 1,171 additions and 775 deletions.
143 changes: 0 additions & 143 deletions cmd/bootstrap.go

This file was deleted.

10 changes: 9 additions & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"context"

"github.com/nlewo/comin/nix"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -11,6 +13,7 @@ var buildCmd = &cobra.Command{
Short: "Build a machine configuration",
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
ctx := context.TODO()
hosts := make([]string, 1)
if hostname != "" {
hosts[0] = hostname
Expand All @@ -19,7 +22,12 @@ var buildCmd = &cobra.Command{
}
for _, host := range hosts {
logrus.Infof("Building the NixOS configuration of machine '%s'", host)
_, err := nix.Build(flakeUrl, host)

drvPath, _, err := nix.ShowDerivation(ctx, flakeUrl, host)
if err != nil {
logrus.Errorf("Failed to evaluate the configuration '%s': '%s'", host, err)
}
err = nix.Build(ctx, drvPath)
if err != nil {
logrus.Errorf("Failed to build the configuration '%s': '%s'", host, err)
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/eval.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"context"

"github.com/nlewo/comin/nix"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -12,14 +14,15 @@ var evalCmd = &cobra.Command{
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
hosts := make([]string, 1)
ctx := context.TODO()
if hostname != "" {
hosts[0] = hostname
} else {
hosts, _ = nix.List(flakeUrl)
}
for _, host := range hosts {
logrus.Infof("Evaluating the NixOS configuration of machine '%s'", host)
_, _, err := nix.ShowDerivation(flakeUrl, host)
_, _, err := nix.ShowDerivation(ctx, flakeUrl, host)
if err != nil {
logrus.Errorf("Failed to eval the configuration '%s': '%s'", host, err)
}
Expand Down
54 changes: 0 additions & 54 deletions cmd/poll.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2022 lewo <[email protected]>
*/
package cmd

Expand Down
53 changes: 53 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cmd

import (
"os"

"github.com/nlewo/comin/config"
"github.com/nlewo/comin/http"
"github.com/nlewo/comin/manager"
"github.com/nlewo/comin/poller"
"github.com/nlewo/comin/repository"
"github.com/nlewo/comin/utils"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var configFilepath string

var runCmd = &cobra.Command{
Use: "run",
Short: "Run comin to deploy your published configurations",
Run: func(cmd *cobra.Command, args []string) {
cfg, err := config.Read(configFilepath)
if err != nil {
logrus.Error(err)
os.Exit(1)
}
gitConfig := config.MkGitConfig(cfg)

repositoryStatus := repository.RepositoryStatus{}
repository, err := repository.New(gitConfig, repositoryStatus)
if err != nil {
logrus.Errorf("Failed to initialize the repository: %s", err)
os.Exit(1)
}

machineId, err := utils.ReadMachineId()
if err != nil {
logrus.Error(err)
os.Exit(1)
}

manager := manager.New(repository, gitConfig.Path, cfg.Hostname, machineId)
go poller.Poller(manager, cfg.Remotes)
go http.Serve(manager, cfg.HttpServer.Address, cfg.HttpServer.Port)
manager.Run()
},
}

func init() {
runCmd.PersistentFlags().StringVarP(&configFilepath, "config", "", "", "the configuration file path")
runCmd.MarkPersistentFlagRequired("config")
rootCmd.AddCommand(runCmd)
}
Loading

0 comments on commit 91826c5

Please sign in to comment.