diff --git a/Cargo.lock b/Cargo.lock index e7f95a7d..2085de1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -467,6 +467,14 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "oci-image-spec" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "os_str_bytes" version = "2.3.2" @@ -710,6 +718,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + [[package]] name = "serde" version = "1.0.115" @@ -730,6 +744,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "slab" version = "0.4.2" diff --git a/Cargo.toml b/Cargo.toml index 78ee9208..5bd65c73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,3 +33,6 @@ tonic = "0.3.1" [build-dependencies] anyhow = "1.0.32" tonic-build = "0.3.1" + +[workspace] +members = ["crates/oci-image-spec"] diff --git a/crates/oci-image-spec/Cargo.toml b/crates/oci-image-spec/Cargo.toml new file mode 100644 index 00000000..ffdbf551 --- /dev/null +++ b/crates/oci-image-spec/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "oci-image-spec" +version = "0.1.0" +authors = ["Lach "] +edition = "2018" + +[dependencies] +serde = { version = "1.0.115", features = ["derive"] } +serde_json = "1.0.57" diff --git a/crates/oci-image-spec/src/config.rs b/crates/oci-image-spec/src/config.rs new file mode 100644 index 00000000..248221be --- /dev/null +++ b/crates/oci-image-spec/src/config.rs @@ -0,0 +1,55 @@ +//! OpenContainer Config Specification +use std::collections::HashMap; + +use serde::{Deserialize, Serialize}; + +#[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize)] +pub struct Config { + #[serde(rename = "Cmd")] + pub cmd: Option>, + #[serde(rename = "Entrypoint")] + pub entrypoint: Option>, + #[serde(rename = "Env")] + pub env: Option>, + /// TODO: in original spec this is a map from string to object + /// serde_json::Value is the best type for this field which i can guess + #[serde(rename = "ExposedPorts")] + pub exposed_ports: Option>, + #[serde(rename = "Labels")] + pub labels: Option>, + #[serde(rename = "StopSignal")] + pub stop_signal: Option, + #[serde(rename = "User")] + pub user: Option, + #[serde(rename = "Volumes")] + pub volumes: Option>, + #[serde(rename = "WorkingDir")] + pub working_dir: Option, +} + +#[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize)] +pub struct History { + pub author: Option, + pub comment: Option, + pub created: Option, + pub created_by: Option, + pub empty_layer: Option, +} + +#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct HistoryRootfs { + pub diff_ids: Vec, + #[serde(rename = "type")] + pub item_type: String, +} + +#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct RootConfig { + pub architecture: String, + pub author: Option, + pub config: Option, + pub created: Option, + pub history: Option>, + pub os: String, + pub rootfs: HistoryRootfs, +} diff --git a/crates/oci-image-spec/src/content_descriptor.rs b/crates/oci-image-spec/src/content_descriptor.rs new file mode 100644 index 00000000..875fe69a --- /dev/null +++ b/crates/oci-image-spec/src/content_descriptor.rs @@ -0,0 +1,16 @@ +use crate::defs::{Annotations, Digest, MediaType, Url}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct ContentDescriptor { + pub annotations: Option, + /// the cryptographic checksum digest of the object, in the pattern ':' + pub digest: Digest, + /// the mediatype of the referenced object + #[serde(rename = "mediaType")] + pub media_type: MediaType, + /// the size in bytes of the referenced object + pub size: i64, + /// a list of urls from which this object may be downloaded + pub urls: Option>, +} diff --git a/crates/oci-image-spec/src/defs.rs b/crates/oci-image-spec/src/defs.rs new file mode 100644 index 00000000..6134b620 --- /dev/null +++ b/crates/oci-image-spec/src/defs.rs @@ -0,0 +1,8 @@ +use std::collections::HashMap; + +pub type Annotations = HashMap; +/// the cryptographic checksum digest of the object, in the pattern ':' +pub type Digest = String; +/// https://opencontainers.org/schema/image/descriptor/mediaType +pub type MediaType = String; +pub type Url = String; diff --git a/crates/oci-image-spec/src/image_index.rs b/crates/oci-image-spec/src/image_index.rs new file mode 100644 index 00000000..bb86946b --- /dev/null +++ b/crates/oci-image-spec/src/image_index.rs @@ -0,0 +1,38 @@ +use super::defs::Annotations; +use crate::defs::{Digest, MediaType, Url}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct Platform { + pub architecture: String, + pub os: String, + #[serde(rename = "os.features")] + pub os_features: Option>, + #[serde(rename = "os.version")] + pub os_version: Option, + pub variant: Option, +} + +#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct Manifests { + pub annotations: Option, + /// the cryptographic checksum digest of the object, in the pattern ':' + pub digest: Digest, + /// the mediatype of the referenced object + #[serde(rename = "mediaType")] + pub media_type: MediaType, + pub platform: Option, + /// the size in bytes of the referenced object + pub size: i64, + /// a list of urls from which this object may be downloaded + pub urls: Option>, +} + +#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct ImageIndex { + pub annotations: Option, + pub manifests: Vec, + /// This field specifies the image index schema version as an integer + #[serde(rename = "schemaVersion")] + pub schema_version: i64, +} diff --git a/crates/oci-image-spec/src/image_layout.rs b/crates/oci-image-spec/src/image_layout.rs new file mode 100644 index 00000000..b20ee6e5 --- /dev/null +++ b/crates/oci-image-spec/src/image_layout.rs @@ -0,0 +1,8 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct ImageLayout { + /// version of the OCI Image Layout (in the oci-layout file) + #[serde(rename = "imageLayoutVersion")] + pub image_layout_version: String, +} diff --git a/crates/oci-image-spec/src/image_manifest.rs b/crates/oci-image-spec/src/image_manifest.rs new file mode 100644 index 00000000..b5829595 --- /dev/null +++ b/crates/oci-image-spec/src/image_manifest.rs @@ -0,0 +1,12 @@ +use serde::{Deserialize, Serialize}; + +use crate::{content_descriptor::ContentDescriptor, defs::Annotations}; +#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct ImageManifest { + pub annotations: Option, + pub config: ContentDescriptor, + pub layers: Vec, + /// This field specifies the image manifest schema version as an integer + #[serde(rename = "schemaVersion")] + pub schema_version: i64, +} diff --git a/crates/oci-image-spec/src/lib.rs b/crates/oci-image-spec/src/lib.rs new file mode 100644 index 00000000..bf87c0d9 --- /dev/null +++ b/crates/oci-image-spec/src/lib.rs @@ -0,0 +1,6 @@ +pub mod config; +pub mod content_descriptor; +pub mod defs; +pub mod image_index; +pub mod image_layout; +pub mod image_manifest;