Repository navigation
Deploy immutable images from selected build Machines #842
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d5af268
Deploy immutable images from selected build Machines
2e7f743
Merge remote-tracking branch 'origin/main' into t3code/implement-803
e09f567
Release temporary build tags and validate destination architectures
722930f
Merge remote-tracking branch 'origin/main' into t3code/implement-803
5c43051
Merge remote-tracking branch 'origin/main' into t3code/implement-803
6e32e1c
Let BuildKit validate cross-platform named image contexts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| //! Bind completed Service outputs to BuildKit named contexts. The existing | ||
| //! Machine image server supplies bytes directly; no external registry fallback. | ||
|
|
||
| use crate::{BuildError, Request}; | ||
| use serde_norway::Value; | ||
| use std::{fs, net::IpAddr}; | ||
|
|
||
| pub(crate) fn prepare(request: &Request<'_>) -> Result<(), BuildError> { | ||
| if request.image_contexts.is_empty() { | ||
| return Ok(()); | ||
| } | ||
| let invalid = |message: &str| BuildError::Request(message.into()); | ||
| let mut document: Value = serde_norway::from_slice( | ||
| &fs::read(request.working_dir.join(request.compose_file)).map_err(input_error)?, | ||
| ) | ||
| .map_err(|_| invalid("invalid captured Build recipe"))?; | ||
| let services = document | ||
| .get_mut("services") | ||
| .and_then(Value::as_mapping_mut) | ||
| .ok_or_else(|| invalid("Build recipe has no services"))?; | ||
| for target in request.targets { | ||
| let build = services | ||
| .get_mut(Value::String(target.name.clone())) | ||
| .and_then(|service| service.get_mut("build")) | ||
| .and_then(Value::as_mapping_mut) | ||
| .ok_or_else(|| invalid("Build target has no recipe"))?; | ||
| let contexts = build.get("additional_contexts"); | ||
| let entries = match contexts { | ||
| Some(Value::Mapping(values)) => values | ||
| .iter() | ||
| .map(|(name, value)| name.as_str().zip(value.as_str())) | ||
| .collect::<Option<Vec<_>>>(), | ||
| Some(Value::Sequence(values)) => values | ||
| .iter() | ||
| .map(|value| value.as_str().and_then(|value| value.split_once('='))) | ||
| .collect::<Option<Vec<_>>>(), | ||
| None | Some(Value::Null) => Some(Vec::new()), | ||
| Some(_) => None, | ||
| } | ||
| .ok_or_else(|| invalid("invalid additional contexts"))?; | ||
| let mut bound = serde_norway::Mapping::new(); | ||
| for (name, value) in entries { | ||
| if let Some(dependency) = value.strip_prefix("service:") { | ||
| let image = request.image_contexts.get(dependency).ok_or_else(|| { | ||
| invalid("Service image context has no completed Build output") | ||
| })?; | ||
| bound.insert( | ||
| name.into(), | ||
| format!( | ||
| "docker-image://{}/{}", | ||
| std::net::SocketAddr::new( | ||
| image | ||
| .source | ||
| .management_address | ||
| .0 | ||
| .to_ipv4_mapped() | ||
| .map_or(IpAddr::V6(image.source.management_address.0), IpAddr::V4), | ||
| image.source.port, | ||
| ), | ||
| image.reference | ||
| ) | ||
| .into(), | ||
| ); | ||
| } else { | ||
| bound.insert(name.into(), value.into()); | ||
| } | ||
| } | ||
| if !bound.is_empty() { | ||
| build.insert("additional_contexts".into(), Value::Mapping(bound)); | ||
| } | ||
| } | ||
| fs::write( | ||
| request.working_dir.join(request.compose_file), | ||
| serde_norway::to_string(&document) | ||
| .map_err(|error| BuildError::Request(error.to_string()))?, | ||
| ) | ||
| .map_err(input_error)?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn input_error(error: std::io::Error) -> BuildError { | ||
| BuildError::Request(format!("prepare completed image contexts: {error}")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When a Compose service declares explicit
build.tags, capture preserves those tags before appendingservice.image, so the first metadata tag can name an auxiliary repository. Using that first tag here causesbind_buildsand image delivery to useauxiliary-repo@sha256:...rather than the repository declared by the Service; for local deploys, an auxiliary repository containing a registry port can additionally triggerRegistryPortReferenceeven whenservice.imageitself is supported. Construct the digest reference fromBuiltService.imageinstead of arbitrary tag ordering.Useful? React with 👍 / 👎.