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

Keep RPM DB in mariner distroless images #429

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion frontend/azlinux/handle_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func specToContainerLLB(w worker, spec *dalec.Spec, targetKey string, rpmDir llb

installOpts := []installOpt{atRoot(workPath)}
installOpts = append(installOpts, importRepos...)
installOpts = append(installOpts, []installOpt{noGPGCheck, withManifests, installWithConstraints(opts)}...)
installOpts = append(installOpts, []installOpt{noGPGCheck, installWithConstraints(opts)}...)

rootfs = builderImg.Run(
w.Install(pkgs, installOpts...),
Expand Down
51 changes: 0 additions & 51 deletions frontend/azlinux/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
)

type installConfig struct {
// Tells the installer to create the distroless rpm manifest.
manifest bool
// Disables GPG checking when installing RPMs.
// this is needed when installing unsigned RPMs.
noGPGCheck bool
Expand Down Expand Up @@ -49,10 +47,6 @@ func withMounts(opts ...llb.RunOption) installOpt {
}
}

func withManifests(cfg *installConfig) {
cfg.manifest = true
}

func atRoot(root string) installOpt {
return func(cfg *installConfig) {
cfg.root = root
Expand Down Expand Up @@ -86,40 +80,6 @@ func setInstallOptions(cfg *installConfig, opts []installOpt) {
}
}

func manifestScript(workPath string, opts ...llb.ConstraintsOpt) llb.State {
mfstDir := filepath.Join(workPath, "var/lib/rpmmanifest")
mfst1 := filepath.Join(mfstDir, "container-manifest-1")
mfst2 := filepath.Join(mfstDir, "container-manifest-2")
rpmdbDir := filepath.Join(workPath, "var/lib/rpm")

chrootedPaths := []string{
filepath.Join(workPath, "/usr/local/bin"),
filepath.Join(workPath, "/usr/local/sbin"),
filepath.Join(workPath, "/usr/bin"),
filepath.Join(workPath, "/usr/sbin"),
filepath.Join(workPath, "/bin"),
filepath.Join(workPath, "/sbin"),
}
chrootedPathEnv := strings.Join(chrootedPaths, ":")

return llb.Scratch().File(llb.Mkfile("manifest.sh", 0o700, []byte(`
#!/usr/bin/env sh

# If the rpm command is in the rootfs then we don't need to do anything
# If not then this is a distroless image and we need to generate manifests of the installed rpms and cleanup the rpmdb.

PATH="`+chrootedPathEnv+`" command -v rpm && exit 0

set -e

mkdir -p `+mfstDir+`

rpm --dbpath=`+rpmdbDir+` -qa > `+mfst1+`
rpm --dbpath=`+rpmdbDir+` -qa --qf "%{NAME}\t%{VERSION}-%{RELEASE}\t%{INSTALLTIME}\t%{BUILDTIME}\t%{VENDOR}\t(none)\t%{SIZE}\t%{ARCH}\t%{EPOCHNUM}\t%{SOURCERPM}\n" > `+mfst2+`
rm -rf `+rpmdbDir+`
`)), opts...)
}

func importGPGScript(keyPaths []string) string {
// all keys that are included should be mounted under this path
keyRoot := "/etc/pki/rpm-gpg"
Expand All @@ -133,8 +93,6 @@ func importGPGScript(keyPaths []string) string {
return importScript
}

const manifestSh = "manifest.sh"

func tdnfInstall(cfg *installConfig, relVer string, pkgs []string) llb.RunOption {
cmdFlags := tdnfInstallFlags(cfg)
// tdnf makecache is needed to ensure that the package metadata is up to date if extra repo
Expand All @@ -157,15 +115,6 @@ func tdnfInstall(cfg *installConfig, relVer string, pkgs []string) llb.RunOption
llb.SourcePath("/import-keys.sh")))
}

if cfg.manifest {
mfstScript := manifestScript(cfg.root, cfg.constraints...)

manifestPath := filepath.Join("/tmp", manifestSh)
runOpts = append(runOpts, llb.AddMount(manifestPath, mfstScript, llb.SourcePath(manifestSh)))

cmdArgs += "; " + manifestPath
}

runOpts = append(runOpts, dalec.ShArgs(cmdArgs))
runOpts = append(runOpts, cfg.mounts...)

Expand Down
11 changes: 4 additions & 7 deletions test/fixtures/moby-runc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@ x-azl: &azl
- name: mariner rpm manifest files
files:
/var/lib/rpmmanifest/container-manifest-1:
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove these checks for the manifest.

contains:
- "moby-runc-${VERSION}-"
- "libseccomp-"
not_exist: true
/var/lib/rpmmanifest/container-manifest-2:
contains:
- "moby-runc-${VERSION}-"
- "libseccomp-"
/var/lib/rpm:
not_exist: true
/var/lib/rpm:
is_dir: true
/var/lib/rpm/rpmdb.sqlite:

targets: # Distro specific build requirements
azlinux3:
Expand Down