Skip to content

Commit 0a78580

Browse files
committed
fix: overlay installer operations
1. Use overlay installer to build the `cmdline` when running in install/upgrade mode. 2. Pull down the overlay installer with the arch specific to the installer being generated, vs. the arch of the `imager`. 3. Print a message when running an overlay installer. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent b1b63f6 commit 0a78580

File tree

5 files changed

+64
-24
lines changed

5 files changed

+64
-24
lines changed

cmd/installer/cmd/imager/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ var rootCmd = &cobra.Command{
124124
},
125125
ExtraOptions: extraOverlayOptions,
126126
}
127+
128+
prof.Input.OverlayInstaller.ImageRef = cmdFlags.OverlayImage
127129
}
128130

129131
prof.Input.SystemExtensions = xslices.Map(

cmd/installer/cmd/installer/root.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,21 @@ func Execute() {
4848
}
4949
}
5050

51-
var options = &install.Options{}
51+
var options = &install.Options{
52+
Board: constants.BoardNone,
53+
}
5254

53-
var bootloader bool
55+
var (
56+
bootloader bool
57+
dummy string
58+
)
5459

5560
func init() {
5661
rootCmd.PersistentFlags().StringVar(&options.ConfigSource, "config", "", "The value of "+constants.KernelParamConfig)
5762
rootCmd.PersistentFlags().StringVar(&options.Disk, "disk", "", "The path to the disk to install to")
5863
rootCmd.PersistentFlags().StringVar(&options.Platform, "platform", "", "The value of "+constants.KernelParamPlatform)
5964
rootCmd.PersistentFlags().StringVar(&options.Arch, "arch", runtime.GOARCH, "The target architecture")
60-
rootCmd.PersistentFlags().StringVar(&options.Board, "board", constants.BoardNone, "Deprecated: no op")
65+
rootCmd.PersistentFlags().StringVar(&dummy, "board", constants.BoardNone, "Deprecated: no op")
6166
rootCmd.PersistentFlags().StringArrayVar(&options.ExtraKernelArgs, "extra-kernel-arg", []string{}, "Extra argument to pass to the kernel")
6267
rootCmd.PersistentFlags().BoolVar(&bootloader, "bootloader", true, "Deprecated: no op")
6368
rootCmd.PersistentFlags().BoolVar(&options.Upgrade, "upgrade", false, "Indicates that the install is being performed by an upgrade")

cmd/installer/pkg/install/install.go

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Options struct {
4747
LegacyBIOSSupport bool
4848
MetaValues MetaValues
4949
OverlayInstaller overlay.Installer[overlay.ExtraOptions]
50+
OverlayName string
5051
OverlayExtractedDir string
5152
ExtraOptions overlay.ExtraOptions
5253

@@ -85,6 +86,25 @@ func Install(ctx context.Context, p runtime.Platform, mode Mode, opts *Options)
8586
return fmt.Errorf("using standard installer image is not supported for board: %s, use an installer with overlay", b)
8687
}
8788

89+
if overlayPresent {
90+
extraOptionsBytes, err := os.ReadFile(constants.ImagerOverlayExtraOptionsPath)
91+
if err != nil {
92+
return err
93+
}
94+
95+
var extraOptions overlay.ExtraOptions
96+
97+
decoder := yaml.NewDecoder(bytes.NewReader(extraOptionsBytes))
98+
decoder.KnownFields(true)
99+
100+
if err := decoder.Decode(&extraOptions); err != nil {
101+
return fmt.Errorf("failed to decode extra options: %w", err)
102+
}
103+
104+
opts.OverlayInstaller = executor.New(constants.ImagerOverlayInstallerDefaultPath)
105+
opts.ExtraOptions = extraOptions
106+
}
107+
88108
cmdline := procfs.NewCmdline("")
89109
cmdline.Append(constants.KernelParamPlatform, p.Name())
90110

@@ -117,6 +137,17 @@ func Install(ctx context.Context, p runtime.Platform, mode Mode, opts *Options)
117137
cmdline.SetAll(b.KernelArgs().Strings())
118138
}
119139

140+
if opts.OverlayInstaller != nil {
141+
overlayOpts, getOptsErr := opts.OverlayInstaller.GetOptions(opts.ExtraOptions)
142+
if getOptsErr != nil {
143+
return fmt.Errorf("failed to get overlay installer options: %w", getOptsErr)
144+
}
145+
146+
opts.OverlayName = overlayOpts.Name
147+
148+
cmdline.SetAll(overlayOpts.KernelArgs)
149+
}
150+
120151
if err := cmdline.AppendAll(
121152
opts.ExtraKernelArgs,
122153
procfs.WithOverwriteArgs("console"),
@@ -126,25 +157,6 @@ func Install(ctx context.Context, p runtime.Platform, mode Mode, opts *Options)
126157
return err
127158
}
128159

129-
if overlayPresent {
130-
extraOptionsBytes, err := os.ReadFile(constants.ImagerOverlayExtraOptionsPath)
131-
if err != nil {
132-
return err
133-
}
134-
135-
var extraOptions overlay.ExtraOptions
136-
137-
decoder := yaml.NewDecoder(bytes.NewReader(extraOptionsBytes))
138-
decoder.KnownFields(true)
139-
140-
if err := decoder.Decode(&extraOptions); err != nil {
141-
return fmt.Errorf("failed to decode extra options: %w", err)
142-
}
143-
144-
opts.OverlayInstaller = executor.New(constants.ImagerOverlayInstallerDefaultPath)
145-
opts.ExtraOptions = extraOptions
146-
}
147-
148160
i, err := NewInstaller(ctx, cmdline, mode, opts)
149161
if err != nil {
150162
return err
@@ -338,6 +350,8 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {
338350
}
339351

340352
if i.options.OverlayInstaller != nil {
353+
i.options.Printf("running overlay installer %q", i.options.OverlayName)
354+
341355
if err = i.options.OverlayInstaller.Install(overlay.InstallOptions[overlay.ExtraOptions]{
342356
InstallDisk: i.options.Disk,
343357
MountPrefix: i.options.MountPrefix,

pkg/imager/out.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,21 @@ func (i *Imager) outInstaller(ctx context.Context, path string, report *reporter
411411
}
412412

413413
if i.overlayInstaller != nil {
414+
tempOverlayPath := filepath.Join(i.tempDir, "overlay-installer", constants.ImagerOverlayBasePath)
415+
416+
if err := os.MkdirAll(tempOverlayPath, 0o755); err != nil {
417+
return fmt.Errorf("failed to create overlay directory: %w", err)
418+
}
419+
420+
if err := i.prof.Input.OverlayInstaller.Extract(
421+
ctx,
422+
tempOverlayPath,
423+
i.prof.Arch,
424+
progressPrintf(report, reporter.Update{Message: "pulling overlay for installer...", Status: reporter.StatusRunning}),
425+
); err != nil {
426+
return err
427+
}
428+
414429
extraOpts, internalErr := yaml.Marshal(i.prof.Overlay.ExtraOptions)
415430
if internalErr != nil {
416431
return fmt.Errorf("failed to marshal extra options: %w", internalErr)
@@ -430,11 +445,11 @@ func (i *Imager) outInstaller(ctx context.Context, path string, report *reporter
430445
mode os.FileMode
431446
}{
432447
{
433-
sourcePath: filepath.Join(i.tempDir, constants.ImagerOverlayArtifactsPath),
448+
sourcePath: filepath.Join(i.tempDir, "overlay-installer", constants.ImagerOverlayArtifactsPath),
434449
imagePath: strings.TrimLeft(constants.ImagerOverlayArtifactsPath, "/"),
435450
},
436451
{
437-
sourcePath: filepath.Join(i.tempDir, constants.ImagerOverlayInstallersPath, i.prof.Overlay.Name),
452+
sourcePath: filepath.Join(i.tempDir, "overlay-installer", constants.ImagerOverlayInstallersPath, i.prof.Overlay.Name),
438453
imagePath: strings.TrimLeft(constants.ImagerOverlayInstallerDefaultPath, "/"),
439454
mode: 0o755,
440455
},

pkg/imager/profile/input.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ type Input struct {
5454
RPiFirmware FileAsset `yaml:"rpiFirmware,omitempty"`
5555
// Base installer image to mutate.
5656
BaseInstaller ContainerAsset `yaml:"baseInstaller,omitempty"`
57+
// OverlayInstaller is an overlay image to inject into the installer.
58+
//
59+
// OverlayInstaller architecture should match the output installer architecture.
60+
OverlayInstaller ContainerAsset `yaml:"overlayInstaller,omitempty"`
5761
// SecureBoot is a section with secureboot keys, only for SecureBoot enabled builds.
5862
SecureBoot *SecureBootAssets `yaml:"secureboot,omitempty"`
5963
// SystemExtensions is a list of system extensions to install.

0 commit comments

Comments
 (0)