From de1cf114c4bcff49469356852cf2a8804b55d562 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Sun, 21 Jul 2024 16:56:53 -0700 Subject: [PATCH] feat: allow configuring opengb config path --- rivet-toolchain/src/backend/mod.rs | 9 +++++++-- rivet-toolchain/src/config/settings.rs | 18 ++++++++++++++++++ rivet-toolchain/src/tasks/backend_dev.rs | 5 +++-- rivet-toolchain/src/tasks/backend_sdk_gen.rs | 9 +++++++-- rivet-toolchain/src/tasks/deploy/backend.rs | 6 ++++-- 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/rivet-toolchain/src/backend/mod.rs b/rivet-toolchain/src/backend/mod.rs index a4188b04..2c488f21 100644 --- a/rivet-toolchain/src/backend/mod.rs +++ b/rivet-toolchain/src/backend/mod.rs @@ -5,7 +5,7 @@ use rivet_api::{apis, models}; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, io::Write, path::PathBuf}; use tempfile::NamedTempFile; -use tokio::{process::Command}; +use tokio::process::Command; use crate::{ config, @@ -15,6 +15,7 @@ use crate::{ const DEFAULT_OPENGB_DOCKER_TAG: &'static str = "ghcr.io/rivet-gg/opengb/v0.1.2"; pub struct OpenGbCommandOpts { + pub config_path: String, pub args: Vec, pub env: HashMap, pub cwd: PathBuf, @@ -45,6 +46,7 @@ pub async fn build_opengb_command(opts: OpenGbCommandOpts) -> GlobalResult { let mut cmd = shell_cmd("opengb"); + cmd.arg("--path").arg(opts.config_path); cmd.args(opts.args); cmd.envs(opts.env); cmd.current_dir(opts.cwd); @@ -71,6 +73,9 @@ pub async fn build_opengb_command(opts: OpenGbCommandOpts) -> GlobalResult GlobalResult, + /// Backend ocnfig to use when running backend config. + #[serde(default = "BackendDevConfig::config_path")] + pub config_path: String, +} + +impl BackendDevConfig { + fn config_path() -> String { + "backend.dev.json".to_string() + } } #[derive(Default, Clone, Serialize, Deserialize)] @@ -58,6 +67,15 @@ pub struct BackendDeployConfig { /// Env vars to pass to the deploy OpenGB commands. #[serde(default)] pub command_environment: HashMap, + /// Backend ocnfig to use when running backend config. + #[serde(default = "BackendDeployConfig::config_path")] + pub config_path: String, +} + +impl BackendDeployConfig { + fn config_path() -> String { + "backend.json".into() + } } #[derive(Default, Clone, Serialize, Deserialize)] diff --git a/rivet-toolchain/src/tasks/backend_dev.rs b/rivet-toolchain/src/tasks/backend_dev.rs index f5911a4a..be78072c 100644 --- a/rivet-toolchain/src/tasks/backend_dev.rs +++ b/rivet-toolchain/src/tasks/backend_dev.rs @@ -25,10 +25,10 @@ impl super::Task for Task { } async fn run(task: TaskCtx, input: Self::Input) -> GlobalResult { - let mut cmd_env = config::settings::try_read(|settings| { + let (mut cmd_env, config_path) = config::settings::try_read(|settings| { let mut env = settings.backend.command_environment.clone(); env.extend(settings.backend.dev.command_environment.clone()); - Ok(env) + Ok((env, settings.backend.dev.config_path.clone())) }) .await?; cmd_env.insert("OPENGB_PORT".into(), input.port.to_string()); @@ -36,6 +36,7 @@ impl super::Task for Task { let exit_code = backend::run_opengb_command( task.clone(), backend::OpenGbCommandOpts { + config_path, args: vec!["dev".into(), "--force-deploy-migrations".into()], env: cmd_env, cwd: input.cwd.into(), diff --git a/rivet-toolchain/src/tasks/backend_sdk_gen.rs b/rivet-toolchain/src/tasks/backend_sdk_gen.rs index f29ae07b..b77712b5 100644 --- a/rivet-toolchain/src/tasks/backend_sdk_gen.rs +++ b/rivet-toolchain/src/tasks/backend_sdk_gen.rs @@ -28,10 +28,14 @@ impl super::Task for Task { } async fn run(task: TaskCtx, input: Input) -> GlobalResult { - let (mut cmd_env, sdk_settings) = config::settings::try_read(|settings| { + let (mut cmd_env, sdk_settings, config_path) = config::settings::try_read(|settings| { let mut env = settings.backend.command_environment.clone(); env.extend(settings.backend.sdk.command_environment.clone()); - Ok((env, settings.backend.sdk.clone())) + Ok(( + env, + settings.backend.sdk.clone(), + settings.backend.deploy.config_path.clone(), + )) }) .await?; @@ -44,6 +48,7 @@ impl super::Task for Task { let exit_code = backend::run_opengb_command( task.clone(), backend::OpenGbCommandOpts { + config_path, args: vec![ "sdk".into(), "generate".into(), diff --git a/rivet-toolchain/src/tasks/deploy/backend.rs b/rivet-toolchain/src/tasks/deploy/backend.rs index acab54a0..d5aaf6f0 100644 --- a/rivet-toolchain/src/tasks/deploy/backend.rs +++ b/rivet-toolchain/src/tasks/deploy/backend.rs @@ -118,15 +118,16 @@ pub async fn deploy(ctx: &Ctx, task: TaskCtx, opts: DeployOpts) -> GlobalResult< task.log_stdout(format!("[Building Project] {}", project_path.display())); // Build - let cmd_env = config::settings::try_read(|settings| { + let (cmd_env, config_path) = config::settings::try_read(|settings| { let mut env = settings.backend.command_environment.clone(); env.extend(settings.backend.deploy.command_environment.clone()); - Ok(env) + Ok((env, settings.backend.deploy.config_path.clone())) }) .await?; let cmd = backend::run_opengb_command( task.clone(), backend::OpenGbCommandOpts { + config_path: config_path.clone(), args: vec![ "build".into(), "--db-driver".into(), @@ -170,6 +171,7 @@ pub async fn deploy(ctx: &Ctx, task: TaskCtx, opts: DeployOpts) -> GlobalResult< let migrate_cmd = backend::run_opengb_command( task.clone(), backend::OpenGbCommandOpts { + config_path, args: vec!["db".into(), "deploy".into()], env: migrate_env, cwd: project_path.clone(),