Port mappings

This commit is contained in:
Maurice
2025-08-13 14:26:49 +02:00
parent 19d1bfe9a2
commit 37c86fc994
3 changed files with 20 additions and 6 deletions

View File

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

View File

@@ -7,6 +7,10 @@ use crate::service::{NetworkMapping, ServiceConfig};
mod service; mod service;
fn escape(str: &str) -> String {
str.replace("$", "\\$")
}
pub fn generate_openrc(config: &ServiceConfig) -> String { pub fn generate_openrc(config: &ServiceConfig) -> String {
let networks: Vec<String> = config.networks.clone() let networks: Vec<String> = config.networks.clone()
.into_iter() .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 mut script = String::from("#!/sbin/openrc-run\n# !!! AUTO GENERATED - DO NOT EDIT !!!\n\n");
let wrap = |cmd: &str| { let wrap = |cmd: &str| {
if let Some(user) = config.user.as_ref() { if let Some(user) = config.user.as_ref() {
format!("\tsu -c \"{}\" {} ", cmd, user) format!("\tsu -c \"{}\" {} ", escape(cmd), user)
} else { } else {
format!("\t{}", cmd) format!("\t{}", cmd)
} }
@@ -74,6 +78,16 @@ pub fn generate_openrc(config: &ServiceConfig) -> String {
arguments.push(format!("--cap-add {}", capability)); 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 { for secret in &config.secrets {
if let Some(target) = &secret.target { if let Some(target) = &secret.target {
arguments.push(format!("--secret {},target={}", &secret.key, 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 { 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 { for mount in &config.mounts {

View File

@@ -69,8 +69,8 @@ pub struct PortMapping {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct VolumeMapping { pub struct VolumeMapping {
pub volume: String, pub source: String,
pub path: String pub target: String
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]