Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions crates/daemon-deploy/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ fn compose_check() -> HealthCheck {
}
}

/// The page a Compose stack's port is asked for, if any. Only a stack that
/// serves the web is asked: one with a health check of its own, or with a
/// domain to serve. A port alone says nothing about what listens on it (a
/// database, a game server, something on UDP), so that stack only has to
/// keep running.
fn compose_probe(spec: &DeploySpec) -> Option<HealthCheck> {
match &spec.health {
Some(check) => Some(check.clone()),
None if !spec.domains.is_empty() => Some(compose_check()),
None => None,
}
}

impl Deployer {
/// The reverse proxy in use now.
pub fn proxy(&self) -> Proxy {
Expand Down Expand Up @@ -1387,9 +1400,8 @@ impl Deployer {

progress.phase("health", Some(70)).await;
let host_port = spec.port.filter(|p| *p > 0);
match host_port {
Some(port) => {
let check = spec.health.clone().unwrap_or_else(compose_check);
match host_port.zip(compose_probe(spec)) {
Some((port, check)) => {
let target = Target {
host_port: port,
container_port: None,
Expand Down Expand Up @@ -2159,6 +2171,36 @@ mod tests {
}
}

#[test]
fn only_a_compose_stack_that_serves_the_web_has_its_port_asked() {
let spec = |extra: serde_json::Value| -> DeploySpec {
let mut raw = serde_json::json!({
"service": "minecraft",
"commit": "a".repeat(40),
"compose_file": "compose.yaml",
"port": 25565,
});
raw.as_object_mut()
.unwrap()
.extend(extra.as_object().unwrap().clone());
serde_json::from_value(raw).unwrap()
};

// A game server or database: a port, but nothing to ask over HTTP.
assert_eq!(compose_probe(&spec(serde_json::json!({}))), None);
// A domain means it serves the web, so it has to answer at all.
assert_eq!(
compose_probe(&spec(serde_json::json!({"domains": ["mc.example.com"]}))),
Some(compose_check())
);
// Its own health check is always used.
let own = compose_probe(&spec(serde_json::json!({
"health": {"path": "/up", "expected_status": 200, "timeout_secs": 30, "retries": 5}
})))
.unwrap();
assert_eq!(own.path, "/up");
}

#[test]
fn build_methods_are_checked_against_what_they_need() {
let spec = |extra: serde_json::Value| -> DeploySpec {
Expand Down
Loading