-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
base: main
Are you sure you want to change the base?
podman buildx inspect #26232
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 2004joshua 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 |
} | ||
|
||
fmt.Printf("Name: %s\n", out.builderName) | ||
fmt.Printf("Driver: %s\n", out.driverName) |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
5c4be6c
to
ba86eb2
Compare
Expect(output).To(MatchRegexp(`Platforms:\s+.*\b` + regexp.QuoteMeta(expectedNativePlatform) + `\b`)) | ||
}) | ||
|
||
It("podman buildx inspect", func() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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)} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
cmd/podman/images/buildx_inspect.go
Outdated
ctx := cmd.Context() | ||
|
||
infoReport, infoErr := registry.ContainerEngine().Info(ctx) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this change
cmd/podman/images/buildx_inspect.go
Outdated
infoReport, infoErr := registry.ContainerEngine().Info(ctx) | ||
|
||
if infoErr != nil { | ||
return fmt.Errorf("retrieving podman engine information: %w", infoErr) | ||
} |
There was a problem hiding this comment.
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.
test/e2e/buildx_inspect_test.go
Outdated
if !registry.IsRemote() { | ||
Skip("This test is only applicable for remote podman") | ||
} |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
test/e2e/buildx_inspect_test.go
Outdated
stdErr := session.ErrorToString() | ||
Expect(stdErr).ToNot(MatchRegexp(`(?i)error starting|fail|fatal|panic`), "stderr should not contain critical error keywords, got: %s", stdErr) |
There was a problem hiding this comment.
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.
test/e2e/buildx_inspect_test.go
Outdated
backendHostOS := strings.TrimSpace(hostOSSession.OutputToString()) | ||
Expect(backendHostOS).ToNot(BeEmpty()) | ||
|
||
emulatedArchsNamesSession := podmanTest.PodmanExitCleanly("info", "--format", "{{.Host.EmulatedArchitectures}}") |
There was a problem hiding this comment.
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.
test/e2e/buildx_inspect_test.go
Outdated
stdErr := session.ErrorToString() | ||
Expect(stdErr).ToNot(MatchRegexp(`(?i)error starting|fail|fatal|panic`), "stderr should not contain critical error keywords, got: %s", stdErr) |
There was a problem hiding this comment.
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.
e6c42a0
to
14cf99e
Compare
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{ |
There was a problem hiding this comment.
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
?
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?