Skip to content

Commit

Permalink
feat: image generation based off language
Browse files Browse the repository at this point in the history
  • Loading branch information
MurielParaire committed Apr 26, 2024
1 parent 5520619 commit 8f6074b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/vmm/src/service.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -36,7 +36,7 @@ pub struct VmmService;
impl VmmServiceTrait for VmmService {
async fn run(
&self,
_request: Request<RunVmmRequest>,
request: Request<RunVmmRequest>,
) -> Result<Response<RunVmmResponse>, Status> {
let response = vmmorchestrator::RunVmmResponse {};

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tools/rootfs/mkrootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8f6074b

Please sign in to comment.