Skip to content

Commit

Permalink
fedora-iot: make use of presets to enable services see osbuild/osbuil…
Browse files Browse the repository at this point in the history
…d#1269

Signed-off-by: Antonio Murdaca <runcom@linux.com>
  • Loading branch information
runcom authored and 7flying committed May 4, 2023
1 parent c413206 commit c2f7ddd
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/distro/fedora/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var (
"redboot-task-runner",
"parsec",
"dbus-parsec",
// these services are already part of 80-iot.preset, why redefine??
}

// Image Definitions
Expand Down
24 changes: 22 additions & 2 deletions internal/distro/fedora/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,17 @@ func iotCommitImage(workload workload.Workload,
img.Platform = t.platform
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, customizations)
if strings.HasPrefix(distro.Name(), "fedora") && !common.VersionLessThan(distro.Releasever(), "38") {
img.OSCustomizations.EnabledServices = append(img.OSCustomizations.EnabledServices, "ignition-firstboot-complete.service", "coreos-ignition-write-issues.service")
// see https://github.com/ostreedev/ostree/issues/2840
img.OSCustomizations.Presets = []osbuild.Preset{
{
Name: "ignition-firstboot-complete.service",
State: osbuild.StateEnable,
},
{
Name: "coreos-ignition-write-issues.service",
State: osbuild.StateEnable,
},
}
}
img.Environment = t.environment
img.Workload = workload
Expand Down Expand Up @@ -334,7 +344,17 @@ func iotContainerImage(workload workload.Workload,
img.Platform = t.platform
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, customizations)
if strings.HasPrefix(distro.Name(), "fedora") && !common.VersionLessThan(distro.Releasever(), "38") {
img.OSCustomizations.EnabledServices = append(img.OSCustomizations.EnabledServices, "ignition-firstboot-complete.service", "coreos-ignition-write-issues.service")
// see https://github.com/ostreedev/ostree/issues/2840
img.OSCustomizations.Presets = []osbuild.Preset{
{
Name: "ignition-firstboot-complete.service",
State: osbuild.StateEnable,
},
{
Name: "coreos-ignition-write-issues.service",
State: osbuild.StateEnable,
},
}
}
img.ContainerLanguage = img.OSCustomizations.Language
img.Environment = t.environment
Expand Down
7 changes: 7 additions & 0 deletions internal/manifest/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type OSCustomizations struct {
EnabledServices []string
DisabledServices []string
DefaultTarget string
Presets []osbuild.Preset

// SELinux policy, when set it enables the labeling of the tree with the
// selected profile
Expand Down Expand Up @@ -651,6 +652,12 @@ func (p *OS) serialize() osbuild.Pipeline {
pipeline.AddStage(osbuild.GenShellInitStage(p.ShellInit))
}

if len(p.Presets) != 0 {
pipeline.AddStage(osbuild.NewSystemdPresetStage(&osbuild.SystemdPresetStageOptions{
Presets: p.Presets,
}))
}

if p.SElinux != "" {
pipeline.AddStage(osbuild.NewSELinuxStage(&osbuild.SELinuxStageOptions{
FileContexts: fmt.Sprintf("etc/selinux/%s/contexts/files/file_contexts", p.SElinux),
Expand Down
26 changes: 26 additions & 0 deletions internal/osbuild/systemd_preset_stage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package osbuild

type SystemdPresetStageOptions struct {
Presets []Preset `json:"presets,omitempty"`
}

type PresetState string

const (
StateEnable PresetState = "enable"
StateDisable PresetState = "disable"
)

type Preset struct {
Name string `json:"name,omitempty"`
State PresetState `json:"state,omitempty"`
}

func (SystemdPresetStageOptions) isStageOptions() {}

func NewSystemdPresetStage(options *SystemdPresetStageOptions) *Stage {
return &Stage{
Type: "org.osbuild.systemd.preset",
Options: options,
}
}
21 changes: 21 additions & 0 deletions test/data/manifests/fedora_36-x86_64-iot_container-boot.json
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,14 @@
}
}
},
{
"id": "sha256:24511c16d8cc4ae8d14c31f583346b58d4190f7da6de9d403aa02bccb84f4d0e",
"options": {
"metadata": {
"rpm.check_gpg": true
}
}
},
{
"id": "sha256:4db9bb285f364b472000badad7fc7e29999f8edf0b62b6d1ef5d379435fd165f",
"options": {
Expand Down Expand Up @@ -7279,6 +7287,9 @@
"sha256:241d1b49d117d229191f8f188bc9d767ce3a6be8bcb1e1bdb147d81825cf8cd7": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f36/f36-x86_64-fedora-20220617/Packages/m/memstrack-0.2.4-2.fc36.x86_64.rpm"
},
"sha256:24511c16d8cc4ae8d14c31f583346b58d4190f7da6de9d403aa02bccb84f4d0e": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f36/f36-x86_64-fedora-20220617/Packages/b/biosdevname-0.7.3-9.fc36.x86_64.rpm"
},
"sha256:26a52a1f741452daf0aa9ae664782f185aafaa190698403553838ef28001e562": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f36/f36-x86_64-fedora-20220617/Packages/d/diffutils-3.8-2.fc36.x86_64.rpm"
},
Expand Down Expand Up @@ -12600,6 +12611,16 @@
"checksum": "sha256:29c7630d3036cffa99fb1c078c4dcd8ea1611b95cb1c6ebbc57571cd3cb71325",
"check_gpg": true
},
{
"name": "biosdevname",
"epoch": 0,
"version": "0.7.3",
"release": "9.fc36",
"arch": "x86_64",
"remote_location": "https://rpmrepo.osbuild.org/v2/mirror/public/f36/f36-x86_64-fedora-20220617/Packages/b/biosdevname-0.7.3-9.fc36.x86_64.rpm",
"checksum": "sha256:24511c16d8cc4ae8d14c31f583346b58d4190f7da6de9d403aa02bccb84f4d0e",
"check_gpg": true
},
{
"name": "bluez",
"epoch": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,14 @@
}
}
},
{
"id": "sha256:24511c16d8cc4ae8d14c31f583346b58d4190f7da6de9d403aa02bccb84f4d0e",
"options": {
"metadata": {
"rpm.check_gpg": true
}
}
},
{
"id": "sha256:4db9bb285f364b472000badad7fc7e29999f8edf0b62b6d1ef5d379435fd165f",
"options": {
Expand Down Expand Up @@ -7446,6 +7454,9 @@
"sha256:241d1b49d117d229191f8f188bc9d767ce3a6be8bcb1e1bdb147d81825cf8cd7": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f36/f36-x86_64-fedora-20220617/Packages/m/memstrack-0.2.4-2.fc36.x86_64.rpm"
},
"sha256:24511c16d8cc4ae8d14c31f583346b58d4190f7da6de9d403aa02bccb84f4d0e": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f36/f36-x86_64-fedora-20220617/Packages/b/biosdevname-0.7.3-9.fc36.x86_64.rpm"
},
"sha256:26a52a1f741452daf0aa9ae664782f185aafaa190698403553838ef28001e562": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f36/f36-x86_64-fedora-20220617/Packages/d/diffutils-3.8-2.fc36.x86_64.rpm"
},
Expand Down Expand Up @@ -12787,6 +12798,16 @@
"checksum": "sha256:29c7630d3036cffa99fb1c078c4dcd8ea1611b95cb1c6ebbc57571cd3cb71325",
"check_gpg": true
},
{
"name": "biosdevname",
"epoch": 0,
"version": "0.7.3",
"release": "9.fc36",
"arch": "x86_64",
"remote_location": "https://rpmrepo.osbuild.org/v2/mirror/public/f36/f36-x86_64-fedora-20220617/Packages/b/biosdevname-0.7.3-9.fc36.x86_64.rpm",
"checksum": "sha256:24511c16d8cc4ae8d14c31f583346b58d4190f7da6de9d403aa02bccb84f4d0e",
"check_gpg": true
},
{
"name": "bluez",
"epoch": 0,
Expand Down
21 changes: 21 additions & 0 deletions test/data/manifests/fedora_37-x86_64-iot_container-boot.json
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,14 @@
}
}
},
{
"id": "sha256:667a15745213f1c5f1f0bb10c70d3920913e210fed90549a81b6c42af5d39993",
"options": {
"metadata": {
"rpm.check_gpg": true
}
}
},
{
"id": "sha256:1502c8529c0e0e9e57c9a1a1635fd28fdcfc1f63004b1d5aa667baa868ea41fd",
"options": {
Expand Down Expand Up @@ -7702,6 +7710,9 @@
"sha256:66305d7a3ca92165f1c17e14cc29ea70280fa1c1fd3bf223b5b1d4f7d1ce0dd8": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f37/f37-x86_64-fedora-development-20221025/Packages/l/libsemanage-3.4-5.fc37.x86_64.rpm"
},
"sha256:667a15745213f1c5f1f0bb10c70d3920913e210fed90549a81b6c42af5d39993": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f37/f37-x86_64-fedora-development-20221025/Packages/b/biosdevname-0.7.3-10.fc37.x86_64.rpm"
},
"sha256:66e967462b711f2b62856dcb115ce53e06d58268ad7e20aa31ef282ea42b0faa": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f37/f37-x86_64-fedora-development-20221025/Packages/d/device-mapper-persistent-data-0.9.0-8.fc37.x86_64.rpm"
},
Expand Down Expand Up @@ -12865,6 +12876,16 @@
"checksum": "sha256:dc2ddc1c946a8f6b7f6d7261ab6662f953a48c160417d57591943602c1a14a70",
"check_gpg": true
},
{
"name": "biosdevname",
"epoch": 0,
"version": "0.7.3",
"release": "10.fc37",
"arch": "x86_64",
"remote_location": "https://rpmrepo.osbuild.org/v2/mirror/public/f37/f37-x86_64-fedora-development-20221025/Packages/b/biosdevname-0.7.3-10.fc37.x86_64.rpm",
"checksum": "sha256:667a15745213f1c5f1f0bb10c70d3920913e210fed90549a81b6c42af5d39993",
"check_gpg": true
},
{
"name": "bluez",
"epoch": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,14 @@
}
}
},
{
"id": "sha256:667a15745213f1c5f1f0bb10c70d3920913e210fed90549a81b6c42af5d39993",
"options": {
"metadata": {
"rpm.check_gpg": true
}
}
},
{
"id": "sha256:1502c8529c0e0e9e57c9a1a1635fd28fdcfc1f63004b1d5aa667baa868ea41fd",
"options": {
Expand Down Expand Up @@ -7869,6 +7877,9 @@
"sha256:66305d7a3ca92165f1c17e14cc29ea70280fa1c1fd3bf223b5b1d4f7d1ce0dd8": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f37/f37-x86_64-fedora-development-20221025/Packages/l/libsemanage-3.4-5.fc37.x86_64.rpm"
},
"sha256:667a15745213f1c5f1f0bb10c70d3920913e210fed90549a81b6c42af5d39993": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f37/f37-x86_64-fedora-development-20221025/Packages/b/biosdevname-0.7.3-10.fc37.x86_64.rpm"
},
"sha256:66e967462b711f2b62856dcb115ce53e06d58268ad7e20aa31ef282ea42b0faa": {
"url": "https://rpmrepo.osbuild.org/v2/mirror/public/f37/f37-x86_64-fedora-development-20221025/Packages/d/device-mapper-persistent-data-0.9.0-8.fc37.x86_64.rpm"
},
Expand Down Expand Up @@ -13052,6 +13063,16 @@
"checksum": "sha256:dc2ddc1c946a8f6b7f6d7261ab6662f953a48c160417d57591943602c1a14a70",
"check_gpg": true
},
{
"name": "biosdevname",
"epoch": 0,
"version": "0.7.3",
"release": "10.fc37",
"arch": "x86_64",
"remote_location": "https://rpmrepo.osbuild.org/v2/mirror/public/f37/f37-x86_64-fedora-development-20221025/Packages/b/biosdevname-0.7.3-10.fc37.x86_64.rpm",
"checksum": "sha256:667a15745213f1c5f1f0bb10c70d3920913e210fed90549a81b6c42af5d39993",
"check_gpg": true
},
{
"name": "bluez",
"epoch": 0,
Expand Down

0 comments on commit c2f7ddd

Please sign in to comment.