Skip to content

Commit

Permalink
Expose docker utils for re-use (#788)
Browse files Browse the repository at this point in the history
Two things:
1. Allow me to access `docker` under the hood of the `DockerRuntime` to
do custom stuff in a separate runtime. I still want to keep
`DockerRuntime` around because some functionality is identical and it
allows me to lean on the existing runtime's implementation of stuff.
2. Allow me to re-use the container config, which is by and large
identical in a separate runtime -- except for the `backend_name`. Turns
out it's not that hard to make that optional!
  • Loading branch information
michaelsilver authored Jul 19, 2024
1 parent d0c27fa commit 8c85ce3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plane/plane-tests/tests/docker_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async fn test_resource_limits() {
}

let mut config = get_container_config_from_executor_config(
&backend_name,
Some(&backend_name),
executor_config.clone(),
None,
None,
Expand Down
15 changes: 9 additions & 6 deletions plane/src/drone/runtime/docker/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn validate_mount_path(path: &Path) -> Result<()> {
}

pub fn get_container_config_from_executor_config(
backend_id: &BackendName,
backend_id: Option<&BackendName>,
exec_config: DockerExecutorConfig,
runtime: Option<&str>,
key: Option<&AcquiredKey>,
Expand All @@ -146,7 +146,10 @@ pub fn get_container_config_from_executor_config(
) -> Result<bollard::container::Config<String>> {
let mut env = exec_config.env;
env.insert("PORT".to_string(), CONTAINER_PORT.to_string());
env.insert("SESSION_BACKEND_ID".to_string(), backend_id.to_string());

if let Some(backend_id) = backend_id {
env.insert("SESSION_BACKEND_ID".to_string(), backend_id.to_string());
}

if let Some(key) = key {
env.insert(
Expand Down Expand Up @@ -205,7 +208,7 @@ pub fn get_container_config_from_executor_config(

Ok(bollard::container::Config {
image: Some(exec_config.image.clone()),
labels: Some(create_labels(backend_id)),
labels: backend_id.map(create_labels),
env: Some(env),
exposed_ports: Some(
vec![(format!("{}/tcp", CONTAINER_PORT), HashMap::new())]
Expand Down Expand Up @@ -271,7 +274,7 @@ pub async fn run_container(
};

let config = get_container_config_from_executor_config(
backend_id,
Some(backend_id),
exec_config,
docker.config.runtime.as_deref(),
acquired_key,
Expand Down Expand Up @@ -328,7 +331,7 @@ mod tests {
exec_config.mount = mount;

get_container_config_from_executor_config(
&backend_name,
Some(&backend_name),
exec_config,
None,
acquired_key.as_ref(),
Expand Down Expand Up @@ -361,7 +364,7 @@ mod tests {
exec_config.network_name = network_name.map(|n| n.to_string());

get_container_config_from_executor_config(
&backend_name,
Some(&backend_name),
exec_config,
None,
acquired_key.as_ref(),
Expand Down
2 changes: 1 addition & 1 deletion plane/src/drone/runtime/docker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct DockerRuntimeConfig {
pub type MetricsCallback = Box<dyn Fn(BackendMetricsMessage) + Send + Sync + 'static>;

pub struct DockerRuntime {
docker: Docker,
pub docker: Docker,
config: DockerRuntimeConfig,
metrics_callback: Arc<Mutex<Option<MetricsCallback>>>,
events_sender: Sender<TerminateEvent>,
Expand Down

0 comments on commit 8c85ce3

Please sign in to comment.