Skip to content

Commit

Permalink
Allow features to be passed as arguments
Browse files Browse the repository at this point in the history
Signed-off-by: David Cassany <dcassany@suse.com>
  • Loading branch information
davidcassany committed Sep 24, 2024
1 parent c561b4c commit b9f6dea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
21 changes: 16 additions & 5 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ func InitCmd(root *cobra.Command) *cobra.Command {
Use: "init FEATURES",
Short: "Initialize container image for booting",
Long: "Init a container image with elemental configuration\n\n" +
"FEATURES - should be provided as a comma-separated list of features to install.\n" +
" Available features: " + strings.Join(features.All, ",") + "\n" +
" Defaults to " + strings.Join(features.Default, ","),
Args: cobra.MaximumNArgs(1),
"FEATURES - provided as an argument list of features to install.\n" +
" Available features:\n\t" + strings.Join(features.All, "\n\t") + "\n\n" +
" Defaults to:\n\t" + strings.Join(features.Default, "\n\t"),
ValidArgs: features.All,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 {
// This is logic is just to keep backward compatibility with
// comma separated values
return cobra.OnlyValidArgs(cmd, strings.Split(args[0], ","))
}
return cobra.OnlyValidArgs(cmd, args)
},
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := config.ReadConfigRun(viper.GetString("config-dir"), cmd.Flags(), types.NewDummyMounter())
if err != nil {
Expand All @@ -54,8 +62,11 @@ func InitCmd(root *cobra.Command) *cobra.Command {

if len(args) == 0 {
spec.Features = features.Default
} else {
} else if len(args) == 1 {
// The old behavior is kept to keep backward compatibiliy
spec.Features = strings.Split(args[0], ",")
} else {
spec.Features = args
}

cfg.Logger.Infof("Initializing system...")
Expand Down
12 changes: 11 additions & 1 deletion examples/green-rpi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ COPY --from=TOOLKIT /usr/bin/elemental /usr/bin/elemental
RUN systemctl enable NetworkManager.service

# Generate initrd with required elemental services
RUN elemental --debug init --force
RUN elemental --debug init --force \
elemental-rootfs \
elemental-sysroot \
grub-config \
grub-default-bootargs \
elemental-setup \
dracut-config \
cloud-config-defaults \
cloud-config-essentials \
boot-assessment \
arm-firmware

# Update os-release file with some metadata
RUN echo IMAGE_REPO=\"${REPO}\" >> /etc/os-release && \
Expand Down
1 change: 0 additions & 1 deletion pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ var (
FeatureCloudConfigDefaults,
FeatureCloudConfigEssentials,
FeatureBootAssessment,
FeatureArmFirmware,
}
)

Expand Down

0 comments on commit b9f6dea

Please sign in to comment.