Skip to content

Commit fbf366f

Browse files
committed
vmm: Add mr_image in sys-config.json
1 parent 5d4aaa8 commit fbf366f

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

dstack-types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ pub struct SysConfig {
118118
pub pccs_url: Option<String>,
119119
pub docker_registry: Option<String>,
120120
pub host_api_url: String,
121+
#[serde(with = "hex_bytes", default)]
122+
pub mr_image: Vec<u8>,
121123
}
122124

123125
#[derive(Serialize, Deserialize, Debug, Clone)]

vmm/src/app.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,22 @@ impl App {
457457
let manifest = work_dir.manifest().context("Failed to read manifest")?;
458458
let cfg = &self.config;
459459
let image_path = cfg.image_path.join(&manifest.image);
460-
let image_info = ImageInfo::load(image_path.join("metadata.json"))
461-
.context("Failed to load image info")?;
462-
let img_ver = image_info.version_tuple().unwrap_or((0, 0, 0));
463-
let sys_config = if img_ver >= (0, 4, 2) {
460+
let image = Image::load(image_path).context("Failed to load image info")?;
461+
let img_ver = image.info.version_tuple().unwrap_or((0, 0, 0));
462+
let sys_config = if img_ver >= (5, 0, 0) {
463+
serde_json::json!({
464+
"kms_urls": cfg.cvm.kms_urls,
465+
"gateway_urls": cfg.cvm.gateway_urls,
466+
"pccs_url": cfg.cvm.pccs_url,
467+
"docker_registry": cfg.cvm.docker_registry,
468+
"host_api_url": format!("vsock://2:{}/api", cfg.host_api.port),
469+
"vm_config": {
470+
"mr_image": &image.digest,
471+
"cpu_count": manifest.vcpu,
472+
"memory_size": manifest.memory * 1024 * 1024,
473+
},
474+
})
475+
} else if img_ver >= (0, 4, 2) {
464476
serde_json::json!({
465477
"kms_urls": cfg.cvm.kms_urls,
466478
"gateway_urls": cfg.cvm.gateway_urls,
@@ -469,7 +481,8 @@ impl App {
469481
"host_api_url": format!("vsock://2:{}/api", cfg.host_api.port),
470482
})
471483
} else if img_ver >= (0, 4, 0) {
472-
let rootfs_hash = image_info
484+
let rootfs_hash = image
485+
.info
473486
.rootfs_hash
474487
.as_ref()
475488
.context("Rootfs hash not found in image info")?;
@@ -482,7 +495,8 @@ impl App {
482495
"host_api_url": format!("vsock://2:{}/api", cfg.host_api.port),
483496
})
484497
} else {
485-
let rootfs_hash = image_info
498+
let rootfs_hash = image
499+
.info
486500
.rootfs_hash
487501
.as_ref()
488502
.context("Rootfs hash not found in image info")?;

vmm/src/app/image.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct Image {
5656
pub hda: Option<PathBuf>,
5757
pub rootfs: Option<PathBuf>,
5858
pub bios: Option<PathBuf>,
59+
pub digest: Option<String>,
5960
}
6061

6162
impl Image {
@@ -67,6 +68,7 @@ impl Image {
6768
let hda = info.hda.as_ref().map(|hda| base_path.join(hda));
6869
let rootfs = info.rootfs.as_ref().map(|rootfs| base_path.join(rootfs));
6970
let bios = info.bios.as_ref().map(|bios| base_path.join(bios));
71+
let digest = fs::read_to_string(base_path.join("digest.txt")).ok().map(|s| s.trim().to_string());
7072
if info.version.is_empty() {
7173
// Older images does not have version field. Fallback to the version of the image folder name
7274
info.version = guess_version(&base_path).unwrap_or_default();
@@ -78,6 +80,7 @@ impl Image {
7880
kernel,
7981
rootfs,
8082
bios,
83+
digest,
8184
}
8285
.ensure_exists()
8386
}

0 commit comments

Comments
 (0)