Skip to content

Commit

Permalink
Refactor to use containerd for oci export
Browse files Browse the repository at this point in the history
  • Loading branch information
fussybeaver committed Aug 31, 2023
1 parent 93c7c29 commit 853c8de
Show file tree
Hide file tree
Showing 14 changed files with 716 additions and 31 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ members = [

[features]
# Enable Buildkit-enabled docker image building
buildkit = ["num", "rand", "tokio-stream", "tower", "tonic", "tower-service", "bollard-stubs/buildkit", "bollard-buildkit-proto"]
buildkit = ["num", "rand", "tempdir", "tokio-stream", "tower", "tonic", "tower-service", "bollard-stubs/buildkit", "bollard-buildkit-proto"]
# Enable tests specifically for the http connector
test_http = []
# Enable tests specifically for rustls
Expand Down Expand Up @@ -64,10 +64,11 @@ serde_urlencoded = "0.7"
tokio = { version = "1.7", features = ["time", "net", "io-util"] }
tonic = { version = "0.9", optional = true }
tower = { version = "0.4", optional = true }
tempdir = { version = "0.3", optional = true }
thiserror = "1.0"
time = { version = "0.3", features = ["formatting", "parsing"], optional = true }
tokio-stream = { version = "0.1", optional = true }
tokio-util = { version = "0.7", features = ["codec"] }
tokio-util = { version = "0.7", features = ["codec", "io"] }
tower-service = { version = "0.3", optional = true }
url = "2.2"
webpki-roots = { version = "0.23", optional = true }
Expand Down
9 changes: 7 additions & 2 deletions codegen/proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub mod moby {
include!("generated/moby.upload.v1.rs");
}
}

}

pub mod google {
Expand Down Expand Up @@ -58,7 +57,6 @@ impl Display for moby::buildkit::v1::StatusResponse {
let mut next = iter.next();
let mut result = Ok(());
while next.is_some() {

result = result.and_then(|_| write!(f, "{}", next.unwrap()));
next = iter.next();
if iter.peek().is_some() {
Expand All @@ -84,3 +82,10 @@ impl Display for moby::buildkit::v1::VertexLog {
)
}
}

impl AsRef<[u8]> for moby::buildkit::v1::BytesMessage {
fn as_ref(&self) -> &[u8] {
self.data.as_ref()
}
}

3 changes: 2 additions & 1 deletion examples/export_oci_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() {

env_logger::init();

let mut docker = Docker::connect_with_http_defaults().unwrap();
let mut docker = Docker::connect_with_socket_defaults().unwrap();

let dockerfile = String::from(
"FROM alpine as builder1
Expand Down Expand Up @@ -41,6 +41,7 @@ async fn main() {
let frontend_opts = bollard::grpc::export::ImageBuildFrontendOptions::builder()
.pull(true)
.build();

let output = bollard::grpc::export::ImageExporterOCIOutputBuilder::new(
"docker.io/library/bollard-oci-export-buildkit-example:latest",
)
Expand Down
4 changes: 2 additions & 2 deletions src/container.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Container API: run docker containers and manage their lifecycle
use futures_core::Stream;
use futures_util::StreamExt;
use futures_util::{StreamExt, TryStreamExt};
use http::header::{CONNECTION, CONTENT_TYPE, UPGRADE};
use http::request::Builder;
use hyper::{body::Bytes, Body, Method};
Expand Down Expand Up @@ -1510,7 +1510,7 @@ impl Docker {
);

let (read, write) = self.process_upgraded(req).await?;
let log = FramedRead::new(read, NewlineLogOutputDecoder::new(true));
let log = FramedRead::new(read, NewlineLogOutputDecoder::new(true)).map_err(|e| e.into());

Ok(AttachContainerResults {
output: Box::pin(log),
Expand Down
1 change: 1 addition & 0 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ impl Docker {
StreamReader::new(res.into_body().map_err(Error::from)),
NewlineLogOutputDecoder::new(false),
)
.map_err(Error::from)
}

async fn decode_into_string(response: Response<Body>) -> Result<String, Error> {
Expand Down
8 changes: 8 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,12 @@ pub enum Error {
#[from]
err: tonic::transport::Error,
},
#[cfg(feature = "buildkit")]
/// Error emitted when a GRPC network request emits a non-OK status code
#[error(transparent)]
TonicStatus {
/// The tonic status emitted.
#[from]
err: tonic::Status,
},
}
5 changes: 4 additions & 1 deletion src/exec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Exec API: Run new commands inside running containers
use futures_util::TryStreamExt;
use http::header::{CONNECTION, UPGRADE};
use http::request::Builder;
use hyper::Body;
Expand Down Expand Up @@ -234,7 +235,9 @@ impl Docker {
let (read, write) = self.process_upgraded(req).await?;

let log =
FramedRead::with_capacity(read, NewlineLogOutputDecoder::new(true), capacity);
FramedRead::with_capacity(read, NewlineLogOutputDecoder::new(true), capacity)
.map_err(|e| e.into());

Ok(StartExecResults::Attached {
output: Box::pin(log),
input: Box::pin(write),
Expand Down
Loading

0 comments on commit 853c8de

Please sign in to comment.