diff --git a/README.md b/README.md index d1a2f17..b23a8cd 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,8 @@ protocol = "tcp" # Protocol, optional # Optionally you can also assign volumes [[volumes]] -volume = "" # Volume name or path on host -path = "" # Volume location/target inside container +source = "" # Volume name or path on host +target = "" # Volume location/target inside container # Or you can make more advanced volumes with mounts [[mounts]] diff --git a/src/main.rs b/src/main.rs index 7a634c2..e6556f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,10 @@ use crate::service::{NetworkMapping, ServiceConfig}; mod service; +fn escape(str: &str) -> String { + str.replace("$", "\\$") +} + pub fn generate_openrc(config: &ServiceConfig) -> String { let networks: Vec = config.networks.clone() .into_iter() @@ -18,7 +22,7 @@ pub fn generate_openrc(config: &ServiceConfig) -> String { let mut script = String::from("#!/sbin/openrc-run\n# !!! AUTO GENERATED - DO NOT EDIT !!!\n\n"); let wrap = |cmd: &str| { if let Some(user) = config.user.as_ref() { - format!("\tsu -c \"{}\" {} ", cmd, user) + format!("\tsu -c \"{}\" {} ", escape(cmd), user) } else { format!("\t{}", cmd) } @@ -74,6 +78,16 @@ pub fn generate_openrc(config: &ServiceConfig) -> String { arguments.push(format!("--cap-add {}", capability)); } + for port in &config.ports { + if let Some(protocol) = &port.protocol { + arguments.push(format!( + "--publish {}:{}/{}", port.host, port.container, protocol + )); + } else { + arguments.push(format!("--publish {}:{}", port.host, port.container)); + } + } + for secret in &config.secrets { if let Some(target) = &secret.target { arguments.push(format!("--secret {},target={}", &secret.key, target)); @@ -94,7 +108,7 @@ pub fn generate_openrc(config: &ServiceConfig) -> String { } for volume in &config.volumes { - arguments.push(format!("--volume {}:{}", &volume.volume, &volume.path)); + arguments.push(format!("--volume {}:{}", &volume.source, &volume.target)); } for mount in &config.mounts { diff --git a/src/service.rs b/src/service.rs index c064de0..b8e8d27 100644 --- a/src/service.rs +++ b/src/service.rs @@ -69,8 +69,8 @@ pub struct PortMapping { #[derive(Debug, Deserialize)] pub struct VolumeMapping { - pub volume: String, - pub path: String + pub source: String, + pub target: String } #[derive(Debug, Deserialize)]