mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-21 02:09:05 +00:00
Split off cli into separate binaries (#37)
* 🎨 Split off cli into separate binaries This commit splits off the cli into 3 binaries: - agent - cli - provider The provider now is a separate component that can be tested by itself and have its own lifecycle. This paves the way to a ligher c3os variant, HA support and other features that can be provided on runtime. This is working, but still there are low hanging fruit to care about. Fixes #14 * 🤖 Add provider bin to releases * ⚙️ Handle signals * ⚙️ Reduce buildsize footprint * 🎨 Scan for providers also in /system/providers * 🤖 Run goreleaser * 🎨 Refactoring
This commit is contained in:
57
cmd/agent/agent.go
Normal file
57
cmd/agent/agent.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/c3os-io/c3os/internal/bus"
|
||||
"github.com/c3os-io/c3os/internal/utils"
|
||||
events "github.com/c3os-io/c3os/pkg/bus"
|
||||
config "github.com/c3os-io/c3os/pkg/config"
|
||||
"github.com/nxadm/tail"
|
||||
)
|
||||
|
||||
// setup needs edgevpn and k3s installed locally
|
||||
// (both k3s and k3s-agent systemd services)
|
||||
func agent(apiAddress string, dir []string, force bool) error {
|
||||
|
||||
os.MkdirAll("/usr/local/.c3os", 0600)
|
||||
|
||||
// Reads config
|
||||
c, err := config.Scan(dir...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := ioutil.TempFile(os.TempDir(), "c3os")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(f.Name(), []byte{}, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t, err := tail.TailFile(f.Name(), tail.Config{Follow: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer os.RemoveAll(f.Name())
|
||||
|
||||
utils.OnSignal(func() {
|
||||
os.RemoveAll(f.Name())
|
||||
}, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
for line := range t.Lines {
|
||||
fmt.Println(line.Text)
|
||||
}
|
||||
}()
|
||||
|
||||
_, err = bus.Manager.Publish(events.EventBootstrap, events.BootstrapPayload{APIAddress: apiAddress, Config: c.String(), Logfile: f.Name()})
|
||||
return err
|
||||
}
|
Reference in New Issue
Block a user