Skip to content

Commit

Permalink
Move additional project roots to Bolt.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Jan 6, 2024
1 parent a099995 commit 2db6d1b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **API** Return `API_REQUEST_TIMEOUT` error after 50s (see `docs/infrastructure/API_TIMEOUTS.md` for context)
- **API** Move generated client APIs to sdks/
- Lower long poll timeout from 60s -> 40s
- **Bolt** Moved additional project roots to Bolt.toml

### Security

Expand Down
10 changes: 0 additions & 10 deletions lib/bolt/config/src/local.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::{collections::HashMap, path::PathBuf};

use serde::Deserialize;

/// Configuration for the Bolt.local.toml file.
Expand All @@ -11,19 +9,11 @@ pub struct Local {
#[serde(default)]
pub namespace: Option<String>,
#[serde(default)]
pub additional_roots: HashMap<String, AdditionalRoot>,
#[serde(default)]
pub up: Up,
#[serde(default)]
pub rust: Rust,
}

#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct AdditionalRoot {
pub path: PathBuf,
}

#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct Up {}
Expand Down
8 changes: 8 additions & 0 deletions lib/bolt/config/src/ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ pub struct Rivet {
pub dynamic_servers: DynamicServers,
#[serde(default)]
pub cdn: Cdn,
#[serde(default)]
pub billing: Option<RivetBilling>,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
Expand Down Expand Up @@ -639,6 +641,12 @@ impl Default for Cdn {
}
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct RivetBilling {
region_price_ids: HashMap<String, String>,
}

fn default_regions() -> HashMap<String, Region> {
toml::from_str(include_str!("../default_regions.toml"))
.expect("failed to parse default_regions.toml")
Expand Down
9 changes: 8 additions & 1 deletion lib/bolt/config/src/project.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::Deserialize;
use std::{collections::HashMap, path::PathBuf};

pub fn decode(s: &str) -> Result<Project, toml::de::Error> {
toml::from_str(s)
Expand All @@ -10,5 +11,11 @@ pub fn decode(s: &str) -> Result<Project, toml::de::Error> {
#[serde(rename_all = "kebab-case")]
pub struct Project {
#[serde(default)]
pub billing_enabled: bool,
pub additional_roots: HashMap<String, AdditionalRoot>,
}

#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct AdditionalRoot {
pub path: PathBuf,
}
2 changes: 1 addition & 1 deletion lib/bolt/core/src/context/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl ProjectContextData {
let mut svc_ctxs_map = HashMap::new();

// Load sub projects
for (_, additional_root) in &config_local.additional_roots {
for (_, additional_root) in &config.additional_roots {
let path = project_root.join(&additional_root.path);
Self::load_root_dir(&mut svc_ctxs_map, path).await;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/bolt/core/src/context/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,11 @@ impl ServiceContextData {
}

// Add billing flag
if project_ctx.config().billing_enabled {
env.push(("IS_BILLING_ENABLED".to_owned(), "1".into()));
if let Some(billing) = &project_ctx.ns().rivet.billing {
env.push((
"RIVET_BILLING".to_owned(),
serde_json::to_string(&billing).unwrap(),
));
}

if project_ctx.ns().dns.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion lib/bolt/core/src/tasks/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn generate_project(ctx: &ProjectContext) {
dep::k8s::gen::project(ctx).await.unwrap();

// Generate additional roots
let additional_roots = &ctx.config_local().additional_roots;
let additional_roots = &ctx.config().additional_roots;
for (_, additional_root) in additional_roots {
let path = fs::canonicalize(ctx.path().join(&additional_root.path))
.await
Expand Down
2 changes: 1 addition & 1 deletion lib/bolt/core/src/tasks/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub async fn generate(ctx: &mut ProjectContext, opts: TemplateOpts) -> Result<()
// Create base path based on selected root
let base_path = if let Some(root) = root {
let root_path = &ctx
.config_local()
.config()
.additional_roots
.get(&root)
.ok_or_else(|| anyhow!("Root `{}` not found in local config", root))?
Expand Down

0 comments on commit 2db6d1b

Please sign in to comment.