add container build after container sync

Signed-off-by: jason yang <xyang@ciq.com>
This commit is contained in:
jason yang
2024-01-25 06:29:12 +00:00
committed by Jonathon Anderson
parent 4a2969f298
commit 4072730172
3 changed files with 22 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import (
"os"
"github.com/spf13/cobra"
"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 +21,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
}

View File

@@ -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.