fix: unjank the demo #85

Merged
taha merged 19 commits from fix_demo into master 2025-07-11 14:32:22 +00:00
Showing only changes of commit 28476af222 - Show all commits

View File

@ -5,6 +5,8 @@ use std::process;
use std::sync::Arc;
use async_trait::async_trait;
use bollard::image::PushImageOptions;
wjro marked this conversation as resolved
Review

add a comment to justify using bollard vs docker via the cli

add a comment to justify using bollard vs docker via the cli
Review

The reason I used bollard was because I find it preferable to access the docker daemon programmatically over an API over using a (albeit relatively stable) CLI interface

The reason I used `bollard` was because I find it preferable to access the docker daemon programmatically over an API over using a (albeit relatively stable) CLI interface
use bollard::query_parameters::PushImageOptionsBuilder;
use bollard::{Docker, body_full};
use dockerfile_builder::Dockerfile;
use dockerfile_builder::instruction::{CMD, COPY, ENV, EXPOSE, FROM, RUN, USER, WORKDIR};
@ -123,6 +125,7 @@ impl OCICompliant for RustWebapp {
let remote_image_name = self.image_name();
// 2. Push the image to the registry.
self.push_docker_image(&local_image_name, &remote_image_name)
.await
.map_err(|e| format!("Failed to push Docker image: {}", e))?;
info!("Successfully pushed Docker image to: {}", remote_image_name);
@ -204,36 +207,23 @@ impl RustWebapp {
}
/// Tags and pushes a Docker image to the configured remote registry.
fn push_docker_image(
async fn push_docker_image(
&self,
image_name: &str,
full_tag: &str,
) -> Result<String, Box<dyn std::error::Error>> {
info!("Pushing docker image {full_tag}");
// Tag the image for the remote registry.
let output = process::Command::new("docker")
.args(["tag", image_name, &full_tag])
.spawn()?
.wait_with_output()?;
self.check_output(&output, "Tagging docker image failed")?;
debug!(
"docker tag output: stdout: {}, stderr: {}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
let docker = Docker::connect_with_socket_defaults().unwrap();
// Push the image.
let output = process::Command::new("docker")
.args(["push", &full_tag])
.spawn()?
.wait_with_output()?;
self.check_output(&output, "Pushing docker image failed")?;
debug!(
"docker push output: stdout: {}, stderr: {}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
// let push_options = PushImageOptionsBuilder::new().tag(tag);
let mut push_image_stream =
docker.push_image(full_tag, Some(PushImageOptionsBuilder::new().build()), None);
while let Some(msg) = push_image_stream.next().await {
println!("Message: {msg:?}");
}
Ok(full_tag.to_string())
}