Skip to content

Commit

Permalink
distro: add OutputFilename option to ImageOptions
Browse files Browse the repository at this point in the history
This commit allows to change the filename when creating a
manifest from an image type. This is useful when doing a UI for users,
e.g. this will allow us to support:
```
$ image-builder build rhel-9 type:qcow2 --output foo.img
```
(this will also be useful for bootc-image-builder).

Well, osbuild itself will still put it under a directory when
doing main_cli.py:exports() but that is something orthogonal.
  • Loading branch information
mvo5 committed Nov 13, 2024
1 parent 70fd73a commit e5c345d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
9 changes: 9 additions & 0 deletions pkg/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ type ImageOptions struct {
Subscription *subscription.ImageOptions `json:"subscription,omitempty"`
Facts *facts.ImageOptions `json:"facts,omitempty"`
PartitioningMode disk.PartitioningMode `json:"partitioning-mode,omitempty"`

OutputFilename string `json:"output_filename"`
}

func (i *ImageOptions) Filename(imgType ImageType) string {
if i.OutputFilename != "" {
return i.OutputFilename
}
return imgType.Filename()
}

type BasePartitionTableMap map[string]disk.PartitionTable
Expand Down
18 changes: 18 additions & 0 deletions pkg/distro/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/osbuild/images/pkg/container"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/distro/distro_test_common"
"github.com/osbuild/images/pkg/distro/test_distro"
"github.com/osbuild/images/pkg/distrofactory"
"github.com/osbuild/images/pkg/ostree"
"github.com/osbuild/images/pkg/rpmmd"
Expand Down Expand Up @@ -567,3 +568,20 @@ func TestDistro_ManifestFIPSWarning(t *testing.T) {
}
}
}

func TestDistro_ImageOptionsFilename(t *testing.T) {
imgType := &test_distro.TestImageType{}

for _, tc := range []struct {
outputFilename string
expectedFilename string
}{
{"", "test.img"},
{"foo.img", "foo.img"},
} {
imgOpts := &distro.ImageOptions{
OutputFilename: tc.outputFilename,
}
assert.Equal(t, tc.expectedFilename, imgOpts.Filename(imgType))
}
}
31 changes: 15 additions & 16 deletions pkg/distro/fedora/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ func diskImage(workload workload.Workload,
return nil, err
}
img.PartitionTable = pt

img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil
}
Expand All @@ -359,8 +358,7 @@ func containerImage(workload workload.Workload,

img.Environment = t.environment
img.Workload = workload

img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil
}
Expand Down Expand Up @@ -392,8 +390,7 @@ func liveInstallerImage(workload workload.Workload,
if err != nil {
return nil, err
}

img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil
}
Expand Down Expand Up @@ -466,8 +463,7 @@ func imageInstallerImage(workload workload.Workload,
if err != nil {
return nil, err
}

img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil
}
Expand Down Expand Up @@ -513,7 +509,8 @@ func iotCommitImage(workload workload.Workload,
img.Workload = workload
img.OSTreeParent = parentCommit
img.OSVersion = d.osVersion
img.Filename = t.Filename()
img.Filename = options.Filename(t)

img.InstallWeakDeps = false

return img, nil
Expand Down Expand Up @@ -544,7 +541,8 @@ func bootableContainerImage(workload workload.Workload,
img.Workload = workload
img.OSTreeParent = parentCommit
img.OSVersion = d.osVersion
img.Filename = t.Filename()
img.Filename = options.Filename(t)

img.InstallWeakDeps = false
img.BootContainer = true
img.BootcConfig = &bootc.Config{
Expand Down Expand Up @@ -596,7 +594,7 @@ func iotContainerImage(workload workload.Workload,
img.OSTreeParent = parentCommit
img.OSVersion = d.osVersion
img.ExtraContainerPackages = packageSets[containerPkgsKey]
img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil
}
Expand Down Expand Up @@ -664,8 +662,7 @@ func iotInstallerImage(workload workload.Workload,
if err != nil {
return nil, err
}

img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil
}
Expand Down Expand Up @@ -705,8 +702,8 @@ func iotImage(workload workload.Workload,
return nil, err
}
img.PartitionTable = pt
img.Filename = options.Filename(t)

img.Filename = t.Filename()
img.Compression = t.compression

return img, nil
Expand Down Expand Up @@ -747,13 +744,15 @@ func iotSimplifiedInstallerImage(workload workload.Workload,
}
rawImg.PartitionTable = pt

rawImg.Filename = t.Filename()
filename := options.Filename(t)
rawImg.Filename = filename

img := image.NewOSTreeSimplifiedInstaller(rawImg, customizations.InstallationDevice)
img.ExtraBasePackages = packageSets[installerPkgsKey]
// img.Workload = workload
img.Platform = t.platform
img.Filename = t.Filename()
img.Filename = filename

if bpFDO := customizations.GetFDO(); bpFDO != nil {
img.FDO = fdo.FromBP(*bpFDO)
}
Expand Down
23 changes: 10 additions & 13 deletions pkg/distro/rhel/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,7 @@ func DiskImage(workload workload.Workload,
return nil, err
}
img.PartitionTable = pt

img.Filename = t.Filename()
img.Filename = options.Filename(t)

img.VPCForceSize = t.DiskImageVPCForceSize

Expand Down Expand Up @@ -415,7 +414,7 @@ func EdgeCommitImage(workload workload.Workload,
img.Workload = workload
img.OSTreeParent = parentCommit
img.OSVersion = t.Arch().Distro().OsVersion()
img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil
}
Expand Down Expand Up @@ -445,7 +444,7 @@ func EdgeContainerImage(workload workload.Workload,
img.OSTreeParent = parentCommit
img.OSVersion = t.Arch().Distro().OsVersion()
img.ExtraContainerPackages = packageSets[ContainerPkgsKey]
img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil
}
Expand Down Expand Up @@ -523,8 +522,7 @@ func EdgeInstallerImage(workload workload.Workload,
img.OSVersion = t.Arch().Distro().OsVersion()
img.Release = fmt.Sprintf("%s %s", t.Arch().Distro().Product(), t.Arch().Distro().OsVersion())
img.FIPS = customizations.GetFIPS()

img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil
}
Expand Down Expand Up @@ -564,8 +562,8 @@ func EdgeRawImage(workload workload.Workload,
return nil, err
}
img.PartitionTable = pt
img.Filename = options.Filename(t)

img.Filename = t.Filename()
img.Compression = t.Compression

return img, nil
Expand Down Expand Up @@ -607,13 +605,14 @@ func EdgeSimplifiedInstallerImage(workload workload.Workload,
}
rawImg.PartitionTable = pt

rawImg.Filename = t.Filename()
filename := options.Filename(t)
rawImg.Filename = filename

img := image.NewOSTreeSimplifiedInstaller(rawImg, customizations.InstallationDevice)
img.ExtraBasePackages = packageSets[InstallerPkgsKey]
// img.Workload = workload
img.Platform = t.platform
img.Filename = t.Filename()
img.Filename = filename
if bpFDO := customizations.GetFDO(); bpFDO != nil {
img.FDO = fdo.FromBP(*bpFDO)
}
Expand Down Expand Up @@ -719,8 +718,7 @@ func ImageInstallerImage(workload workload.Workload,
img.Product = d.product
img.OSVersion = d.osVersion
img.Release = fmt.Sprintf("%s %s", d.product, d.osVersion)

img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil
}
Expand All @@ -744,8 +742,7 @@ func TarImage(workload workload.Workload,

img.Environment = t.Environment
img.Workload = workload

img.Filename = t.Filename()
img.Filename = options.Filename(t)

return img, nil

Expand Down

0 comments on commit e5c345d

Please sign in to comment.