Skip to content

Feat: send additional build contexts as tar files for remote builds #26628

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

Merged
merged 1 commit into from
Jul 24, 2025

Conversation

2004joshua
Copy link
Contributor

@2004joshua 2004joshua commented Jul 14, 2025

Fixed the --build-context flag to properly send files for remote builds. Previously only the main context was sent over as a tar while additional contexts were passed as local paths and this would cause builds to fail since the files wouldn't exist.

New changes modifies the Build API to use multipart HTTP requests allowing multiple build contexts to be sent as tar files. Each additional context is packaged and transferred based on its type:

  • Local Directories: Sent as tar archives
  • Git Repositories: URL sent to the server, which then clones it
  • Container Images: Image reference sent to the server, which pulls the image
  • URLs/archives: URL sent to the server, which handles the download

Version check is in place to make sure that the server is updated to at least the upcoming 5.6.0 update or else the fix wont be usable.

Fixes: #23433

Does this PR introduce a user-facing change?

Added support for --build-context for podman-remote

@github-actions github-actions bot added the kind/api-change Change to remote API; merits scrutiny label Jul 14, 2025
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.

Not a full review, but reading into memory does not seem viable to me.
Have a look at ManifestModify() and the bindings manifests Modify() functions which AFAICT to such a multipart request without reading all into memory

Git Repositories: cloned locally then sent as a tar
URLs/archives: downloaded locally then sent as a tar

It would be best if just the server downloads them instead of the client, sending them as tar via the API just sounds slower.

@2004joshua 2004joshua force-pushed the build_context branch 2 times, most recently from 7ea602e to b2db9e2 Compare July 14, 2025 15:32
Copy link

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@2004joshua 2004joshua force-pushed the build_context branch 3 times, most recently from 5b62920 to d56b2a1 Compare July 14, 2025 20:39
Copy link
Member

@nalind nalind left a comment

Choose a reason for hiding this comment

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

Some unnecessary duplication of archive/extracting logic on both ends, probably still have an issue where the top-level directory of an additional build context has a different timestamp between otherwise-identical build requests made at different times.

@Luap99
Copy link
Member

Luap99 commented Jul 17, 2025

I think for me this goes a bit to much into the breaking chnage territory, if caching gets broken on remote then this is a bit problematic. Also the copy now makes it much slower compared to the local file thing before.

I think this PR is overall the right thing to do but I think I would prefer for this to wait for 6.0. Or maybe this is something where the work @Honny1 is doing with a local build API could help here. Where we can have the local and remote way working so users could take advantage of either one.

@Honny1
Copy link
Member

Honny1 commented Jul 17, 2025

I think this PR is overall the right thing to do but I think I would prefer for this to wait for 6.0. Or maybe this is something where the work @Honny1 is doing with a local build API could help here. Where we can have the local and remote way working so users could take advantage of either one.

Yes, a local API will help with performance issues, but only on systems with a podman machine. Probably also on remote systems, but that would have some security implications.

@@ -249,8 +249,8 @@ var _ = Describe("run basic podman commands", func() {
})

It("podman build contexts", func() {
Skip("Waiting for VM images with Podman > 5.5.2 for multipart build context support")
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 all of the sudden skipping for all tests, I would think this test must still pass. IF this doesn't pass it means we break backwards compatibility.

For the qemu skip you can switch the test to say unskip when machine image contain podman with this patch.

Copy link
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

After a quick review of the code, I believe it would be more straightforward if additional build contexts were handled within the query, and the files to be transferred were part of the incoming tar. This could simplify the code significantly by removing the need to parse multipart/form-data.

@2004joshua 2004joshua force-pushed the build_context branch 6 times, most recently from e9f7827 to 3ccd11a Compare July 21, 2025 16:35
@Luap99
Copy link
Member

Luap99 commented Jul 21, 2025

Also if we add a new content type then the new format must be document in our swagger file in pkg/api/server/register_images.go as well.

buildDir := filepath.Join(anchorDir, "build")
err := os.Mkdir(buildDir, 0o700)
if err != nil {
return "", err
}

err = archive.Untar(r.Body, buildDir, nil)
err = archive.Untar(r, buildDir, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Any reason this isn't chrootarchive.Untar()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That function already had it like that

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but why?

// Additional build contexts for builds that require more than one context.
// We send both URL and image links through query parameters where we then setup the additional build contexts
// struct. Local additional build contexts are sent as tar files via multipart/form-data.
// (As of version 5.6.0)
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 the compat endpoint. Do other clients submit this information this way?

// Additional build contexts for builds that require more than one context.
// We send both URL and image links through query parameters where we then setup the additional build contexts
// struct. Local additional build contexts are sent as tar files via multipart/form-data.
// (As of version 5.6.0)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need to mention data types used by the implementation, which a client wouldn't care about. A client would care about how they're expected to describe contexts that are URLs or images, so it would probably be good to describe what the strings should look like here.

@2004joshua 2004joshua force-pushed the build_context branch 3 times, most recently from 1c4f355 to 0467ad7 Compare July 23, 2025 01:58
Fixed the --build-context flag to properly send files for remote builds. Previously
only the main context was sent over as a tar while additional contexts were passed as
local paths and this would cause builds to fail since the files wouldn't exist.

New changes modifies the Build API to use multipart HTTP requests allowing multiple
build contexts to be used. Each additional context is packaged and
transferred based on its type:
- Local Directories: Sent as tar archives
- Git Repositories: link sent to the server where its then cloned
- Container Images: Image reference sent to the server, it then pulls the image there
- URLs/archives: URL sent to the server, which handles the download

Fixes: containers#23433

Signed-off-by: Joshua Arrevillaga <[email protected]>
@mheon
Copy link
Member

mheon commented Jul 23, 2025

LGTM

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.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 24, 2025
Copy link
Contributor

openshift-ci bot commented Jul 24, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 2004joshua, Luap99

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

The pull request process is described 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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 24, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 12b7a33 into containers:main Jul 24, 2025
82 of 85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Change to remote API; merits scrutiny lgtm Indicates that a PR is ready to be merged. machine release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Additional build contexts should be sent as additional tar files
6 participants