Compare commits

..

2 Commits

Author SHA1 Message Date
Maurice
30c813bcf2 Update 2025-08-16 20:08:50 +02:00
Maurice
37c86fc994 Port mappings 2025-08-13 14:26:49 +02:00
3 changed files with 21 additions and 7 deletions

View File

@@ -56,8 +56,8 @@ protocol = "tcp" # Protocol, optional
# Optionally you can also assign volumes
[[volumes]]
volume = "<VOLUME NAME>" # Volume name or path on host
path = "<PATH>" # Volume location/target inside container
source = "<VOLUME NAME>" # Volume name or path on host
target = "<PATH>" # Volume location/target inside container
# Or you can make more advanced volumes with mounts
[[mounts]]

View File

@@ -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<String> = 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 {
@@ -153,7 +167,7 @@ pub fn generate_openrc(config: &ServiceConfig) -> String {
"podman stop {} --ignore",
config.service.name
)));
script.push_str("\n}\n\n");
script.push_str("\n}\n");
// }
script

View File

@@ -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)]