Skip to content

Commit

Permalink
pipeline/ostree-deployment:added systedm-unit-create
Browse files Browse the repository at this point in the history
Hooked up the stage and auto-add create-mountpoint.service
added the systemd-unit-create to raw and simplified-installer pipeline
and added feature to auto add-enable osbuild-create-mountpoint.service
when ever user adds filesystem customization.

Signed-off-by: Sayan Paul <[email protected]>
  • Loading branch information
say-paul committed Mar 13, 2024
1 parent f9374c5 commit a796073
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/distro/rhel9/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ func edgeRawImage(workload workload.Workload,
img.Filename = t.Filename()
img.Compression = t.compression

for _, fs := range customizations.GetFilesystems() {
img.CustomFilesystems = append(img.CustomFilesystems, fs.Mountpoint)
}

return img, nil
}

Expand Down Expand Up @@ -546,6 +550,10 @@ func edgeSimplifiedInstallerImage(workload workload.Workload,

rawImg.Filename = t.Filename()

for _, fs := range customizations.GetFilesystems() {
rawImg.CustomFilesystems = append(rawImg.CustomFilesystems, fs.Mountpoint)
}

// 92+ only
if kopts := customizations.GetKernel(); kopts != nil && kopts.Append != "" {
rawImg.KernelOptionsAppend = append(rawImg.KernelOptionsAppend, kopts.Append)
Expand Down
3 changes: 3 additions & 0 deletions pkg/image/ostree_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type OSTreeDiskImage struct {
// Container buildable tweaks the buildroot to be container friendly,
// i.e. to not rely on an installed osbuild-selinux
ContainerBuildable bool

CustomFilesystems []string
}

func NewOSTreeDiskImageFromCommit(commit ostree.SourceSpec) *OSTreeDiskImage {
Expand Down Expand Up @@ -107,6 +109,7 @@ func baseRawOstreeImage(img *OSTreeDiskImage, buildPipeline manifest.Build, opts
osPipeline.IgnitionPlatform = img.IgnitionPlatform
osPipeline.LockRoot = img.LockRoot
osPipeline.UseBootupd = opts.useBootupd
osPipeline.CustomFileSystems = img.CustomFilesystems

// other image types (e.g. live) pass the workload to the pipeline.
if img.Workload != nil {
Expand Down
49 changes: 49 additions & 0 deletions pkg/manifest/ostree_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type OSTreeDeployment struct {

// Use bootupd instead of grub2 as the bootloader
UseBootupd bool

CustomFileSystems []string
}

// NewOSTreeCommitDeployment creates a pipeline for an ostree deployment from a
Expand Down Expand Up @@ -353,6 +355,19 @@ func (p *OSTreeDeployment) serialize() osbuild.Pipeline {
},
}))

// This will create a custom systemd unit that create
// mountpoints if its not present.This will safeguard
// any ostree deployment which has custom filesystem
// during ostree upgrade.
// issue # https://github.com/osbuild/images/issues/352
if len(p.CustomFileSystems) != 0 {
serviceName := "osbuild-ostree-mountpoints.service"
stageOption := osbuild.NewSystemdUnitCreateStageOptions(createMountpointService(serviceName, p.CustomFileSystems))
stageOption.MountOSTree(p.osName, ref, 0)
pipeline.AddStage(stageOption)
p.EnabledServices = append(p.EnabledServices, serviceName)
}

// We enable / disable services below using the systemd stage, but its effect
// may be overridden by systemd which may reset enabled / disabled services on
// firstboot (which happend on F37+). This behavior, if available, is triggered
Expand Down Expand Up @@ -481,3 +496,37 @@ func (p *OSTreeDeployment) getInline() []string {

return inlineData
}

// Creates systemd unit stage by ingesting the servicename and mount-points
func createMountpointService(serviceName string, mountpoints []string) *osbuild.SystemdUnitCreateStageOptions {
var conditionPathExists []string
for _, mountpoint := range mountpoints {
conditionPathExists = append(conditionPathExists, "|!"+mountpoint)
}
unit := osbuild.Unit{
Description: "Generated by osbuild - Create mountpoints if does not exist",
ConditionPathExists: conditionPathExists,
}
service := osbuild.Service{
Type: osbuild.Oneshot,
RemainAfterExit: true,
//compatibility with composefs, will require transient rootfs to be enabled too.
ExecStartPre: []string{"/bin/sh -c \"if [ -z \"$(grep -Uq composefs /run/ostree-booted)\" ]; then chattr -i /; fi\""},
ExecStopPost: []string{"/bin/sh -c \"if [ -z \"$(grep -Uq composefs /run/ostree-booted)\" ]; then chattr +i /; fi\""},
ExecStart: []string{"mkdir -p " + strings.Join(mountpoints[:], " ")},
}
install := osbuild.Install{
WantedBy: []string{"local-fs.target"},
}
options := osbuild.SystemdUnitCreateStageOptions{
Filename: serviceName,
UnitPath: osbuild.Etc,
UnitType: osbuild.System,
Config: osbuild.SystemdServiceUnit{
Unit: &unit,
Service: &service,
Install: &install,
},
}
return &options
}

0 comments on commit a796073

Please sign in to comment.