diff --git a/CHANGELOG.md b/CHANGELOG.md index 92939b24..51ef1e9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New build for Rocky Linux 9 - Add nightly release support. #969 - Add container rename command. #583 +- Add container build flags and warn message after container sync. #509 ### Fixed - Make Variables.mk consistent with spec file w.r.t. WWPROVISIONDIR, e.g. diff --git a/internal/app/wwctl/container/syncuser/main.go b/internal/app/wwctl/container/syncuser/main.go index 369c046a..67e2d296 100644 --- a/internal/app/wwctl/container/syncuser/main.go +++ b/internal/app/wwctl/container/syncuser/main.go @@ -5,6 +5,8 @@ import ( "os" "github.com/spf13/cobra" + container_build "github.com/warewulf/warewulf/internal/pkg/api/container" + "github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1" "github.com/warewulf/warewulf/internal/pkg/container" "github.com/warewulf/warewulf/internal/pkg/wwlog" ) @@ -20,5 +22,23 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } + if write && !build { + // when write = true and build = false, we will print a warnning, this is the default case + wwlog.Warn("Syncuser is completed, please remember to rebuild container or add `--build` flag for automatic rebuild after syncuser") + } else if write && build { + // if write = true and build = true, then it'll trigger the container build after sync + cbp := &wwapiv1.ContainerBuildParameter{ + ContainerNames: []string{containerName}, + Force: true, + All: false, + Default: false, + } + err := container_build.ContainerBuild(cbp) + if err != nil { + wwlog.Error("Error during container build: %s", err) + os.Exit(1) + } + } + return nil } diff --git a/internal/app/wwctl/container/syncuser/root.go b/internal/app/wwctl/container/syncuser/root.go index d14c100b..296ed34e 100644 --- a/internal/app/wwctl/container/syncuser/root.go +++ b/internal/app/wwctl/container/syncuser/root.go @@ -25,10 +25,12 @@ uid/gid collision is detected. File ownerships are also changed.`, Args: cobra.MinimumNArgs(1), } write bool + build bool ) func init() { baseCmd.PersistentFlags().BoolVar(&write, "write", false, "Synchronize uis/gids and write files in container") + baseCmd.PersistentFlags().BoolVar(&build, "build", false, "Build container after syncuser is completed") } // GetRootCommand returns the root cobra.Command for the application.