From 4f484e58e988a8bc5b7cfd895075fa17ee743b6c Mon Sep 17 00:00:00 2001 From: Nulo Date: Fri, 23 Jun 2023 18:20:30 -0300 Subject: [PATCH] parsear entrypoint en image config --- rootfs/init/src/main.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/rootfs/init/src/main.rs b/rootfs/init/src/main.rs index 9cc2dba..4c54768 100644 --- a/rootfs/init/src/main.rs +++ b/rootfs/init/src/main.rs @@ -8,7 +8,8 @@ use std::{env, io, os::unix, path::Path, process}; #[serde(rename_all = "PascalCase")] struct Config { env: Vec, - cmd: Vec, + cmd: Option>, + entrypoint: Option>, } #[derive(Serialize, Deserialize, Debug)] @@ -39,8 +40,20 @@ fn main() -> Result<(), io::Error> { unix::fs::chroot(src_path)?; env::set_current_dir("/")?; - let mut child = process::Command::new(&config.config.cmd[0]) - .args(&config.config.cmd[1..]) + // https://github.com/opencontainers/image-spec/blob/b5ec432b1c946c09e1568b18ef70b654a93739f6/conversion.md#verbatim-fields + let args = match (config.config.cmd, config.config.entrypoint) { + (None, Some(args)) => args, + (Some(args), None) => args, + (None, None) => panic!("Invalid config"), + (Some(cmd), Some(entrypoint)) => { + let mut args = entrypoint.clone(); + args.append(&mut cmd.clone()); + args + } + }; + + let mut child = process::Command::new(&args[0]) + .args(&args[1..]) .env_clear() .envs(config.config.env.iter().map(|s| s.split_once('=').unwrap())) .spawn()?;