From d27bdac369092ed0548de60bdbf44955ae97dc0e Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 23 Sep 2022 13:11:13 +0200 Subject: [PATCH] manifest: new pipeline for building ISO rootfs.img --- internal/manifest/iso_rootfs.go | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 internal/manifest/iso_rootfs.go diff --git a/internal/manifest/iso_rootfs.go b/internal/manifest/iso_rootfs.go new file mode 100644 index 000000000..f33ca40ee --- /dev/null +++ b/internal/manifest/iso_rootfs.go @@ -0,0 +1,71 @@ +package manifest + +import ( + "fmt" + + "github.com/osbuild/osbuild-composer/internal/osbuild" +) + +type ISORootfsImg struct { + Base + + Size uint64 + + anacondaPipeline *Anaconda +} + +func NewISORootfsImg(m *Manifest, buildPipeline *Build, anacondaPipeline *Anaconda) *ISORootfsImg { + p := &ISORootfsImg{ + Base: NewBase(m, "rootfs-image", buildPipeline), + anacondaPipeline: anacondaPipeline, + } + buildPipeline.addDependent(p) + m.addPipeline(p) + return p +} + +func (p *ISORootfsImg) serialize() osbuild.Pipeline { + pipeline := p.Base.serialize() + + pipeline.AddStage(osbuild.NewMkdirStage(&osbuild.MkdirStageOptions{ + Paths: []osbuild.Path{ + { + Path: "LiveOS", + }, + }, + })) + pipeline.AddStage(osbuild.NewTruncateStage(&osbuild.TruncateStageOptions{ + Filename: "LiveOS/rootfs.img", + Size: fmt.Sprintf("%d", p.Size), + })) + + mkfsStageOptions := &osbuild.MkfsExt4StageOptions{ + UUID: "2fe99653-f7ff-44fd-bea8-fa70107524fb", + Label: "Anaconda", + } + lodevice := osbuild.NewLoopbackDevice( + &osbuild.LoopbackDeviceOptions{ + Filename: "LiveOS/rootfs.img", + }, + ) + + devName := "device" + devices := osbuild.Devices{devName: *lodevice} + mkfsStage := osbuild.NewMkfsExt4Stage(mkfsStageOptions, devices) + pipeline.AddStage(mkfsStage) + + inputName := "tree" + copyStageOptions := &osbuild.CopyStageOptions{ + Paths: []osbuild.CopyStagePath{ + { + From: fmt.Sprintf("input://%s/", inputName), + To: fmt.Sprintf("mount://%s/", devName), + }, + }, + } + copyStageInputs := osbuild.NewPipelineTreeInputs(inputName, p.anacondaPipeline.Name()) + copyStageMounts := &osbuild.Mounts{*osbuild.NewExt4Mount(devName, devName, "/")} + copyStage := osbuild.NewCopyStage(copyStageOptions, copyStageInputs, &devices, copyStageMounts) + pipeline.AddStage(copyStage) + return pipeline +}