Skip to content

Commit

Permalink
dnf: mark packages as user
Browse files Browse the repository at this point in the history
  • Loading branch information
supakeen committed Jul 14, 2023
1 parent da35345 commit f5f4fb0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/manifest/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (p *OS) getContainerSpecs() []container.Spec {
}

func (p *OS) serializeStart(packages []rpmmd.PackageSpec, containers []container.Spec, commits []ostree.CommitSpec) {
if len(p.packageSpecs) > 0 {
if len(p.getPackageSpecs()) > 0 {
panic("double call to serializeStart()")
}

Expand All @@ -331,12 +331,12 @@ func (p *OS) serializeStart(packages []rpmmd.PackageSpec, containers []container
}

if p.KernelName != "" {
p.kernelVer = rpmmd.GetVerStrFromPackageSpecListPanic(p.packageSpecs, p.KernelName)
p.kernelVer = rpmmd.GetVerStrFromPackageSpecListPanic(p.getPackageSpecs(), p.KernelName)
}
}

func (p *OS) serializeEnd() {
if len(p.packageSpecs) == 0 {
if len(p.getPackageSpecs()) == 0 {
panic("serializeEnd() call when serialization not in progress")
}
p.kernelVer = ""
Expand All @@ -346,7 +346,7 @@ func (p *OS) serializeEnd() {
}

func (p *OS) serialize() osbuild.Pipeline {
if len(p.packageSpecs) == 0 {
if len(p.getPackageSpecs()) == 0 {
panic("serialization not started")
}

Expand All @@ -373,7 +373,9 @@ func (p *OS) serialize() osbuild.Pipeline {
rpmOptions.OSTreeBooted = common.ToPtr(true)
rpmOptions.DBPath = "/usr/share/rpm"
}
pipeline.AddStage(osbuild.NewRPMStage(rpmOptions, osbuild.NewRpmStageSourceFilesInputs(p.packageSpecs)))
pipeline.AddStage(osbuild.NewRPMStage(rpmOptions, osbuild.NewRpmStageSourceFilesInputs(p.getPackageSpecs())))

pipeline.AddStage(osbuild.NewDNFMarkStageFromPackageSpecs(p.getPackageSpecs()))

if !p.NoBLS {
// If the /boot is on a separate partition, the prefix for the BLS stage must be ""
Expand Down Expand Up @@ -608,7 +610,7 @@ func (p *OS) serialize() osbuild.Pipeline {
Nick: p.OSNick,
}

_, err := rpmmd.GetVerStrFromPackageSpecList(p.packageSpecs, "dracut-config-rescue")
_, err := rpmmd.GetVerStrFromPackageSpecList(p.getPackageSpecs(), "dracut-config-rescue")
hasRescue := err == nil
bootloader = osbuild.NewGrub2LegacyStage(
osbuild.NewGrub2LegacyStageOptions(
Expand Down
54 changes: 54 additions & 0 deletions pkg/osbuild/dnf_mark_stage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package osbuild

import "github.com/osbuild/images/pkg/rpmmd"

type DNFMarkStagePackageOptions struct {
Name string `json:"name"`
Mark string `json:"mark"`
Group string `json:"group,omitempty"`
}

type DNFMarkStageOptions struct {
Packages []DNFMarkStagePackageOptions `json:"packages"`
}

func (o DNFMarkStageOptions) isStageOptions() {}

func (o DNFMarkStageOptions) validate() error {
return nil
}

func NewDNFMarkStageOptions(packages []DNFMarkStagePackageOptions) *DNFMarkStageOptions {
return &DNFMarkStageOptions{
Packages: packages,
}
}

type DNFMarkStage struct {
}

func NewDNFMarkStage(options *DNFMarkStageOptions) *Stage {
if err := options.validate(); err != nil {
panic(err)
}

return &Stage{
Type: "org.osbuild.dnf.mark",
Options: options,
}
}

func NewDNFMarkStageFromPackageSpecs(packageSpecs []rpmmd.PackageSpec) *Stage {
var packages []DNFMarkStagePackageOptions

for _, ps := range packageSpecs {
packages = append(packages, DNFMarkStagePackageOptions{
Name: ps.Name,
Mark: "user",
})
}

options := NewDNFMarkStageOptions(packages)

return NewDNFMarkStage(options)
}

0 comments on commit f5f4fb0

Please sign in to comment.