Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/image-builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type buildOptions struct {
OutputDir string
StoreDir string
OutputBasename string
InVm []string

WriteManifest bool
WriteBuildlog bool
Expand All @@ -40,6 +41,7 @@ func buildImage(pbar progress.ProgressBar, res *imagefilter.Result, osbuildManif
StoreDir: opts.StoreDir,
OutputDir: opts.OutputDir,
Metrics: opts.Metrics,
InVm: opts.InVm,
}
if opts.WriteBuildlog {
if err := os.MkdirAll(opts.OutputDir, 0755); err != nil {
Expand Down
15 changes: 14 additions & 1 deletion cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,23 @@ func cmdBuild(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
runInVm, err := cmd.Flags().GetBool("in-vm")
if err != nil {
return err
}
// XXX: check env here, i.e. if user is root and osbuild is installed

// Setup osbuild environment if running in a container
if setup.IsContainer() {
if err := setup.EnsureEnvironment(cacheDir, false); err != nil {
if err := setup.EnsureEnvironment(cacheDir, runInVm); err != nil {
return fmt.Errorf("entrypoint setup failed: %w", err)
}
}

if runInVm && !setup.IsContainer() {
return fmt.Errorf("running in VM outside container is not supported yet")
}

pbar, err := progressFromCmd(cmd)
if err != nil {
return err
Expand Down Expand Up @@ -475,6 +483,9 @@ func cmdBuild(cmd *cobra.Command, args []string) error {
WriteBuildlog: withBuildlog,
Metrics: withMetrics,
}
if runInVm {
buildOpts.InVm = []string{"image"}
}
pbar.SetPulseMsgf("Image building step")
imagePath, err := buildImage(pbar, res, mf.Bytes(), buildOpts)
if err != nil {
Expand Down Expand Up @@ -663,6 +674,7 @@ operating systems like Fedora, CentOS and RHEL with easy customizations support.
buildCmd.Flags().String("progress", "auto", "type of progress bar to use (e.g. verbose,term)")
buildCmd.Flags().Bool("with-metrics", false, `print timing information at the end of the build`)
buildCmd.Flags().String("output-name", "", "set specific output basename")
buildCmd.Flags().Bool("in-vm", false, `run the osbuild pipeline in a virtual machine`)
rootCmd.AddCommand(buildCmd)
buildCmd.Flags().AddFlagSet(uploadCmd.Flags())
// add after the rest of the uploadCmd flag set is added to avoid
Expand All @@ -681,6 +693,7 @@ operating systems like Fedora, CentOS and RHEL with easy customizations support.
}
describeImgCmd.Flags().String("arch", "", `use the different architecture`)
describeImgCmd.Flags().String("distro", "", `build manifest for a different distroname (e.g. centos-9)`)
describeImgCmd.Flags().Bool("in-vm", false, `run container in a virtual machine`)

rootCmd.AddCommand(describeImgCmd)

Expand Down
Loading