Skip to content
Merged
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
24 changes: 24 additions & 0 deletions crates/oci-tar-builder/src/bin.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::fs::File;
use std::path::PathBuf;
use std::{env, fs};
Expand All @@ -6,6 +7,7 @@ use anyhow::Context;
use clap::Parser;
use oci_spec::image::{self as spec, Arch};
use oci_tar_builder::{Builder, WASM_LAYER_MEDIA_TYPE};
use sha256::{digest, try_digest};

pub fn main() {
let args = Args::parse();
Expand All @@ -21,9 +23,15 @@ pub fn main() {
let entry_point = args.name.clone() + ".wasm";

let mut builder = Builder::default();
let mut layer_digests = Vec::new();
for module_path in args.module.iter() {
let module_path = PathBuf::from(module_path);
builder.add_layer_with_media_type(&module_path, WASM_LAYER_MEDIA_TYPE.to_string());
layer_digests.push(
try_digest(&module_path)
.context("failed to calculate digest for module")
.unwrap(),
);
}

for layer_config in args.layer.iter() {
Expand All @@ -33,6 +41,11 @@ pub fn main() {
let layer_type = layer_options.first().unwrap();
let layer_path = PathBuf::from(layer_options.last().unwrap());
builder.add_layer_with_media_type(&layer_path, layer_type.to_string());
layer_digests.push(
try_digest(&layer_path)
.context("failed to calculate digest for module")
.unwrap(),
);
}

if let Some(components_path) = args.components.as_deref() {
Expand All @@ -44,6 +57,11 @@ pub fn main() {
match ext {
"wasm" => {
builder.add_layer_with_media_type(&path, WASM_LAYER_MEDIA_TYPE.to_string());
layer_digests.push(
try_digest(&path)
.context("failed to calculate digest for module")
.unwrap(),
);
}
_ => println!(
"Skipping Unknown file type: {:?} with extension {:?}",
Expand All @@ -54,8 +72,14 @@ pub fn main() {
}
}

// Need each config to be unique since we don't have layers to make them unique in the rootfs
// https://github.com/opencontainers/image-spec/pull/1173
let unique_id = digest(layer_digests.join(""));
let mut labels: HashMap<String, String> = HashMap::new();
labels.insert("containerd.runwasi.layers".to_string(), unique_id);
let config = spec::ConfigBuilder::default()
.entrypoint(vec![entry_point])
.labels(labels)
.build()
.unwrap();

Expand Down