Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
9 changes: 9 additions & 0 deletions crates/oci-image-spec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "oci-image-spec"
version = "0.1.0"
authors = ["Lach <iam@lach.pw>"]
edition = "2018"

[dependencies]
serde = { version = "1.0.115", features = ["derive"] }
serde_json = "1.0.57"
55 changes: 55 additions & 0 deletions crates/oci-image-spec/src/config.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<String>>,
#[serde(rename = "Entrypoint")]
pub entrypoint: Option<Vec<String>>,
#[serde(rename = "Env")]
pub env: Option<Vec<String>>,
/// 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<HashMap<String, serde_json::Value>>,
#[serde(rename = "Labels")]
pub labels: Option<HashMap<String, String>>,
#[serde(rename = "StopSignal")]
pub stop_signal: Option<String>,
#[serde(rename = "User")]
pub user: Option<String>,
#[serde(rename = "Volumes")]
pub volumes: Option<HashMap<String, serde_json::Value>>,
#[serde(rename = "WorkingDir")]
pub working_dir: Option<String>,
}

#[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize)]
pub struct History {
pub author: Option<String>,
pub comment: Option<String>,
pub created: Option<String>,
pub created_by: Option<String>,
pub empty_layer: Option<bool>,
}

#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
pub struct HistoryRootfs {
pub diff_ids: Vec<String>,
#[serde(rename = "type")]
pub item_type: String,
}

#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
pub struct RootConfig {
pub architecture: String,
pub author: Option<String>,
pub config: Option<Config>,
pub created: Option<String>,
pub history: Option<Vec<History>>,
pub os: String,
pub rootfs: HistoryRootfs,
}
16 changes: 16 additions & 0 deletions crates/oci-image-spec/src/content_descriptor.rs
Original file line number Diff line number Diff line change
@@ -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<Annotations>,
/// the cryptographic checksum digest of the object, in the pattern '<algorithm>:<encoded>'
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<Vec<Url>>,
}
8 changes: 8 additions & 0 deletions crates/oci-image-spec/src/defs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::collections::HashMap;

pub type Annotations = HashMap<String, String>;
/// the cryptographic checksum digest of the object, in the pattern '<algorithm>:<encoded>'
pub type Digest = String;
/// https://opencontainers.org/schema/image/descriptor/mediaType
pub type MediaType = String;
pub type Url = String;
38 changes: 38 additions & 0 deletions crates/oci-image-spec/src/image_index.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<String>>,
#[serde(rename = "os.version")]
pub os_version: Option<String>,
pub variant: Option<String>,
}

#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
pub struct Manifests {
pub annotations: Option<Annotations>,
/// the cryptographic checksum digest of the object, in the pattern '<algorithm>:<encoded>'
pub digest: Digest,
/// the mediatype of the referenced object
#[serde(rename = "mediaType")]
pub media_type: MediaType,
pub platform: Option<Platform>,
/// 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<Vec<Url>>,
}

#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
pub struct ImageIndex {
pub annotations: Option<Annotations>,
pub manifests: Vec<Manifests>,
/// This field specifies the image index schema version as an integer
#[serde(rename = "schemaVersion")]
pub schema_version: i64,
}
8 changes: 8 additions & 0 deletions crates/oci-image-spec/src/image_layout.rs
Original file line number Diff line number Diff line change
@@ -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,
}
12 changes: 12 additions & 0 deletions crates/oci-image-spec/src/image_manifest.rs
Original file line number Diff line number Diff line change
@@ -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<Annotations>,
pub config: ContentDescriptor,
pub layers: Vec<ContentDescriptor>,
/// This field specifies the image manifest schema version as an integer
#[serde(rename = "schemaVersion")]
pub schema_version: i64,
}
6 changes: 6 additions & 0 deletions crates/oci-image-spec/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;