parsear entrypoint en image config

This commit is contained in:
Cat /dev/Nulo 2023-06-23 18:20:30 -03:00
parent 67784da199
commit 4f484e58e9

View file

@ -8,7 +8,8 @@ use std::{env, io, os::unix, path::Path, process};
#[serde(rename_all = "PascalCase")] #[serde(rename_all = "PascalCase")]
struct Config { struct Config {
env: Vec<String>, env: Vec<String>,
cmd: Vec<String>, cmd: Option<Vec<String>>,
entrypoint: Option<Vec<String>>,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -39,8 +40,20 @@ fn main() -> Result<(), io::Error> {
unix::fs::chroot(src_path)?; unix::fs::chroot(src_path)?;
env::set_current_dir("/")?; env::set_current_dir("/")?;
let mut child = process::Command::new(&config.config.cmd[0]) // https://github.com/opencontainers/image-spec/blob/b5ec432b1c946c09e1568b18ef70b654a93739f6/conversion.md#verbatim-fields
.args(&config.config.cmd[1..]) 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() .env_clear()
.envs(config.config.env.iter().map(|s| s.split_once('=').unwrap())) .envs(config.config.env.iter().map(|s| s.split_once('=').unwrap()))
.spawn()?; .spawn()?;