Skip to content

Commit

Permalink
Fixes #652 Updated probeRPMStatus to check if binaries are present
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Singh <[email protected]>
  • Loading branch information
SkySingh04 committed Jun 19, 2024
1 parent 975aab2 commit d959a94
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions pkg/pkgmgr/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"os/exec"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -35,6 +36,7 @@ const (
rpmManifestWildcard = "container-manifest-*"

installToolsCmd = "tdnf install busybox cpio dnf-utils -y"
isBinariesCmd = "sh -c 'ls /usr/sbin/busybox /usr/bin/rpm /usr/bin/yum /usr/bin/dnf /usr/bin/microdnf'"
resultQueryFormat = "%{NAME}\t%{VERSION}-%{RELEASE}\t%{ARCH}\n"
)

Expand Down Expand Up @@ -247,14 +249,31 @@ func (rm *rpmManager) probeRPMStatus(ctx context.Context, toolImage string) erro
llb.ResolveModeDefault,
)

toolsInstalled := toolingBase.Run(llb.Shlex(installToolsCmd), llb.WithProxy(utils.GetProxy())).Root()
toolsApplied := rm.config.ImageState.File(llb.Copy(toolsInstalled, "/usr/sbin/busybox", "/usr/sbin/busybox"))
toolList := []string{"dnf", "microdnf", "rpm", "yum"}
missingTools := make([]string, 0)

Check warning on line 253 in pkg/pkgmgr/rpm.go

View check run for this annotation

Codecov / codecov/patch

pkg/pkgmgr/rpm.go#L252-L253

Added lines #L252 - L253 were not covered by tests

// Check if required tools are already present in the image
for _, tool := range toolList {
toolPath, err := exec.LookPath(tool)
if err != nil || toolPath == "" {
missingTools = append(missingTools, tool)

Check warning on line 259 in pkg/pkgmgr/rpm.go

View check run for this annotation

Codecov / codecov/patch

pkg/pkgmgr/rpm.go#L256-L259

Added lines #L256 - L259 were not covered by tests
}
}

var toolsApplied llb.State
if len(missingTools) > 0 {
log.Info("Required tools are missing, proceeding with tool installation...")
toolsInstalled := toolingBase.Run(llb.Shlex(installToolsCmd), llb.WithProxy(utils.GetProxy())).Root()
toolsApplied = rm.config.ImageState.File(llb.Copy(toolsInstalled, "/usr/sbin/busybox", "/usr/sbin/busybox"))
} else {
log.Info("All required tools are present, skipping tool installation.")
toolsApplied = rm.config.ImageState

Check warning on line 270 in pkg/pkgmgr/rpm.go

View check run for this annotation

Codecov / codecov/patch

pkg/pkgmgr/rpm.go#L263-L270

Added lines #L263 - L270 were not covered by tests
}

mkFolders := toolsApplied.
File(llb.Mkdir(resultsPath, 0o744, llb.WithParents(true))).
File(llb.Mkdir(inputPath, 0o744, llb.WithParents(true)))

toolList := []string{"dnf", "microdnf", "rpm", "yum"}

rpmDBList := []string{
filepath.Join(rpmLibPath, rpmBDB),
filepath.Join(rpmLibPath, rpmNDB),
Expand Down Expand Up @@ -353,6 +372,7 @@ func (rm *rpmManager) probeRPMStatus(ctx context.Context, toolImage string) erro
return nil
}


func parseManifestFile(file string) (map[string]string, error) {
// split into lines
file = strings.TrimSuffix(file, "\n")
Expand Down

0 comments on commit d959a94

Please sign in to comment.