Skip to content

Commit

Permalink
fix: Fix for wrong traefik config regarding TLS (Fixes #157)
Browse files Browse the repository at this point in the history
  • Loading branch information
stmh committed Jan 3, 2025
1 parent 70a95e4 commit 8f459a5
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions scotty/src/docker/loadbalancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,23 @@ impl LoadBalancerImpl for TraefikLoadBalancer {
format!("traefik.http.routers.{}-{}.rule", &service_name, idx),
format!("Host(`{}`)", domain),
);

if global_settings.traefik.use_tls {
labels.insert(
format!("traefik.http.routers.{}-{}.tls", &service_name, idx),
"true".to_string(),
);

if let Some(certresolver) = &global_settings.traefik.certresolver {
labels.insert(
format!(
"traefik.http.routers.{}-{}.tls.certresolver",
&service_name, idx
),
certresolver.clone(),
);
}
}
}

labels.insert(
Expand All @@ -247,19 +264,6 @@ impl LoadBalancerImpl for TraefikLoadBalancer {
),
format!("{}", &service.port),
);
if global_settings.traefik.use_tls {
labels.insert(
format!("traefik.http.routers.{}.tls", &service_name),
"true".to_string(),
);

if let Some(certresolver) = &global_settings.traefik.certresolver {
labels.insert(
format!("traefik.http.routers.{}.tls.certresolver", &service_name),
certresolver.clone(),
);
}
}

let mut middlewares = vec![];

Expand Down Expand Up @@ -444,12 +448,12 @@ mod tests {
"8080"
);
assert_eq!(
labels.get("traefik.http.routers.web--myapp.tls").unwrap(),
labels.get("traefik.http.routers.web--myapp-0.tls").unwrap(),
"true"
);
assert_eq!(
labels
.get("traefik.http.routers.web--myapp.tls.certresolver")
.get("traefik.http.routers.web--myapp-0.tls.certresolver")
.unwrap(),
"myresolver"
);
Expand Down

0 comments on commit 8f459a5

Please sign in to comment.