Skip to content

Commit

Permalink
feat: customize image size
Browse files Browse the repository at this point in the history
Can possible to change boot image size.
Change the default image size for some cloud platform.

Signed-off-by: Serge Logvinov <serge.logvinov@sinextra.dev>
Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
sergelogvinov authored and smira committed Oct 16, 2023
1 parent 865f08f commit 401e894
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
21 changes: 21 additions & 0 deletions cmd/installer/cmd/imager/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ package imager

import (
"context"
"fmt"
"os"
"runtime"

"github.com/dustin/go-humanize"
"github.com/siderolabs/gen/xslices"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
Expand All @@ -27,6 +29,7 @@ var cmdFlags struct {
Platform string
Arch string
Board string
ImageDiskSize string
ExtraKernelArgs []string
MetaValues install.MetaValues
SystemExtensionImages []string
Expand Down Expand Up @@ -94,6 +97,23 @@ var rootCmd = &cobra.Command{
ImageRef: cmdFlags.BaseInstallerImage,
}
}

if cmdFlags.ImageDiskSize != "" {
size, err := humanize.ParseBytes(cmdFlags.ImageDiskSize)
if err != nil {
return fmt.Errorf("error parsing disk image size: %w", err)
}

if size < profile.MinRAWDiskSize {
return fmt.Errorf("disk image size must be at least %s", humanize.Bytes(profile.MinRAWDiskSize))
}

if prof.Output.ImageOptions == nil {
prof.Output.ImageOptions = &profile.ImageOptions{}
}

prof.Output.ImageOptions.DiskSize = int64(size)
}
}

if err := os.MkdirAll(cmdFlags.OutputPath, 0o755); err != nil {
Expand Down Expand Up @@ -136,6 +156,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&cmdFlags.Arch, "arch", runtime.GOARCH, "The target architecture")
rootCmd.PersistentFlags().StringVar(&cmdFlags.BaseInstallerImage, "base-installer-image", "", "Base installer image to use")
rootCmd.PersistentFlags().StringVar(&cmdFlags.Board, "board", "", "The value of "+constants.KernelParamBoard)
rootCmd.PersistentFlags().StringVar(&cmdFlags.ImageDiskSize, "image-disk-size", "", "Set custom disk image size (accepts human readable values, e.g. 6GiB)")
rootCmd.PersistentFlags().StringArrayVar(&cmdFlags.ExtraKernelArgs, "extra-kernel-arg", []string{}, "Extra argument to pass to the kernel")
rootCmd.PersistentFlags().Var(&cmdFlags.MetaValues, "meta", "A key/value pair for META")
rootCmd.PersistentFlags().StringArrayVar(&cmdFlags.SystemExtensionImages, "system-extension-image", []string{}, "The image reference to the system extension to install")
Expand Down
8 changes: 4 additions & 4 deletions pkg/imager/profile/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var Default = map[string]Profile{
Kind: OutKindImage,
OutFormat: OutFormatXZ,
ImageOptions: &ImageOptions{
DiskSize: DefaultRAWDiskSize,
DiskSize: MinRAWDiskSize,
DiskFormat: DiskFormatRaw,
},
},
Expand All @@ -162,7 +162,7 @@ var Default = map[string]Profile{
Kind: OutKindImage,
OutFormat: OutFormatXZ,
ImageOptions: &ImageOptions{
DiskSize: DefaultRAWDiskSize,
DiskSize: MinRAWDiskSize,
DiskFormat: DiskFormatRaw,
},
},
Expand All @@ -174,7 +174,7 @@ var Default = map[string]Profile{
Kind: OutKindImage,
OutFormat: OutFormatXZ,
ImageOptions: &ImageOptions{
DiskSize: DefaultRAWDiskSize,
DiskSize: MinRAWDiskSize,
DiskFormat: DiskFormatRaw,
},
},
Expand All @@ -199,7 +199,7 @@ var Default = map[string]Profile{
Kind: OutKindImage,
OutFormat: OutFormatXZ,
ImageOptions: &ImageOptions{
DiskSize: DefaultRAWDiskSize,
DiskSize: MinRAWDiskSize,
DiskFormat: DiskFormatRaw,
},
},
Expand Down

0 comments on commit 401e894

Please sign in to comment.