func()

in targets/linux/rpm/distro/container.go [17:83]


func (cfg *Config) BuildContainer(ctx context.Context, client gwclient.Client, worker llb.State, sOpt dalec.SourceOpts, spec *dalec.Spec, targetKey string, rpmDir llb.State, opts ...llb.ConstraintsOpt) (llb.State, error) {
	opts = append(opts, dalec.ProgressGroup("Install RPMs"))
	const workPath = "/tmp/rootfs"

	bi, err := spec.GetSingleBase(targetKey)
	if err != nil {
		return llb.Scratch(), err
	}

	skipBase := bi != nil
	rootfs, err := bi.ToState(sOpt, opts...)
	if err != nil {
		return llb.Scratch(), err
	}

	installTimeRepos := spec.GetInstallRepos(targetKey)
	repoMounts, keyPaths, err := cfg.RepoMounts(installTimeRepos, sOpt, opts...)
	if err != nil {
		return llb.Scratch(), err
	}
	importRepos := []DnfInstallOpt{DnfWithMounts(repoMounts), DnfImportKeys(keyPaths)}

	rpmMountDir := "/tmp/rpms"

	installOpts := []DnfInstallOpt{DnfAtRoot(workPath)}
	installOpts = append(installOpts, importRepos...)
	installOpts = append(installOpts, []DnfInstallOpt{
		DnfNoGPGCheck,
		dnfInstallWithConstraints(opts)}...)

	baseMountPath := rpmMountDir + "-base"
	basePkgs := llb.Scratch().File(llb.Mkdir("/RPMS", 0o755))
	pkgs := []string{
		filepath.Join(rpmMountDir, "**/*.rpm"),
	}

	if !skipBase && len(cfg.BasePackages) > 0 {
		opts := append(opts, dalec.ProgressGroup("Create base virtual package"))

		var basePkgStates []llb.State
		for _, spec := range cfg.BasePackages {
			pkg, err := cfg.BuildPkg(ctx, client, worker, sOpt, &spec, targetKey, opts...)
			if err != nil {
				return llb.Scratch(), errors.Wrap(err, "error building base runtime deps package")
			}
			basePkgStates = append(basePkgStates, pkg)
		}

		basePkgs = dalec.MergeAtPath(basePkgs, basePkgStates, "/")
		pkgs = append(pkgs, filepath.Join(baseMountPath, "**/*.rpm"))
	}

	rootfs = worker.Run(
		cfg.Install(pkgs, installOpts...),
		llb.AddMount(rpmMountDir, rpmDir, llb.SourcePath("/RPMS")),
		llb.AddMount(baseMountPath, basePkgs, llb.SourcePath("/RPMS")),
		dalec.WithConstraints(opts...),
	).AddMount(workPath, rootfs)

	if post := spec.GetImagePost(targetKey); post != nil && len(post.Symlinks) > 0 {
		rootfs = worker.
			Run(dalec.WithConstraints(opts...), dalec.InstallPostSymlinks(post, workPath)).
			AddMount(workPath, rootfs)
	}

	return rootfs, nil
}