mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-02 09:36:19 +00:00
seedling: Webui enhancements (#620)
* 🌱 Make sure webui starts on alpine Also drop to shell when there are no providers Signed-off-by: mudler <mudler@c3os.io> * 🌱 Suppress verbose logging on tty Signed-off-by: mudler <mudler@c3os.io> * 🌱 Print WebUI address Signed-off-by: mudler <mudler@c3os.io> * 🎨 Update banner Signed-off-by: mudler <mudler@c3os.io> * 🌱 Refactor, display also interfaces Signed-off-by: mudler <mudler@c3os.io> * 🌱 Address feedback from review Signed-off-by: mudler <mudler@c3os.io> Signed-off-by: mudler <mudler@c3os.io>
This commit is contained in:
committed by
Itxaka
parent
d59892c5c5
commit
667fd76d9d
@@ -18,6 +18,11 @@ type WebUI struct {
|
|||||||
Disable bool `yaml:"disable"`
|
Disable bool `yaml:"disable"`
|
||||||
ListenAddress string `yaml:"listen_address"`
|
ListenAddress string `yaml:"listen_address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w WebUI) HasAddress() bool {
|
||||||
|
return w.ListenAddress != ""
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Fast bool `yaml:"fast,omitempty"`
|
Fast bool `yaml:"fast,omitempty"`
|
||||||
WebUI WebUI `yaml:"webui"`
|
WebUI WebUI `yaml:"webui"`
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -38,6 +39,28 @@ func optsToArgs(options map[string]string) (res []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func displayInfo(agentConfig *Config) {
|
||||||
|
fmt.Println("--------------------------")
|
||||||
|
fmt.Println("No providers found, dropping to a shell. \n -- For instructions on how to install manually, see: https://kairos.io/docs/installation/manual/")
|
||||||
|
if !agentConfig.WebUI.Disable {
|
||||||
|
if !agentConfig.WebUI.HasAddress() {
|
||||||
|
ips := machine.LocalIPs()
|
||||||
|
if len(ips) > 0 {
|
||||||
|
fmt.Print("WebUI installer running at : ")
|
||||||
|
for _, ip := range ips {
|
||||||
|
fmt.Printf("%s%s ", ip, config.DefaultWebUIListenAddress)
|
||||||
|
}
|
||||||
|
fmt.Print("\n")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("WebUI installer running at : %s\n", agentConfig.WebUI.ListenAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
ifaces := machine.Interfaces()
|
||||||
|
fmt.Printf("Network Interfaces: %s\n", strings.Join(ifaces, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ManualInstall(config string, options map[string]string) error {
|
func ManualInstall(config string, options map[string]string) error {
|
||||||
dat, err := os.ReadFile(config)
|
dat, err := os.ReadFile(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -88,7 +111,7 @@ func Install(dir ...string) error {
|
|||||||
|
|
||||||
// Reads config, and if present and offline is defined,
|
// Reads config, and if present and offline is defined,
|
||||||
// runs the installation
|
// runs the installation
|
||||||
cc, err := config.Scan(config.Directories(dir...), config.MergeBootLine)
|
cc, err := config.Scan(config.Directories(dir...), config.MergeBootLine, config.NoLogs)
|
||||||
if err == nil && cc.Install != nil && cc.Install.Auto {
|
if err == nil && cc.Install != nil && cc.Install.Auto {
|
||||||
r["cc"] = cc.String()
|
r["cc"] = cc.String()
|
||||||
r["device"] = cc.Install.Device
|
r["device"] = cc.Install.Device
|
||||||
@@ -110,14 +133,23 @@ func Install(dir ...string) error {
|
|||||||
fmt.Printf("- config not found in the system: %s", err.Error())
|
fmt.Printf("- config not found in the system: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = bus.Manager.Publish(events.EventChallenge, events.EventPayload{Config: cc.String()})
|
agentConfig, err := LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try to clear screen
|
||||||
|
cmd.ClearScreen()
|
||||||
cmd.PrintBranding(DefaultBanner)
|
cmd.PrintBranding(DefaultBanner)
|
||||||
|
|
||||||
agentConfig, err := LoadConfig()
|
// If there are no providers registered, we enter a shell for manual installation and print information about
|
||||||
|
// the webUI
|
||||||
|
if !bus.Manager.HasRegisteredPlugins() {
|
||||||
|
displayInfo(agentConfig)
|
||||||
|
return utils.Shell().Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = bus.Manager.Publish(events.EventChallenge, events.EventPayload{Config: cc.String()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,10 @@ func (b *Bus) LoadProviders() {
|
|||||||
b.Manager.Autoload("agent-provider", "/system/providers", "/usr/local/system/providers", wd).Register()
|
b.Manager.Autoload("agent-provider", "/system/providers", "/usr/local/system/providers", wd).Register()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bus) HasRegisteredPlugins() bool {
|
||||||
|
return len(b.Plugins) > 0
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Bus) Initialize() {
|
func (b *Bus) Initialize() {
|
||||||
if b.registered {
|
if b.registered {
|
||||||
return
|
return
|
||||||
|
@@ -15,14 +15,18 @@ func PrintText(f string, banner string) {
|
|||||||
f)
|
f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClearScreen() {
|
||||||
|
fmt.Print("\033c")
|
||||||
|
}
|
||||||
|
|
||||||
func PrintBranding(b []byte) {
|
func PrintBranding(b []byte) {
|
||||||
brandingFile := kairos.BrandingFile("banner")
|
brandingFile := kairos.BrandingFile("banner")
|
||||||
if _, err := os.Stat(brandingFile); err == nil {
|
if _, err := os.Stat(brandingFile); err == nil {
|
||||||
f, err := os.ReadFile(brandingFile)
|
f, err := os.ReadFile(brandingFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Println(string(f))
|
fmt.Println(string(f))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
utils.PrintBanner(b)
|
utils.PrintBanner(b)
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kairos-io/kairos/internal/agent"
|
"github.com/kairos-io/kairos/internal/agent"
|
||||||
|
"github.com/kairos-io/kairos/pkg/config"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
process "github.com/mudler/go-processmanager"
|
process "github.com/mudler/go-processmanager"
|
||||||
"github.com/nxadm/tail"
|
"github.com/nxadm/tail"
|
||||||
@@ -134,7 +135,7 @@ func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c
|
|||||||
func Start(ctx context.Context) error {
|
func Start(ctx context.Context) error {
|
||||||
|
|
||||||
s := state{}
|
s := state{}
|
||||||
listen := ":8080"
|
listen := config.DefaultWebUIListenAddress
|
||||||
|
|
||||||
ec := echo.New()
|
ec := echo.New()
|
||||||
assetHandler := http.FileServer(getFileSystem())
|
assetHandler := http.FileServer(getFileSystem())
|
||||||
|
Reference in New Issue
Block a user