@@ -17,6 +17,7 @@ import (
1717 "github.com/moby/buildkit/client/llb"
1818 ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1919 "github.com/project-copacetic/copacetic/pkg/buildkit"
20+ "github.com/project-copacetic/copacetic/pkg/types"
2021 "github.com/project-copacetic/copacetic/pkg/types/unversioned"
2122 "github.com/project-copacetic/copacetic/pkg/utils"
2223 log "github.com/sirupsen/logrus"
@@ -489,25 +490,31 @@ func (rm *rpmManager) installUpdates(ctx context.Context, updates unversioned.Up
489490 if dnfTooling == "" {
490491 dnfTooling = rm .rpmTools ["dnf" ]
491492 }
492- checkUpdateTemplate := `sh -c '%[1]s clean all && %[1]s makecache --refresh -y; if [ "$(%[1]s -q check-update | wc -l)" -ne 0 ]; then echo >> /updates.txt; fi'`
493- if ! rm .checkForUpgrades (ctx , dnfTooling , checkUpdateTemplate ) {
494- return nil , nil , fmt .Errorf ("no patchable packages found" )
493+ if updates == nil {
494+ checkUpdateTemplate := `sh -c '%[1]s clean all && %[1]s makecache --refresh -y; if [ "$(%[1]s -q check-update | wc -l)" -ne 0 ]; then echo >> /updates.txt; fi'`
495+ if ! rm .checkForUpgrades (ctx , dnfTooling , checkUpdateTemplate ) {
496+ return nil , nil , types .ErrNoUpdatesFound
497+ }
495498 }
496499
497500 const dnfInstallTemplate = `sh -c '%[1]s upgrade --refresh %[2]s -y && %[1]s clean all'`
498501 installCmd = fmt .Sprintf (dnfInstallTemplate , dnfTooling , pkgs )
499502 case rm .rpmTools ["yum" ] != "" :
500- checkUpdateTemplate := `sh -c '%[1]s clean all && %[1]s makecache fast; if [ "$(%[1]s -q check-update | wc -l)" -ne 0 ]; then echo >> /updates.txt; fi'`
501- if ! rm .checkForUpgrades (ctx , rm .rpmTools ["yum" ], checkUpdateTemplate ) {
502- return nil , nil , fmt .Errorf ("no patchable packages found" )
503+ if updates == nil {
504+ checkUpdateTemplate := `sh -c '%[1]s clean all && %[1]s makecache fast; if [ "$(%[1]s -q check-update | wc -l)" -ne 0 ]; then echo >> /updates.txt; fi'`
505+ if ! rm .checkForUpgrades (ctx , rm .rpmTools ["yum" ], checkUpdateTemplate ) {
506+ return nil , nil , types .ErrNoUpdatesFound
507+ }
503508 }
504509
505510 const yumInstallTemplate = `sh -c '%[1]s upgrade %[2]s -y && %[1]s clean all'`
506511 installCmd = fmt .Sprintf (yumInstallTemplate , rm .rpmTools ["yum" ], pkgs )
507512 case rm .rpmTools ["microdnf" ] != "" :
508- checkUpdateTemplate := `sh -c "%[1]s install dnf -y; dnf clean all && dnf makecache --refresh -y; dnf check-update -y; if [ $? -ne 0 ]; then echo >> /updates.txt; fi;"`
509- if ! rm .checkForUpgrades (ctx , rm .rpmTools ["microdnf" ], checkUpdateTemplate ) {
510- return nil , nil , fmt .Errorf ("no patchable packages found" )
513+ if updates == nil {
514+ checkUpdateTemplate := `sh -c "%[1]s install dnf -y; dnf clean all && dnf makecache --refresh -y; dnf check-update -y; if [ $? -ne 0 ]; then echo >> /updates.txt; fi;"`
515+ if ! rm .checkForUpgrades (ctx , rm .rpmTools ["microdnf" ], checkUpdateTemplate ) {
516+ return nil , nil , types .ErrNoUpdatesFound
517+ }
511518 }
512519
513520 const microdnfInstallTemplate = `sh -c '%[1]s update %[2]s -y && %[1]s clean all'`
@@ -619,28 +626,30 @@ func (rm *rpmManager) unpackAndMergeUpdates(ctx context.Context, updates unversi
619626 llb .AddEnv ("PACKAGES_PRESENT" , string (jsonPackageData )),
620627 llb .Args ([]string {
621628 `bash` , `-c` , `
622- json_str=$PACKAGES_PRESENT
623- update_packages=""
624-
625- while IFS=':' read -r package version; do
626- pkg_name=$(echo "$package" | sed 's/^"\(.*\)"$/\1/')
629+ json_str=$PACKAGES_PRESENT
630+ update_packages=""
627631
628- pkg_version=$(echo "$version" | sed 's/^"\(.*\)"$/\1/')
629- latest_version=$(yum list available $pkg_name 2>/dev/null | grep $pkg_name | tail -n 1 | tr -s ' ' | cut -d ' ' -f 2 )
632+ while IFS=':' read -r package version; do
633+ pkg_name=$(echo "$package" | sed 's/^"\(.*\)"$/\1/' )
630634
631- if [ "$latest_version" != "$pkg_version" ]; then
632- update_packages="$update_packages $pkg_name"
633- fi
634- done <<< "$(echo "$json_str" | tr -d '{}\n' | tr ',' '\n')"
635+ pkg_version=$(echo "$version" | sed 's/^"\(.*\)"$/\1/')
636+ latest_version=$(yum list available $pkg_name 2>/dev/null | grep $pkg_name | tail -n 1 | tr -s ' ' | cut -d ' ' -f 2)
635637
636- if [ -z "$update_packages " ]; then
637- echo "No packages to update "
638- exit 1
639- fi
638+ if [ "$latest_version" != "$pkg_version " ]; then
639+ update_packages="$update_packages $pkg_name "
640+ fi
641+ done <<< "$(echo "$json_str" | tr -d '{}\n' | tr ',' '\n')"
640642
641- echo "$update_packages" > packages.txt
642- ` ,
643+ if [ -n "$update_packages" ]; then
644+ echo "$update_packages" > packages.txt
645+ touch /updates.txt
646+ fi
647+ ` ,
643648 })).Root ()
649+ if _ , err := buildkit .ExtractFileFromState (ctx , rm .config .Client , & busyboxCopied , "/updates.txt" ); err != nil {
650+ log .Info ("No upgradable packages found for this image (RPM distroless path)." )
651+ return nil , nil , types .ErrNoUpdatesFound
652+ }
644653 }
645654
646655 // Create a new state for tooling image with all the packages from the image we are trying to patch
0 commit comments