Skip to content

Commit 382ef3a

Browse files
added start-pixie command in the auroraboot command (#331)
* added pixiecore bootcmd for only starting the pixiecore server * added new start pixie * Updated code for a cleaner looker + included a unit test for start pixit + update usage information for clarity on usage.
1 parent 3780014 commit 382ef3a

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

internal/cmd/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func GetApp(version string) *cli.App {
5151
&GenKeyCmd,
5252
&SysextCmd,
5353
&NetBootCmd,
54+
&StartPixieCmd,
5455
&WebCMD,
5556
&RedFishDeployCmd,
5657
&WorkerCmd,

internal/cmd/start-pixie.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/kairos-io/AuroraBoot/internal"
6+
"github.com/kairos-io/AuroraBoot/pkg/ops"
7+
"github.com/kairos-io/AuroraBoot/pkg/schema"
8+
"github.com/kairos-io/kairos-sdk/types"
9+
"github.com/urfave/cli/v2"
10+
)
11+
12+
var StartPixieCmd = cli.Command{
13+
Name: "start-pixie",
14+
Aliases: []string{"sp"},
15+
Usage: "Start the Pixiecore netboot server and serve custom PXE files (kernel, initrd, squashfs) with a cloud-config.",
16+
Description: `Start a Pixiecore-based PXE server to serve a kernel, initrd, and squashfs image for network booting.
17+
18+
Arguments:
19+
cloud-config-file Path to the cloud-init or cloud-config YAML file.
20+
squashfs-file Path to the root filesystem squashfs image.
21+
address IP address to bind the server (e.g., 0.0.0.0).
22+
port Port for the netboot server (e.g., 8080).
23+
initrd-file Path to the initrd image.
24+
kernel-file Path to the kernel image.
25+
26+
Options:
27+
--debug Enable debug logging for troubleshooting.
28+
29+
Example:
30+
start-pixie user-data.yaml rootfs.squashfs 0.0.0.0 8080 initrd.img vmlinuz --debug
31+
`,
32+
ArgsUsage: "<cloud-config-file> <squashfs-file> <address> <port> <initrd-file> <kernel-file>",
33+
Flags: []cli.Flag{
34+
&cli.BoolFlag{
35+
Name: "debug",
36+
Usage: "Enable debug logging",
37+
},
38+
// Add more flags for optional NetBoot struct fields as needed
39+
},
40+
Action: func(c *cli.Context) error {
41+
cloudConfigFile := c.Args().Get(0)
42+
squashFSfile := c.Args().Get(1)
43+
address := c.Args().Get(2)
44+
netbootPort := c.Args().Get(3)
45+
initrdFile := c.Args().Get(4)
46+
kernelFile := c.Args().Get(5)
47+
48+
// Simple argument validation
49+
if cloudConfigFile == "" || squashFSfile == "" || address == "" || netbootPort == "" || initrdFile == "" || kernelFile == "" {
50+
cli.ShowCommandHelp(c, c.Command.Name)
51+
fmt.Println("")
52+
return fmt.Errorf("all arguments are required")
53+
}
54+
55+
loglevel := "info"
56+
if c.Bool("debug") {
57+
loglevel = "debug"
58+
}
59+
internal.Log = types.NewKairosLogger("AuroraBoot", loglevel, false)
60+
61+
// Optionally parse NetBoot from flags here if desired
62+
nb := schema.NetBoot{} // Use defaults, or parse from CLI flags
63+
64+
f := ops.StartPixiecore(
65+
cloudConfigFile,
66+
address,
67+
netbootPort,
68+
func() string { return squashFSfile }, // Wrap squashFSfile in a function
69+
func() string { return initrdFile }, // Wrap initrdFile in a function
70+
func() string { return kernelFile }, // Wrap kernelFile in a function
71+
nb,
72+
)
73+
74+
return f(c.Context)
75+
},
76+
}

internal/cmd/start-pixie_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cmd_test
2+
3+
import (
4+
"bytes"
5+
cmdpkg "github.com/kairos-io/AuroraBoot/internal/cmd"
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
"github.com/urfave/cli/v2"
9+
)
10+
11+
var _ = Describe("start-pixie", Label("pixie", "cmd"), func() {
12+
var app *cli.App
13+
var err error
14+
var buf *bytes.Buffer
15+
16+
BeforeEach(func() {
17+
buf = new(bytes.Buffer)
18+
app = cmdpkg.GetApp("v0.0.0")
19+
app.Writer = buf
20+
})
21+
22+
It("errors out if no arguments are provided", func() {
23+
err = app.Run([]string{"", "start-pixie"})
24+
Expect(err).ToNot(BeNil())
25+
Expect(err.Error()).To(ContainSubstring("all arguments are required"))
26+
})
27+
28+
It("errors out if only some arguments are provided", func() {
29+
err = app.Run([]string{"", "start-pixie", "cloud.yaml", "rootfs.squashfs"})
30+
Expect(err).ToNot(BeNil())
31+
Expect(err.Error()).To(ContainSubstring("all arguments are required"))
32+
})
33+
34+
It("shows help output", func() {
35+
err = app.Run([]string{"", "start-pixie", "--help"})
36+
Expect(err).To(BeNil())
37+
Expect(buf.String()).To(ContainSubstring("Start the Pixiecore netboot server"))
38+
})
39+
})

0 commit comments

Comments
 (0)