From 245f09bd220695664e754f5407f424e9033c322c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 2 Feb 2021 12:42:45 +0100 Subject: Add network-mode setting for endpoints This patch adds the ability to set network mode for an endpoint. This means that all containers on the endpoint are started with, for example, --net=host (if that is desired). Signed-off-by: Matthias Beyer Tested-by: Matthias Beyer --- src/endpoint/configured.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/endpoint/configured.rs') diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index 7d38c45..83d51b4 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -50,6 +50,9 @@ pub struct Endpoint { #[getset(get_copy = "pub")] num_max_jobs: usize, + #[getset(get = "pub")] + network_mode: Option, + #[getset(get = "pub")] uri: String, } @@ -116,6 +119,7 @@ impl Endpoint { .uri(ep.uri().clone()) .docker(docker) .num_max_jobs(ep.maxjobs()) + .network_mode(ep.network_mode().clone()) .build() }), @@ -124,6 +128,7 @@ impl Endpoint { .name(ep.name().clone()) .uri(ep.uri().clone()) .num_max_jobs(ep.maxjobs()) + .network_mode(ep.network_mode().clone()) .docker(shiplift::Docker::unix(ep.uri())) .build() }), @@ -301,11 +306,18 @@ impl<'a> PreparedContainer<'a> { .collect::>(); trace!("Job resources: Environment variables = {:?}", envs); - let builder_opts = shiplift::ContainerOptions::builder(job.image().as_ref()) - .env(envs.iter().map(AsRef::as_ref).collect::>()) - .cmd(vec!["/bin/bash"]) // we start the container with /bin/bash, but exec() the script in it later - .attach_stdin(true) // we have to attach, otherwise bash exits - .build(); + let builder_opts = { + let mut builder_opts = shiplift::ContainerOptions::builder(job.image().as_ref()); + builder_opts.env(envs.iter().map(AsRef::as_ref).collect::>()); + builder_opts.cmd(vec!["/bin/bash"]); // we start the container with /bin/bash, but exec() the script in it later + builder_opts.attach_stdin(true); // we have to attach, otherwise bash exits + + if let Some(network_mode) = endpoint.network_mode().as_ref() { + builder_opts.network_mode(network_mode); + } + + builder_opts.build() + }; trace!("Builder options = {:?}", builder_opts); let create_info = endpoint -- cgit v1.2.3