-
Notifications
You must be signed in to change notification settings - Fork 785
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
cmd/build: add support for --push
#4677
base: main
Are you sure you want to change the base?
Conversation
I was thinking this would just be added to the client and not the service side. buildah build --push Would internally do buildah build followed by buildah push. |
What do you think @nalind @flouthoc @vrothberg |
That would be simpler; API callers already have a For the "output=registry" case, setting |
And just in case, we'll need updates to the man page and additional test added for the final PR. From a quick flyby review, it LGTM other than other comments. |
I am no fan of mixing multiple commands as it breaks separation of concerns. But I leave the decision up to the core maintainers of Buildah. |
I see this for compatibility with buildx I don't think we have to add other options for push, and potentially could have just done this in podman build, but the --output=type calls are handled within buildah. |
I concur should we just do this at podman, and only add |
07d26e5
to
f934001
Compare
I honestly didn't think that is how we'd want to push. On the outset,
You're right, that was an oversight. |
So adding the |
internal/util/util.go
Outdated
|
||
image := opts.Attrs["name"] | ||
destSpec := opts.Attrs["name"] | ||
dest, err := alltransports.ParseImageName(destSpec) |
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 am not sure this code is correct, or necessary. I know that @mtrmac and @vrothberg frown on parsing specs outside of github.com/containers/image or github.com/containers/common/libimage
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.
Yes; as a general principle I think the CLI layer, or something as close to it as possible, should be responsible for turning strings into a unique types.ImageReference
.
Admittedly that’s not always possible, but it’s the thing to strive for.
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.
Does it help if it's moved to util? #4677 (comment)
define/types.go
Outdated
@@ -100,6 +100,8 @@ type Secret struct { | |||
|
|||
// BuildOutputOptions contains the the outcome of parsing the value of a build --output flag | |||
type BuildOutputOption struct { | |||
Type string | |||
Attrs map[string]string |
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 adding an untyped map instead simple Go fields that exactly represent what we need?
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 was referenced from buildx but the idea remains the same, for every type, there are (and would be in the future) multiple arguments/options which are consolidated under attributes here. It's possible for us to have individual fields here but those would eventually proliferate into a heterogenous struct type and I'm not sure how ideal that would be.
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 ultimately up to Buildah maintainers, not me.
IMHO individual fields, or individual types, is much better than Attrs
, because Attrs
is equally heterogenous, just with much worse compiler / linter support.
We can do interfaces, type checks, wrappers, …
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.
That's a good point. Perhaps we can have embedded structs here for individual Types as and when the situation arises? Looking for inputs
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.
Up to Buildah maintainers.
(My personal style would be:
Type
field first- Then separate sections for individual subtypes, separated by blank lines and with a comment “valid if Type == … ”
so that future maintainers can just look at the type definition and don’t have to chase individual field uses in an IDE.
I agree that separate structs, or even type checks, might be overkill for this small scope.)
internal/util/util.go
Outdated
libimageOptions.Writer = os.Stdout | ||
runtime, err := libimage.RuntimeFromStore(store, &libimage.RuntimeOptions{SystemContext: &types.SystemContext{}}) | ||
destString := fmt.Sprintf("%s:%s", dest.Transport().Name(), dest.StringWithinTransport()) | ||
_, err = runtime.Push(context.Background(), image, destString, libimageOptions) |
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.
(Eventually, could libImage
have an API that accepts type.ImageReference
directly?)
e22f351
to
d6925cd
Compare
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.
It’s quite likely I don’t have a full context of the goals / constraints of the Buildx feature set or compatibility; I’m looking basically only at this PR in isolation.
I’ll fully defer to actual Buildah maintainers.
util/util.go
Outdated
@@ -50,6 +51,31 @@ func StringInSlice(s string, slice []string) bool { | |||
return util.StringInSlice(s, slice) | |||
} | |||
|
|||
func StringToImageReference(image string) (types.ImageReference, error) { |
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.
UIArgumentToImageReference
? HeuristicUserInputToImageReference
? Something along those lines? (Up to Buildah maintainers.)
I, fairly desperately, don’t want this code to be used to “round-trip” between ImageReference
and string
[there already are other functions for that], and this plain naming of the function suggests that it could be used for that purpose.
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, fairly desperately, don’t want this code to be used to “round-trip” between ImageReference and string
Sorry but would you mind explaining what you mean? Some sort of abuse this function would get by being used in unintended places?
Also, how about ImageStringToImageReference
?
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.
Some sort of abuse this function would get by being used in unintended places?
Yes. The function is a heuristic that can parse the input using several different format/semantics, depending on what happens to work.
A failure case I’ve seen fairly frequently in this space is finding some pre-existing function like that, similarly targeted at the UI and heuristically doing “what the user meant”, and embedding it somewhere deeper in the call stack, calling it with a string produced from a Go value, without accounting for the details of the heuristics, or possibly the CLI-level heuristics being expanded to add new user-level features. The outcome is that the Go value → string → Go value transformation (which might, sometimes, be unavoidable, e.g. for multi-machine operations) becomes inexact, hard to predict, and possibly even leads to security issues.
Hence all of the concern about not using strings as an internal representation if at all possible, as the easiest preventative measure.
Secondarily, using the right string representation / API. The types.ImageReference
values already have an API for producing a string representation, and for creating one from a string representation. That one (alltransports.ParseImageName
) should be used anywhere below the CLI heuristic layers, and the new function should be named so that it isn’t accidentally used instead.
So that’s why I would like some mention of UI, and preferably “heuristics” in the name.
“Image string” does not help because it does not disambiguate “a lossy heuristic subject to change” from “a stable round-trip-safe value conversion”, either would apply to images and strings.
d6925cd
to
bd7e5cf
Compare
Hi, I just created containers/podman#18642 It looks related to this PR.
I agree but a good reason to combine them is to enable parallelism. |
bd7e5cf
to
4b19451
Compare
@danishprakash Are you still working on this? |
@danishprakash still working on this? |
Yes, going to get back to this end of this week. |
0036033
to
f9d20a2
Compare
f9d20a2
to
61ed32a
Compare
Ephemeral COPR build failed. @containers/packit-build please check. |
61ed32a
to
7a1ef03
Compare
7a1ef03
to
b2c313d
Compare
Any updates? Thanks! And, one more question, for now, once build finished, how can I push all arch images to the registry at once if no Error: unknown flag: --push
See 'podman buildx build --help' |
@danishprakash would you like me to try to get someone to take this over? |
b2c313d
to
a5d4921
Compare
Tests were pending, I had added them a couple of months back. Two RPM tests are failing, I'm not sure if they're related. Also, this still needs a final pass from @mtrmac. |
5c25e1e
to
0efaf1f
Compare
@mtrmac PTAL |
return fmt.Errorf("failed to export build output: %w", err) | ||
} | ||
} | ||
return nil |
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 this right it does no output if not opts.Push?
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.
iiuc, type=image
outputs a container image format, only when you specify --output
, it additionally pushes the image to the registry.
* pass systemCtx to push util * fix test Signed-off-by: Danish Prakash <[email protected]>
0efaf1f
to
80defed
Compare
Hi, is this still WIP? |
Yes |
What type of PR is this?
/kind feature
Which issue(s) this PR fixes:
Closes #4671
Special notes for your reviewer:
Extremely WIP draft.
Does this PR introduce a user-facing change?