Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distro: add OutputFilename option to ImageOptions #1039

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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 != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, if we do this we will have to add validation here too, something like:

        if filepath.Base(s) != s {
		return fmt.Errorf("cannot use %q: only relative filenames supported", s)
	}
	if filepath.Clean(s) != s {
		return fmt.Errorf("cannot use %q: only clean filenames supported", s)
	}

and of course error handling which will make the diff a bit more annoying.

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
Loading