sparkles: Add bundles to post-install hooks (#171)

* 🤖 Add bundles and sysext test

*  Exec bundles also after install

* 🤖 Adapt tests

* 🎨 Create dir only if doesn't exist

* 🎨 Return err on mount

* 🎨 Make bundle errors failure as an option

* 🎨 Minor fixups

* debug

* 🤖 Fix spec

* 🤖 Get correct version for bundle test

* 🎨 Fixups

* 🤖 systemd-sysext is available only on opensuse for now
This commit is contained in:
Ettore Di Giacinto 2022-10-03 00:16:01 +02:00 committed by Itxaka
parent b1396c541b
commit a8875f6b4f
4 changed files with 39 additions and 18 deletions

View File

@ -63,14 +63,14 @@ func Run(opts ...Option) error {
if !machine.SentinelExist("bundles") {
opts := c.Bundles.Options()
err := bundles.RunBundles(opts...)
if !c.IgnoreBundleErrors && err != nil {
if c.FailOnBundleErrors && err != nil {
return err
}
// Re-load providers
bus.Reload()
err = machine.CreateSentinel("bundles")
if !c.IgnoreBundleErrors && err != nil {
if c.FailOnBundleErrors && err != nil {
return err
}
}

View File

@ -0,0 +1,30 @@
package hook
import (
config "github.com/kairos-io/kairos/pkg/config"
"github.com/kairos-io/kairos/pkg/machine"
"github.com/kairos-io/kairos/sdk/bundles"
)
type BundleOption struct{}
func (b BundleOption) Run(c config.Config) error {
machine.Mount("COS_PERSISTENT", "/usr/local") //nolint:errcheck
defer func() {
machine.Umount("/usr/local")
}()
machine.Mount("COS_OEM", "/oem") //nolint:errcheck
defer func() {
machine.Umount("/oem")
}()
opts := c.Install.Bundles.Options()
err := bundles.RunBundles(opts...)
if c.FailOnBundleErrors && err != nil {
return err
}
return nil
}

View File

@ -2,29 +2,20 @@ package hook
import (
"fmt"
"strings"
config "github.com/kairos-io/kairos/pkg/config"
"github.com/kairos-io/kairos/pkg/machine"
"github.com/kairos-io/kairos/pkg/utils"
)
type GrubOptions struct{}
func (b GrubOptions) Run(c config.Config) error {
oem, _ := utils.SH("blkid -L COS_OEM")
if oem == "" {
fmt.Println("OEM partition not found")
return nil // do not error out
}
oem = strings.TrimSuffix(oem, "\n")
oemMount, err := utils.SH(fmt.Sprintf("mkdir /tmp/oem && mount %s /tmp/oem", oem))
if err != nil {
fmt.Printf("could not mount oem: %s\n", oemMount+err.Error())
return nil // do not error out
}
machine.Mount("COS_OEM", "/tmp/oem") //nolint:errcheck
defer func() {
machine.Umount("/tmp/oem")
}()
for k, v := range c.Install.GrubOptions {
out, err := utils.SH(fmt.Sprintf("grub2-editenv /tmp/oem/grubenv set %s=%s", k, v))
if err != nil {
@ -33,6 +24,5 @@ func (b GrubOptions) Run(c config.Config) error {
}
}
utils.SH("umount /tmp/oem") //nolint:errcheck
return nil
}

View File

@ -11,7 +11,8 @@ type Interface interface {
var All = []Interface{
&RunStage{}, // Shells out to stages defined from the container image
&GrubOptions{}, // Set custom GRUB options
&Lifecycle{}, // Handles poweroff/reboot by config options
&BundleOption{},
&Lifecycle{}, // Handles poweroff/reboot by config options
}
func Run(c config.Config, hooks ...Interface) error {