-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
images: add new
image.BootcDiskImage
type for bootc-image-builder
Add a new `BootcDiskImage` type that is more opinionated then OSTreeDiskImage as the two are more and more diverging. This will be used in `bootc-image-builder`.
- Loading branch information
Showing
3 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package image | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
|
||
"github.com/osbuild/images/pkg/artifact" | ||
"github.com/osbuild/images/pkg/container" | ||
"github.com/osbuild/images/pkg/manifest" | ||
"github.com/osbuild/images/pkg/platform" | ||
"github.com/osbuild/images/pkg/runner" | ||
) | ||
|
||
type BootcDiskImage struct { | ||
*OSTreeDiskImage | ||
} | ||
|
||
func NewBootcDiskImage(container container.SourceSpec) *BootcDiskImage { | ||
// XXX: hardcoded for now | ||
ref := "ostree/1/1/0" | ||
|
||
return &BootcDiskImage{ | ||
&OSTreeDiskImage{ | ||
Base: NewBase("bootc-raw-image"), | ||
ContainerSource: &container, | ||
Ref: ref, | ||
OSName: "default", | ||
}, | ||
} | ||
} | ||
|
||
func (img *BootcDiskImage) InstantiateManifestFromContainers(m *manifest.Manifest, | ||
containers []container.SourceSpec, | ||
runner runner.Runner, | ||
rng *rand.Rand) (*artifact.Artifact, error) { | ||
|
||
buildPipeline := manifest.NewBuildFromContainersSourceSpec(m, runner, containers, &manifest.BuildOptions{ContainerBuildable: true}) | ||
buildPipeline.Checkpoint() | ||
|
||
// don't support compressing non-raw images | ||
imgFormat := img.Platform.GetImageFormat() | ||
if imgFormat == platform.FORMAT_UNSET { | ||
// treat unset as raw for this check | ||
imgFormat = platform.FORMAT_RAW | ||
} | ||
if imgFormat != platform.FORMAT_RAW && img.Compression != "" { | ||
panic(fmt.Sprintf("no compression is allowed with %q format for %q", imgFormat, img.name)) | ||
} | ||
|
||
baseImage := baseRawOstreeImage(img.OSTreeDiskImage, buildPipeline) | ||
switch imgFormat { | ||
case platform.FORMAT_QCOW2: | ||
// TODO: create new build pipeline here that uses "bib" itself | ||
// as the buildroot to get access to tooling like "qemu-img" | ||
qcow2Pipeline := manifest.NewQCOW2(buildPipeline, baseImage) | ||
qcow2Pipeline.Compat = img.Platform.GetQCOW2Compat() | ||
qcow2Pipeline.SetFilename(img.Filename) | ||
return qcow2Pipeline.Export(), nil | ||
} | ||
|
||
switch img.Compression { | ||
case "xz": | ||
compressedImage := manifest.NewXZ(buildPipeline, baseImage) | ||
compressedImage.SetFilename(img.Filename) | ||
return compressedImage.Export(), nil | ||
case "": | ||
baseImage.SetFilename(img.Filename) | ||
return baseImage.Export(), nil | ||
default: | ||
panic(fmt.Sprintf("unsupported compression type %q on %q", img.Compression, img.name)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package image_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/osbuild/images/pkg/container" | ||
"github.com/osbuild/images/pkg/image" | ||
) | ||
|
||
func TestBootcDiskImageNew(t *testing.T) { | ||
containerSource := container.SourceSpec{ | ||
Source: "source-spec", | ||
Name: "name", | ||
} | ||
|
||
img := image.NewBootcDiskImage(containerSource) | ||
require.NotNil(t, img) | ||
assert.Equal(t, img.OSTreeDiskImage.Base.Name(), "bootc-raw-image") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters