Port mappings
This commit is contained in:
@@ -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]]
|
||||
|
||||
18
src/main.rs
18
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<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 {
|
||||
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user