shoebill/cmd/sync.go

53 lines
1.5 KiB
Go
Raw Normal View History

2023-07-20 09:26:25 +00:00
package cmd
import (
2023-08-02 15:00:34 +00:00
"git.badhouseplants.net/allanger/shoebill/internal/controller"
2023-07-20 09:26:25 +00:00
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var (
sync = &cobra.Command{
Use: "sync",
Short: "sync does something",
Long: ``,
Run: syncCmd,
}
)
func init() {
sync.Flags().StringP("config", "c", "config.yaml", "A path to the configuration file")
sync.Flags().String("workdir", "", "A path to the workdir. On the moment of running, it should be an empty dir")
sync.Flags().String("ssh-key", "", "A path to the pricate ssh key")
2023-10-13 16:02:11 +00:00
sync.Flags().Bool("dry-run", false, "If set to false, will not push changes to git")
2023-10-20 11:31:30 +00:00
sync.Flags().String("diff", "main", "If values us set, will show helm diffs for not preserved charts, values will be taken from the target branch")
2023-10-11 12:14:20 +00:00
sync.Flags().String("sops-bin", "/usr/bin/sops", "A path to the sops binary in your system")
2023-07-20 09:26:25 +00:00
rootCmd.AddCommand(sync)
}
func syncCmd(cmd *cobra.Command, args []string) {
config := cmd.Flag("config").Value.String()
workdir := cmd.Flag("workdir").Value.String()
sshKey := cmd.Flag("ssh-key").Value.String()
2023-10-11 12:14:20 +00:00
sopsBin := cmd.Flag("sops-bin").Value.String()
2023-07-20 09:26:25 +00:00
dryRun, err := cmd.Flags().GetBool("dry-run")
2023-10-20 11:31:30 +00:00
diff, err := cmd.Flags().GetString("diff")
2023-07-20 09:26:25 +00:00
if err != nil {
logrus.Fatal(err)
}
configObj, err := controller.ReadTheConfig(config)
if err != nil {
logrus.Fatal(err)
}
2023-10-11 12:14:20 +00:00
configObj.SopsBin = sopsBin
2023-07-20 09:26:25 +00:00
2023-10-13 16:02:11 +00:00
err = controller.Sync(workdir, sshKey, configObj, dryRun, diff)
2023-07-20 09:26:25 +00:00
if err != nil {
logrus.Fatal(err)
}
logrus.Info("your config is synced")
}