Skip to content

Commit

Permalink
feat(jstzd): add docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
ryutamago committed Sep 12, 2024
1 parent 1475a6a commit 605ae93
Show file tree
Hide file tree
Showing 8 changed files with 684 additions and 40 deletions.
279 changes: 241 additions & 38 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ members = [
"crates/jstz_rollup",
"crates/jstz_sdk",
"crates/jstz_wpt",
"crates/octez"
"crates/octez",
"crates/jstzd"
]

[workspace.package]
Expand Down Expand Up @@ -98,6 +99,10 @@ tokio-util = "0.7.10"
url = "2.4.1"
urlpattern = "0.2.0"
wasm-bindgen = "0.2.92"
bollard = "0.16.1"
# async-dropper = { version = "0.3.1", features = ["tokio", "simple"] }
# async-trait = "0.1.82"
# async-scoped = "0.9.0"

[workspace.dependencies.tezos-smart-rollup]
version = "0.2.2"
Expand Down Expand Up @@ -157,4 +162,4 @@ boa_gc = { git = "https://github.com/trilitech/boa.git", branch = "ryutamago/fix
boa_interner = { git = "https://github.com/trilitech/boa.git", branch = "ryutamago/fix-undefined-to-json" }
boa_macros = { git = "https://github.com/trilitech/boa.git", branch = "ryutamago/fix-undefined-to-json" }
boa_parser = { git = "https://github.com/trilitech/boa.git", branch = "ryutamago/fix-undefined-to-json" }
boa_profiler = { git = "https://github.com/trilitech/boa.git", branch = "ryutamago/fix-undefined-to-json" }
boa_profiler = { git = "https://github.com/trilitech/boa.git", branch = "ryutamago/fix-undefined-to-json" }
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ comment:
layout: "header, files, footer"
hide_project_coverage: false

ignore:
- crates/jstzd/src/main.rs

# Configures coverage checks -- both patch and project-wide checks
# can drop by 5% before failing the CI build.
#
Expand Down
10 changes: 10 additions & 0 deletions crates/jstzd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "jstzd"
authors.workspace = true
version.workspace = true
edition.workspace = true
repository.workspace = true

[dependencies]
anyhow.workspace = true
bollard.workspace = true
91 changes: 91 additions & 0 deletions crates/jstzd/src/docker/image.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
pub trait Image: Sized {
const LATEST_TAG: &'static str = "latest";
fn image_name(&self) -> &str;
fn image_tag(&self) -> &str {
Self::LATEST_TAG
}
fn image_uri(&self) -> String {
format!("{}:{}", self.image_name(), self.image_tag())
}
// Overrides the entrypoint of the image
fn entrypoint(&self) -> Option<&str> {
None
}
// If specified, used as a validation on container creation
fn exposed_ports(&self) -> &[u16] {
&[]
}
}

pub struct GenericImage {
image_name: String,
image_tag: Option<String>,
entrypoint: Option<String>,
exposed_ports: Option<Vec<u16>>,
}

impl Image for GenericImage {
fn image_name(&self) -> &str {
&self.image_name
}

fn image_tag(&self) -> &str {
if let Some(tag) = &self.image_tag {
return tag;
}
Self::LATEST_TAG
}

fn entrypoint(&self) -> Option<&str> {
self.entrypoint.as_deref()
}

fn exposed_ports(&self) -> &[u16] {
if let Some(ports) = &self.exposed_ports {
return ports;
}
&[]
}
}

impl GenericImage {
pub fn new(image_name: &str) -> GenericImage {
GenericImage {
image_name: image_name.to_string(),
image_tag: None,
entrypoint: None,
exposed_ports: None,
}
}

pub fn with_tag(mut self, image_tag: &str) -> Self {
self.image_tag = Some(image_tag.to_string());
self
}

pub fn with_entrypoint(mut self, entrypoint: &str) -> Self {
self.entrypoint = Some(entrypoint.to_string());
self
}

pub fn with_exposed_ports(mut self, exposed_ports: &[u16]) -> Self {
self.exposed_ports = Some(Vec::from(exposed_ports));
self
}
}

#[cfg(test)]
mod test {
use super::*;
#[test]
fn builds_docker_image() {
let image = GenericImage::new("busybox")
.with_entrypoint("sh")
.with_tag("stable")
.with_exposed_ports(&[8080]);
assert_eq!(image.image_name(), "busybox");
assert_eq!(image.image_tag(), "stable");
assert_eq!(image.entrypoint(), Some("sh"));
assert_eq!(image.exposed_ports(), &[8080]);
}
}
7 changes: 7 additions & 0 deletions crates/jstzd/src/docker/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub use bollard::Docker;

mod image;
mod runnable_image;

pub use image::{GenericImage, Image};
pub use runnable_image::RunnableImage;
Loading

0 comments on commit 605ae93

Please sign in to comment.