Skip to content

Commit f4365bd

Browse files
committed
build: accept --in-vm flag for container build
Accept in-vm flag for building images in a container and install osbuild-virt-deps in the container. The functionality for running in VM outside container is not in the scope, but is planned.
1 parent 6a1aada commit f4365bd

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RUN mkdir -p /etc/containers/networks
1818
# Fast-track osbuild so we don't depend on the "slow" Fedora release process to implement new features in bib
1919
RUN dnf install -y dnf-plugins-core \
2020
&& dnf copr enable -y @osbuild/osbuild \
21-
&& dnf install -y libxcrypt-compat wget osbuild osbuild-ostree osbuild-depsolve-dnf osbuild-lvm2 openssl subscription-manager \
21+
&& dnf install -y libxcrypt-compat wget osbuild osbuild-ostree osbuild-depsolve-dnf osbuild-lvm2 osbuild-virt-deps openssl subscription-manager \
2222
&& dnf clean all
2323

2424
COPY --from=builder /build/bin/image-builder /usr/bin/

cmd/image-builder/build.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type buildOptions struct {
1414
OutputDir string
1515
StoreDir string
1616
OutputBasename string
17+
InVm []string
1718

1819
WriteManifest bool
1920
WriteBuildlog bool
@@ -40,6 +41,7 @@ func buildImage(pbar progress.ProgressBar, res *imagefilter.Result, osbuildManif
4041
StoreDir: opts.StoreDir,
4142
OutputDir: opts.OutputDir,
4243
Metrics: opts.Metrics,
44+
InVm: opts.InVm,
4345
}
4446
if opts.WriteBuildlog {
4547
if err := os.MkdirAll(opts.OutputDir, 0755); err != nil {

cmd/image-builder/main.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,23 @@ func cmdBuild(cmd *cobra.Command, args []string) error {
415415
if err != nil {
416416
return err
417417
}
418+
runInVm, err := cmd.Flags().GetBool("in-vm")
419+
if err != nil {
420+
return err
421+
}
418422
// XXX: check env here, i.e. if user is root and osbuild is installed
419423

420424
// Setup osbuild environment if running in a container
421425
if setup.IsContainer() {
422-
if err := setup.EnsureEnvironment(cacheDir, false); err != nil {
426+
if err := setup.EnsureEnvironment(cacheDir, runInVm); err != nil {
423427
return fmt.Errorf("entrypoint setup failed: %w", err)
424428
}
425429
}
426430

431+
if runInVm && !setup.IsContainer() {
432+
return fmt.Errorf("running in VM outside container is not supported yet")
433+
}
434+
427435
pbar, err := progressFromCmd(cmd)
428436
if err != nil {
429437
return err
@@ -475,6 +483,9 @@ func cmdBuild(cmd *cobra.Command, args []string) error {
475483
WriteBuildlog: withBuildlog,
476484
Metrics: withMetrics,
477485
}
486+
if runInVm {
487+
buildOpts.InVm = []string{"image"}
488+
}
478489
pbar.SetPulseMsgf("Image building step")
479490
imagePath, err := buildImage(pbar, res, mf.Bytes(), buildOpts)
480491
if err != nil {
@@ -663,6 +674,7 @@ operating systems like Fedora, CentOS and RHEL with easy customizations support.
663674
buildCmd.Flags().String("progress", "auto", "type of progress bar to use (e.g. verbose,term)")
664675
buildCmd.Flags().Bool("with-metrics", false, `print timing information at the end of the build`)
665676
buildCmd.Flags().String("output-name", "", "set specific output basename")
677+
buildCmd.Flags().Bool("in-vm", false, `run the osbuild pipeline in a virtual machine`)
666678
rootCmd.AddCommand(buildCmd)
667679
buildCmd.Flags().AddFlagSet(uploadCmd.Flags())
668680
// add after the rest of the uploadCmd flag set is added to avoid
@@ -681,6 +693,7 @@ operating systems like Fedora, CentOS and RHEL with easy customizations support.
681693
}
682694
describeImgCmd.Flags().String("arch", "", `use the different architecture`)
683695
describeImgCmd.Flags().String("distro", "", `build manifest for a different distroname (e.g. centos-9)`)
696+
describeImgCmd.Flags().Bool("in-vm", false, `run container in a virtual machine`)
684697

685698
rootCmd.AddCommand(describeImgCmd)
686699

0 commit comments

Comments
 (0)