Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added check for binaries to skip "installToolsCmd" #670

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"encoding/json"
"errors"
"fmt"
"os/exec"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -35,6 +36,7 @@
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 @@
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the tools we want to check are busybox cpio dnf-utils? and if they are not already present, we want to be able to install them with microdnf,yum etc rather than just tdnf


// 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 @@
return nil
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit new line

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