fix: unjank the demo #85
@ -5,6 +5,8 @@ use std::process;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use bollard::image::PushImageOptions;
|
||||||
|
wjro marked this conversation as resolved
|
|||||||
|
use bollard::query_parameters::PushImageOptionsBuilder;
|
||||||
use bollard::{Docker, body_full};
|
use bollard::{Docker, body_full};
|
||||||
use dockerfile_builder::Dockerfile;
|
use dockerfile_builder::Dockerfile;
|
||||||
use dockerfile_builder::instruction::{CMD, COPY, ENV, EXPOSE, FROM, RUN, USER, WORKDIR};
|
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();
|
let remote_image_name = self.image_name();
|
||||||
// 2. Push the image to the registry.
|
// 2. Push the image to the registry.
|
||||||
self.push_docker_image(&local_image_name, &remote_image_name)
|
self.push_docker_image(&local_image_name, &remote_image_name)
|
||||||
|
.await
|
||||||
.map_err(|e| format!("Failed to push Docker image: {}", e))?;
|
.map_err(|e| format!("Failed to push Docker image: {}", e))?;
|
||||||
info!("Successfully pushed Docker image to: {}", remote_image_name);
|
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.
|
/// Tags and pushes a Docker image to the configured remote registry.
|
||||||
fn push_docker_image(
|
async fn push_docker_image(
|
||||||
&self,
|
&self,
|
||||||
image_name: &str,
|
image_name: &str,
|
||||||
full_tag: &str,
|
full_tag: &str,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
info!("Pushing docker image {full_tag}");
|
info!("Pushing docker image {full_tag}");
|
||||||
|
|
||||||
// Tag the image for the remote registry.
|
let docker = Docker::connect_with_socket_defaults().unwrap();
|
||||||
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)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Push the image.
|
// let push_options = PushImageOptionsBuilder::new().tag(tag);
|
||||||
let output = process::Command::new("docker")
|
|
||||||
.args(["push", &full_tag])
|
let mut push_image_stream =
|
||||||
.spawn()?
|
docker.push_image(full_tag, Some(PushImageOptionsBuilder::new().build()), None);
|
||||||
.wait_with_output()?;
|
|
||||||
self.check_output(&output, "Pushing docker image failed")?;
|
while let Some(msg) = push_image_stream.next().await {
|
||||||
debug!(
|
println!("Message: {msg:?}");
|
||||||
"docker push output: stdout: {}, stderr: {}",
|
}
|
||||||
String::from_utf8_lossy(&output.stdout),
|
|
||||||
String::from_utf8_lossy(&output.stderr)
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(full_tag.to_string())
|
Ok(full_tag.to_string())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user
add a comment to justify using bollard vs docker via the cli
The reason I used
bollardwas because I find it preferable to access the docker daemon programmatically over an API over using a (albeit relatively stable) CLI interface