Skip to content

Commit cb8eef7

Browse files
committed
feat: add support to ports mapping
1 parent a72f071 commit cb8eef7

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/configs/index.rs

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl IndexConfig {
4747
pub struct Package {
4848
pub image: String,
4949
pub volumes: Option<Vec<Volume>>,
50+
pub ports: Option<Vec<Port>>,
5051
pub current_directory: Option<String>,
5152
pub environment_variables: Option<Vec<EnvironmentVariable>>,
5253
pub binaries: Option<Vec<Binary>>,
@@ -59,6 +60,7 @@ impl Package {
5960
Package {
6061
image: format!("docker.io/{}", name),
6162
volumes: None,
63+
ports: None,
6264
current_directory: None,
6365
environment_variables: None,
6466
binaries: None,
@@ -73,6 +75,12 @@ pub struct Volume {
7375
pub target: String,
7476
}
7577

78+
#[derive(Serialize, Deserialize, Debug, Clone)]
79+
pub struct Port {
80+
pub host: u16,
81+
pub container: u16,
82+
}
83+
7684
#[derive(Serialize, Deserialize, Debug, Clone)]
7785
pub struct Binary {
7886
pub name: String,

src/packages.rs

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ impl Package {
6666
info!("- [{}]", self.name);
6767
if verbose {
6868
info!(" - image: {}", self.index.image);
69+
if let Some(ports) = &self.index.ports {
70+
info!(" - volumes:");
71+
for port in ports {
72+
info!(" - {}:{}", port.host, port.container);
73+
}
74+
}
6975
if let Some(volumes) = &self.index.volumes {
7076
info!(" - volumes:");
7177
for volume in volumes {

src/runner.rs

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn run(package: &Package, binary: Option<String>, params: &Vec<String>) -> b
3232
let binary = get_binary(package, &binary);
3333

3434
add_default_flags(package, &mut args);
35+
add_ports(package, &mut args);
3536
add_volumes(package, &mut args);
3637
add_current_directory(package, &mut args);
3738
add_environment_variables(package, &mut args);
@@ -93,6 +94,15 @@ fn add_volumes(package: &Package, args: &mut Vec<String>) {
9394
}
9495
}
9596

97+
fn add_ports(package: &Package, args: &mut Vec<String>) {
98+
if let Some(ports) = &package.index.ports {
99+
for port in ports {
100+
args.push("-p".to_string());
101+
args.push(format!("{}:{}", &port.host, port.container));
102+
}
103+
}
104+
}
105+
96106
fn add_current_directory(package: &Package, args: &mut Vec<String>) {
97107
if let Some(current_directory) = &package.index.current_directory {
98108
args.push("-w".to_string());

0 commit comments

Comments
 (0)