Skip to content

Commit

Permalink
Pass PORT environment variable to docker backend (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgb committed Oct 19, 2023
1 parent 3570e2d commit a0e50c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
8 changes: 8 additions & 0 deletions core/src/messages/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use std::{
time::Duration,
};

const DEFAULT_CONTAINER_PORT: u16 = 8080;

#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug)]
pub enum DockerCredentials {
UsernamePassword { username: String, password: String },
Expand Down Expand Up @@ -320,6 +322,12 @@ pub struct DockerExecutableConfig {
pub volume_mounts: Vec<Value>,
}

impl DockerExecutableConfig {
pub fn port(&self) -> u16 {
self.port.unwrap_or(DEFAULT_CONTAINER_PORT)
}
}

#[serde_as]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, TypedMessage)]
#[typed_message(subject = "cluster.#cluster.drone.#drone_id.spawn", response = "bool")]
Expand Down
20 changes: 7 additions & 13 deletions drone/src/agent/engines/docker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use std::{net::SocketAddr, pin::Pin};
use tokio_stream::{wrappers::IntervalStream, Stream, StreamExt};

/// The port in the container which is exposed.
const DEFAULT_CONTAINER_PORT: u16 = 8080;
const DOCKER_TIMEOUT_SECONDS: u64 = 30;
/// Interval between reporting stats of a running backend.
/// NOTE: the minimum possible interval is 1 second.
Expand Down Expand Up @@ -172,11 +171,12 @@ impl DockerInterface {
name: &str,
executable_config: &DockerExecutableConfig,
) -> Result<()> {
let env: Vec<String> = executable_config
.env
.iter()
.map(|(k, v)| format!("{}={}", k, v))
.collect();
let mut env = executable_config.env.clone();

env.entry("PORT".to_string())
.or_insert_with(|| executable_config.port().to_string());

let env: Vec<String> = env.iter().map(|(k, v)| format!("{}={}", k, v)).collect();

let device_requests = if self.gpu {
Some(vec![DeviceRequest {
Expand Down Expand Up @@ -379,13 +379,7 @@ impl Engine for DockerInterface {

if running {
let ip = get_ip_of_container(&container)?;
let addr = SocketAddr::new(
ip,
spawn_request
.executable
.port
.unwrap_or(DEFAULT_CONTAINER_PORT),
);
let addr = SocketAddr::new(ip, spawn_request.executable.port());

Ok(EngineBackendStatus::Running { addr })
} else {
Expand Down

0 comments on commit a0e50c6

Please sign in to comment.