Skip to content

podman buildx inspect #26232

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

2004joshua
Copy link

@2004joshua 2004joshua commented May 29, 2025

I added support for "podman buildx inspect". The goal was to replicate "docker buildx inspect" as much as possible but a problem encountered was podman doesn't use docker's Buildkit so to replicate the output I resorted to printing the statements. I used the default names docker used for its output but changed the driver name to podman. Since there was no Buildkit I picked "N/A" as a viable option to describe the version of Buildkit being used. I used the Emulated Architectures + Host Architecture as the supported platforms, when running podman in remote mode it will only return the Server Architecture. The --bootstrap flag was also added, its purpose was to make sure the builderkit container is running before you inspect but since there is none I considered it to be a NOP flag. I also added an extra field to the HostInfo struct so I am able to get the emulated architectures through the engine so a new field to podman info was also introduced as a result.

Fixes #13014

Does this PR introduce a user-facing change?

yes

@openshift-ci openshift-ci bot added the do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None label May 29, 2025
Copy link
Contributor

openshift-ci bot commented May 29, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 2004joshua
Once this PR has been reviewed and has the lgtm label, please assign baude for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added release-note and removed do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None labels May 29, 2025
}

fmt.Printf("Name: %s\n", out.builderName)
fmt.Printf("Driver: %s\n", out.driverName)
Copy link
Member

Choose a reason for hiding this comment

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

is there ever going to be a need for formatted output (like json?)

Copy link
Author

Choose a reason for hiding this comment

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

No, the way docker does it is they also use prints

Copy link
Member

Choose a reason for hiding this comment

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

I dont think that makes it "right" . @Luap99 you have kind of become the defacto fmt guy on the team, would you prefer we use structs and templates or OK with this?

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 a template would be nicer but I don't care that much.

@2004joshua 2004joshua force-pushed the buildxInspect branch 2 times, most recently from 5c4be6c to ba86eb2 Compare May 29, 2025 16:48
Expect(output).To(MatchRegexp(`Platforms:\s+.*\b` + regexp.QuoteMeta(expectedNativePlatform) + `\b`))
})

It("podman buildx inspect", func() {
Copy link
Member

@jankaluza jankaluza May 30, 2025

Choose a reason for hiding this comment

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

Great that you introduced tests for this change :-).

I think there's a some duplicated code here:

  • Native platform parsing
  • Emulated Architectures parsing
  • Expected Platform assertions

Maybe you could move these to separated functions and reuse them to make the tests easier to read and also edit in the future if we change the way how this command behaves.

Copy link
Member

Choose a reason for hiding this comment

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

I agree it is quite hard to read the tests due the duplication.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

Welcome to the team, I am not familiar with docker buildx output so I cannot comment on the specifcs there so these are mostly general style comments.

if registry.IsRemote() {
runtimeOS := infoReport.Host.OS
runtimeArch := infoReport.Host.Arch
defaultNode.Platforms = []string{fmt.Sprintf("%s/%s", runtimeOS, runtimeArch)}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this not using infoReport.Host.EmulatedArchitectures? The build will happen on the remote system so listing th elocal arch of the client seems not correct?

Copy link
Author

Choose a reason for hiding this comment

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

The reason I didn't include emulation.Registered() for remote builds was because the build tag in emulation.go had //go:build !remote so there wasn't a way to get those emulated archs. It also doesn't list the arch of the client it give you the remote system arch.

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 want the remote system's architectures, though? The build happens on the server, so we should be reporting what the server can do?

Comment on lines 52 to 54
ctx := cmd.Context()

infoReport, infoErr := registry.ContainerEngine().Info(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

for consistency the rest of the cli code uses registry.Context() so this should to.

Copy link
Author

Choose a reason for hiding this comment

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

added this change

Comment on lines 54 to 56
infoReport, infoErr := registry.ContainerEngine().Info(ctx)

if infoErr != nil {
return fmt.Errorf("retrieving podman engine information: %w", infoErr)
}
Copy link
Member

Choose a reason for hiding this comment

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

As general rule unless you must store the error for latter go error variables are generally called err and there is no newline between the call and if err != nil { return err} branch. Second, I would remove the word "engine" from the error. We don't say podman engine.

Comment on lines 17 to 19
if !registry.IsRemote() {
Skip("This test is only applicable for remote podman")
}
Copy link
Member

Choose a reason for hiding this comment

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

Why are these skipped on remote? Looking at the podman code the command has a branch for if remote but it should work fine. All tests here skip on remote which means the IsRemote() condition in the actual comman is never executed.

Second calling registry.IsRemote() is actually incorrect from test context and doesn't do what you want. If you really have to skip on remote one must use SkipIfRemote() which uses IsRemote from the e2e package. Notice how this is using the remote_testing build tag to switch the behaviour. registry.IsRemote() passes cli arguments which makes no sense in the context of ginkgo tests.

Expect(output).To(MatchRegexp(`Platforms:\s+.*\b` + regexp.QuoteMeta(expectedNativePlatform) + `\b`))
})

It("podman buildx inspect", func() {
Copy link
Member

Choose a reason for hiding this comment

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

I agree it is quite hard to read the tests due the duplication.

Comment on lines 50 to 51
stdErr := session.ErrorToString()
Expect(stdErr).ToNot(MatchRegexp(`(?i)error starting|fail|fatal|panic`), "stderr should not contain critical error keywords, got: %s", stdErr)
Copy link
Member

Choose a reason for hiding this comment

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

this is not checking anything ExitCleanly() verifies already that there is not stderr output so there is no reason to regex check any of its output.

backendHostOS := strings.TrimSpace(hostOSSession.OutputToString())
Expect(backendHostOS).ToNot(BeEmpty())

emulatedArchsNamesSession := podmanTest.PodmanExitCleanly("info", "--format", "{{.Host.EmulatedArchitectures}}")
Copy link
Member

Choose a reason for hiding this comment

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

you can use {{json .Host.EmulatedArchitectures}} which gives you a json array and then just json.Unmarshal() the result into a []string which should simplyfy the manual string parsing you are doing here.

Comment on lines 133 to 134
stdErr := session.ErrorToString()
Expect(stdErr).ToNot(MatchRegexp(`(?i)error starting|fail|fatal|panic`), "stderr should not contain critical error keywords, got: %s", stdErr)
Copy link
Member

Choose a reason for hiding this comment

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

same as above, and same comment on deduplication.

@2004joshua 2004joshua force-pushed the buildxInspect branch 3 times, most recently from e6c42a0 to 14cf99e Compare May 30, 2025 23:19
Added support for "podman buildx inspect". The goal was to replicate the default output from "docker buildx inspect" as
much as possible but a problem encountered was podman not supporting BuildKit. To replicate the output I resorted to
printing the statements with default values but only changed the driver name to use podman instead of docker. Since
there was no buildkit, gave it the value of "N/A" to depict it's not supported. For Platforms, I resorted to using
the emulated architectures found on your linux system + the host architecture of your local machine or podman server. The
bootstrap flag was also added but is considered a NOP since there is no buildkit container to run before running inspect.
An extra field was added to the HostInfo struct so when you run "podman info" the emulated architectures will show, this
was used so you can grab the information from the podman engine.

Fixes containers#13014

Signed-off-by: Joshua Arrevillaga <[email protected]>

func init() {
buildxInspectCmd.Flags().Bool("bootstrap", false, "Currently a No Op for podman")
registry.Commands = append(registry.Commands, registry.CliCommand{
Copy link
Member

Choose a reason for hiding this comment

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

@Luap99 What would you say about marking this one as hidden? I don't think we necessarily want this in podman buildx --help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The buildx inspect command is missing
6 participants