Feat: send additional build contexts for remote builds

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: #23433

Signed-off-by: Joshua Arrevillaga <2004jarrevillaga@gmail.com>
This commit is contained in:
Joshua Arrevillaga
2025-07-03 14:56:21 -04:00
parent 7efa0b829a
commit 73f3e98947
5 changed files with 719 additions and 26 deletions

View File

@ -1491,7 +1491,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// name: Content-Type
// type: string
// default: application/x-tar
// enum: ["application/x-tar"]
// enum: ["application/x-tar", "multipart/form-data"]
// - in: header
// name: X-Registry-Config
// type: string
@ -1516,6 +1516,28 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// and build for all of the platforms that are available. Stages that use *scratch* as a starting point can not be inspected,
// so at least one non-*scratch* stage must be present for detection to work usefully.
// - in: query
// name: additionalbuildcontexts
// type: array
// items:
// type: string
// default: []
// description: |
// Additional build contexts for builds that require more than one context.
// Each additional context must be specified as a key-value pair in the format "name=value".
//
// The value can be specified in two formats:
// - URL context: Use the prefix "url:" followed by a URL to a tar archive
// Example: "mycontext=url:https://example.com/context.tar"
// - Image context: Use the prefix "image:" followed by an image reference
// Example: "mycontext=image:alpine:latest" or "mycontext=image:docker.io/library/ubuntu:22.04"
//
// Local contexts are provided via multipart/form-data upload. When using multipart/form-data,
// include additional build contexts as separate form fields with names prefixed by "build-context-".
// For example, a local context named "mycontext" should be uploaded as a tar file in a field
// named "build-context-mycontext".
//
// (As of version 5.6.0)
// - in: query
// name: extrahosts
// type: string
// default: