From 8f6074b874f4db8807a225d81944dc662a584eec Mon Sep 17 00:00:00 2001 From: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:03:58 +0200 Subject: [PATCH] feat: image generation based off language --- src/vmm/src/service.rs | 15 +++++++++++++-- tools/rootfs/mkrootfs.sh | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/vmm/src/service.rs b/src/vmm/src/service.rs index c6c3126..5d7f2ee 100644 --- a/src/vmm/src/service.rs +++ b/src/vmm/src/service.rs @@ -1,5 +1,5 @@ use self::vmmorchestrator::{ - vmm_service_server::VmmService as VmmServiceTrait, RunVmmRequest, RunVmmResponse, + vmm_service_server::VmmService as VmmServiceTrait, Language, RunVmmRequest, RunVmmResponse }; use crate::core::vmm::VMM; use crate::VmmErrors; @@ -36,7 +36,7 @@ pub struct VmmService; impl VmmServiceTrait for VmmService { async fn run( &self, - _request: Request, + request: Request, ) -> Result, Status> { let response = vmmorchestrator::RunVmmResponse {}; @@ -77,10 +77,21 @@ impl VmmServiceTrait for VmmService { let initramfs_exists = Path::new(&initramfs_entire_file_path).try_exists().expect(&format!("Could not access folder {:?}", &initramfs_entire_file_path)); if !initramfs_exists { + // get request with the language + let req: RunVmmRequest = request.into_inner(); + let language: Language = Language::from_i32(req.language).expect("Unknown language"); + + let image = match language { + Language::Rust => "rust:alpine", + Language::Python => "python:alpine", + Language::Node => "node:alpine", + }; + info!("Initramfs not found, building initramfs"); // Execute the script using sh and capture output and error streams let output = Command::new("sh") .arg("./tools/rootfs/mkrootfs.sh") + .arg(image) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() diff --git a/tools/rootfs/mkrootfs.sh b/tools/rootfs/mkrootfs.sh index 10929ac..88aa127 100755 --- a/tools/rootfs/mkrootfs.sh +++ b/tools/rootfs/mkrootfs.sh @@ -8,7 +8,7 @@ fi if [ -d fs-gen ] then - cargo run --bin fs-gen -- alpine:latest ./fs-gen/test -o ../tools/rootfs/initramfs.img + cargo run --bin fs-gen -- $1 ./fs-gen/test -o ../tools/rootfs/initramfs.img else echo "Module fs-gen not found" fi \ No newline at end of file