Skip to content

Commit

Permalink
fix: add apk add (#60)
Browse files Browse the repository at this point in the history
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
  • Loading branch information
sozercan committed Mar 9, 2023
1 parent 60433a8 commit adc6f10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test-images.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"distro": "Alpine",
"description": "Valid apk/db, apk present"
},
{
"image": "mcr.microsoft.com/oss/grafana/grafana-image-renderer",
"tag": "v3.6.2",
"distro": "Alpine",
"description": "Valid apk/db, apk present, tiff package with dependencies"
},
{
"image": "mcr.microsoft.com/oss/nginx/nginx",
"tag": "1.21.6",
Expand Down
16 changes: 11 additions & 5 deletions pkg/pkgmgr/apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,23 @@ func (am *apkManager) upgradePackages(ctx context.Context, updates types.UpdateP
// TODO: Add support for custom APK config
apkUpdated := am.config.ImageState.Run(llb.Shlex("apk update")).Root()

// Add all requested update packages
// This works around cases where some packages (for example, tiff) require other packages in it's dependency tree to be updated
const apkAddTemplate = `apk add --no-cache %s`
pkgStrings := []string{}
for _, u := range updates {
pkgStrings = append(pkgStrings, u.Name)
}
addCmd := fmt.Sprintf(apkAddTemplate, strings.Join(pkgStrings, " "))
apkAdded := apkUpdated.Run(llb.Shlex(addCmd)).Root()

// Install all requested update packages without specifying the version. This works around:
// - Reports being slightly out of date, where a newer security revision has displaced the one specified leading to not found errors.
// - Reports not specifying version epochs correct (e.g. bsdutils=2.36.1-8+deb11u1 instead of with epoch as 1:2.36.1-8+dev11u1)
// Note that this keeps the log files from the operation, which we can consider removing as a size optimization in the future.
const apkInstallTemplate = `apk upgrade --no-cache %s`
pkgStrings := []string{}
for _, u := range updates {
pkgStrings = append(pkgStrings, u.Name)
}
installCmd := fmt.Sprintf(apkInstallTemplate, strings.Join(pkgStrings, " "))
apkInstalled := apkUpdated.Run(llb.Shlex(installCmd)).Root()
apkInstalled := apkAdded.Run(llb.Shlex(installCmd)).Root()

// Write updates-manifest to host for post-patch validation
const outputResultsTemplate = `sh -c 'apk info --installed -v %s > %s; if [[ $? -ne 0 ]]; then echo "WARN: apk info --installed returned $?"; fi'`
Expand Down

0 comments on commit adc6f10

Please sign in to comment.