Added wwctl image build --syncuser

- #1321

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2025-02-11 08:59:29 -07:00
parent f2092b2854
commit b56fc19f9e
3 changed files with 16 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added support for comma-separated hostlist patterns. #1635 - Added support for comma-separated hostlist patterns. #1635
- Added default value for `warewulf.conf:dhcp.template`. #1725 - Added default value for `warewulf.conf:dhcp.template`. #1725
- Added `UniqueField` template function. #829 - Added `UniqueField` template function. #829
- Added `wwctl image build --syncuser`. #1321
### Changed ### Changed

View File

@@ -1,16 +1,27 @@
package build package build
import ( import (
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/api/image" apiimage "github.com/warewulf/warewulf/internal/pkg/api/image"
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1" "github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/warewulf/warewulf/internal/pkg/image"
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
if SyncUser {
for _, name := range args {
if err := image.SyncUids(name, true); err != nil {
return fmt.Errorf("syncuser error: %w", err)
}
}
}
cbp := &wwapiv1.ImageBuildParameter{ cbp := &wwapiv1.ImageBuildParameter{
ImageNames: args, ImageNames: args,
Force: BuildForce, Force: BuildForce,
All: BuildAll, All: BuildAll,
} }
return image.ImageBuild(cbp) return apiimage.ImageBuild(cbp)
} }

View File

@@ -23,11 +23,13 @@ var (
} }
BuildForce bool BuildForce bool
BuildAll bool BuildAll bool
SyncUser bool
) )
func init() { func init() {
baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "(re)Build all images") baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "(re)Build all images")
baseCmd.PersistentFlags().BoolVarP(&BuildForce, "force", "f", false, "Force rebuild, even if it isn't necessary") baseCmd.PersistentFlags().BoolVarP(&BuildForce, "force", "f", false, "Force rebuild, even if it isn't necessary")
baseCmd.PersistentFlags().BoolVar(&SyncUser, "syncuser", false, "Synchronize UIDs/GIDs from host to image")
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.