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

Refactor RPM handlers and Reorganize Code for Linux targets #493

Merged
merged 15 commits into from
Feb 20, 2025

Conversation

adamperlin
Copy link
Contributor

@adamperlin adamperlin commented Jan 8, 2025

This PR refactors the handlers for RPM targets to be methods on a distro config, almost identical to how the DEB targets work. For example, installing build dependencies, building and testing a package, installing in a container, and the like should not vary much between rpm-based distros, so the functionality has been made into methods that encode the functionality for all rpm distros.

As part of this change, the project structure was altered to nest functionality common to RPM targets under frontend/linux/rpm, and functionality common to deb targets has been moved to frontend/linux/deb. A DistroConfig interface common to both is under frontend/linux. The DistroConfig interface is meant to encode what kinds of functionality any new type of distro would need to provide, such that the generic handlers HandleContainer(DistroConfig) and HandlePackage(DistroConfig) can be used for distro/container and distro/<package> type targets.

Special notes for your reviewer:
Many of the changed files in this PR are simply renames or changes of a single import, so the number of substantively changed files is much less than the diff shows.

@adamperlin adamperlin force-pushed the adamperlin/refactor-rpm branch from d834e04 to 1ca8771 Compare January 8, 2025 19:38
@adamperlin adamperlin force-pushed the adamperlin/refactor-rpm branch from 1e3f133 to 0212f81 Compare January 9, 2025 18:05
@adamperlin adamperlin force-pushed the adamperlin/refactor-rpm branch from 3a81bef to 8fd0366 Compare January 9, 2025 18:38
@@ -0,0 +1,49 @@
package rpm
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code hasn't changed beyond method renames

func (cfg *Config) Handle(ctx context.Context, client gwclient.Client) (*gwclient.Result, error) {
var mux frontend.BuildMux

mux.Add("rpm", linux.HandlePackage(cfg), &targets.Target{
Copy link
Contributor Author

@adamperlin adamperlin Jan 9, 2025

Choose a reason for hiding this comment

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

We can use the root generic linux.HandlePackage for this, parameterized on the cfg


type PackageInstaller func(*dnfInstallConfig, string, []string) llb.RunOption

type dnfInstallConfig struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only have a dnf install config and not a tdnfInstallConfig, since in Dalec thus far every option we use is both dnf and tdnf compatible. In the future as we add more distros, we may need to rethink this portion, but if we stick to only using the options that are the same between the two, then it makes our life easier!


}

func DnfInstall(cfg *dnfInstallConfig, releaseVer string, pkgs []string) llb.RunOption {
Copy link
Contributor Author

@adamperlin adamperlin Jan 9, 2025

Choose a reason for hiding this comment

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

I've split out the install methods between TdnfInstall/DnfInstall maybe prematurely, in case there are differences between dnf and tdnf. In particular, I'm not sure if the separate /import-keys.sh script is needed for dnf yet, since we haven't yet added distros that use dnf.

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

WDYT about moving the rpm/deb stuff into a top-level package like packaging/rpm and packaging/deb or even packaging/linux/rpm and packaging/linux/deb?

Likewise I think we can move all the targets stuff into a top-level package called targets.

@adamperlin
Copy link
Contributor Author

@cpuguy83 I am definitely open to that! I think splitting the targets and the packaging pieces out makes a lot of sense!

…d top-level handler helper functions) to a new targets/ dir.

We now have targets/linux/deb for debian/ubuntu, targets/linux/rpm for azlinux, and targets/windows for windows.

Move packaging specific code -- for example, code for building up deb and rpm spec files + utility functions for creating buildroot state to a new packaging/ dir.
The only code that remains under frontend/ is specific to the frontend itself, i.e. the frontend entrypoint, target routing, helpers that are specific to all
targets, helpers for solve requests to buildkit, etc.
@adamperlin adamperlin force-pushed the adamperlin/refactor-rpm branch from 54ec7f2 to cb3dd0f Compare February 14, 2025 18:03
@adamperlin adamperlin marked this pull request as ready for review February 14, 2025 18:18
@adamperlin adamperlin requested a review from a team as a code owner February 14, 2025 18:18
@adamperlin
Copy link
Contributor Author

This should be ready for another look @cpuguy83 @MorrisLaw!

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

This LGTM

I do have some nits about the package structure, but not a blocker.

For the targets package, I feel like each of the distro subpackages are uneccessary.
Instead we can have something like targets.Bookworm which would be the distro config for bookworm, as an example.

I also think the linux and windows subpackages probably aren't neccessary.
LIkewise in the packaging package.

But overall, this is a nice change.
Thank you!

@cpuguy83 cpuguy83 merged commit 449d2a6 into Azure:main Feb 20, 2025
18 checks passed
@adamperlin
Copy link
Contributor Author

That makes sense! I can possibly do a follow up to remove some of those subpackages!

@adamperlin adamperlin deleted the adamperlin/refactor-rpm branch February 20, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants