Skip to content

Commit

Permalink
Allow specifying service domain directly
Browse files Browse the repository at this point in the history
  • Loading branch information
akrantz01 committed May 3, 2022
1 parent e56ab7c commit 86a9e26
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
6 changes: 3 additions & 3 deletions example-service.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
# Whether to enable web access (default: true)
enabled = true

# The base domain where the application can be accessed
# Defaults to the `deployment.domain` key in the configuration
base = "wafflehacks.tech"
# The domain where the application can be accessed
# Defaults to the filename combined with the `deployment.domain` key in the configuration
domain = "testing.wafflehacks.tech"

# What external services this depends on
# Currently supports: PostgreSQL and Redis
Expand Down
2 changes: 1 addition & 1 deletion src/management/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async fn get(service: String) -> Result<impl Reply, Rejection> {
"{}.{}",
&service,
cfg.web
.base
.domain
.as_ref()
.unwrap_or_else(|| &config::instance().deployment.domain)
))
Expand Down
13 changes: 8 additions & 5 deletions src/processor/jobs/update_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ impl Job for UpdateService {
.image(&service.docker.image, &service.docker.tag);

if service.web.enabled {
let subdomain = self.name.replace('-', ".");
let base = match &service.web.base {
Some(base) => base,
None => &config.deployment.domain,
let domain = match service.web.domain.clone() {
Some(d) => d,
None => format!(
"{}.{}",
self.name.replace('-', "."),
&config.deployment.domain
),
};

options = options.domain(format!("{}.{}", subdomain, base));
options = options.domain(domain);
}

for (k, v) in service.environment.iter() {
Expand Down
8 changes: 4 additions & 4 deletions src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ pub struct Web {
pub enabled: bool,
#[serde(default)]
#[serde_as(as = "NoneAsEmptyString")]
pub base: Option<String>,
pub domain: Option<String>,
}

impl Default for Web {
fn default() -> Web {
Web {
enabled: true,
base: None,
domain: None,
}
}
}
Expand Down Expand Up @@ -159,7 +159,7 @@ mod tests {
assert_eq!(service.environment.len(), 4);
assert_eq!(service.secrets.len(), 6);
assert_eq!(service.web.enabled, true);
assert_eq!(service.web.base, Some("wafflehacks.tech".into()));
assert_eq!(service.web.domain, Some("testing.wafflehacks.tech".into()));
}

#[tokio::test]
Expand All @@ -177,6 +177,6 @@ mod tests {
assert_eq!(service.environment.len(), 0);
assert_eq!(service.secrets.len(), 0);
assert_eq!(service.web.enabled, true);
assert_eq!(service.web.base, None);
assert_eq!(service.web.domain, None);
}
}

0 comments on commit 86a9e26

Please sign in to comment.