From f0925f0ae989c55a913e383fac43b9e5ebfa03bf Mon Sep 17 00:00:00 2001 From: NathanFlurry Date: Mon, 9 Sep 2024 09:26:55 +0000 Subject: [PATCH] chore: remove bolt templates (#1135) ## Changes --- lib/bolt/cli/src/commands/create.rs | 148 ------ lib/bolt/cli/src/commands/mod.rs | 1 - lib/bolt/cli/src/main.rs | 3 - lib/bolt/core/src/tasks/mod.rs | 1 - lib/bolt/core/src/tasks/template.rs | 468 ------------------ svc/templates/README.md | 3 - svc/templates/api/Cargo.toml | 31 -- svc/templates/api/Service.toml | 7 - svc/templates/api/src/auth.rs | 25 - svc/templates/api/src/lib.rs | 2 - svc/templates/api/src/main.rs | 5 - svc/templates/api/src/route/example.rs | 17 - svc/templates/api/src/route/mod.rs | 28 -- svc/templates/api/tests/basic.rs | 59 --- svc/templates/bucket/Service.toml | 8 - svc/templates/database/Service.toml | 7 - svc/templates/operation/Cargo.toml | 18 - svc/templates/operation/Service.toml | 7 - svc/templates/operation/src/lib.rs | 13 - svc/templates/operation/tests/integration.rs | 6 - svc/templates/proto/msg/{{ name }}.proto | 13 - svc/templates/proto/{{ name }}.proto | 13 - svc/templates/standalone/Cargo.toml | 19 - svc/templates/standalone/Service.toml | 9 - svc/templates/standalone/src/lib.rs | 23 - svc/templates/standalone/src/main.rs | 11 - svc/templates/standalone/tests/integration.rs | 18 - svc/templates/worker/Cargo.toml | 19 - svc/templates/worker/Service.toml | 8 - svc/templates/worker/src/lib.rs | 1 - svc/templates/worker/src/workers/mod.rs | 5 - .../worker/src/workers/{{ snake name }}.rs | 9 - .../worker/tests/{{ snake name }}.rs | 13 - 33 files changed, 1018 deletions(-) delete mode 100644 lib/bolt/cli/src/commands/create.rs delete mode 100644 lib/bolt/core/src/tasks/template.rs delete mode 100644 svc/templates/README.md delete mode 100644 svc/templates/api/Cargo.toml delete mode 100644 svc/templates/api/Service.toml delete mode 100644 svc/templates/api/src/auth.rs delete mode 100644 svc/templates/api/src/lib.rs delete mode 100644 svc/templates/api/src/main.rs delete mode 100644 svc/templates/api/src/route/example.rs delete mode 100644 svc/templates/api/src/route/mod.rs delete mode 100644 svc/templates/api/tests/basic.rs delete mode 100644 svc/templates/bucket/Service.toml delete mode 100644 svc/templates/database/Service.toml delete mode 100644 svc/templates/operation/Cargo.toml delete mode 100644 svc/templates/operation/Service.toml delete mode 100644 svc/templates/operation/src/lib.rs delete mode 100644 svc/templates/operation/tests/integration.rs delete mode 100644 svc/templates/proto/msg/{{ name }}.proto delete mode 100644 svc/templates/proto/{{ name }}.proto delete mode 100644 svc/templates/standalone/Cargo.toml delete mode 100644 svc/templates/standalone/Service.toml delete mode 100644 svc/templates/standalone/src/lib.rs delete mode 100644 svc/templates/standalone/src/main.rs delete mode 100644 svc/templates/standalone/tests/integration.rs delete mode 100644 svc/templates/worker/Cargo.toml delete mode 100644 svc/templates/worker/Service.toml delete mode 100644 svc/templates/worker/src/lib.rs delete mode 100644 svc/templates/worker/src/workers/mod.rs delete mode 100644 svc/templates/worker/src/workers/{{ snake name }}.rs delete mode 100644 svc/templates/worker/tests/{{ snake name }}.rs diff --git a/lib/bolt/cli/src/commands/create.rs b/lib/bolt/cli/src/commands/create.rs deleted file mode 100644 index 8ff7c32a65..0000000000 --- a/lib/bolt/cli/src/commands/create.rs +++ /dev/null @@ -1,148 +0,0 @@ -use anyhow::*; -use bolt_core::{context::ProjectContext, tasks}; -use clap::Parser; - -#[derive(Parser)] -pub struct CreateOpts { - #[clap(subcommand)] - command: SubCommand, - - #[clap(long)] - create_pkg: bool, - /// The additional root in which to create the service. Leave blank for top-most. - #[clap(long)] - root: Option, -} - -impl CreateOpts { - pub async fn execute(self, ctx: ProjectContext) -> Result<()> { - let CreateOpts { - command, - create_pkg, - root, - } = self; - - command.execute(ctx, create_pkg, root).await - } -} - -#[derive(Parser)] -enum SubCommand { - Api { - #[clap(index = 1)] - api_name: String, - }, - Bucket { - #[clap(index = 1)] - pkg_name: String, - #[clap(index = 2)] - service_name: String, - }, - #[clap(alias = "db")] - Database { - #[clap(index = 1)] - pkg_name: String, - #[clap(index = 2)] - service_name: String, - }, - #[clap(alias = "op")] - Operation { - #[clap(index = 1)] - pkg_name: String, - #[clap(index = 2)] - service_name: String, - }, - Standalone { - #[clap(index = 1)] - pkg_name: String, - #[clap(index = 2)] - service_name: String, - }, - Worker { - #[clap(index = 1)] - pkg_name: String, - #[clap(index = 2)] - service_name: String, - }, -} - -impl SubCommand { - pub async fn execute( - self, - mut ctx: ProjectContext, - create_pkg: bool, - root: Option, - ) -> Result<()> { - let (pkg_name, template_type, service_name) = match self { - Self::Api { api_name } => ( - String::new(), - tasks::template::TemplateType::Api, - api_name.to_string(), - ), - Self::Bucket { - pkg_name, - service_name, - } => ( - pkg_name.to_string(), - tasks::template::TemplateType::Bucket, - service_name.to_string(), - ), - Self::Database { - pkg_name, - service_name, - } => ( - pkg_name.to_string(), - tasks::template::TemplateType::Database, - service_name.to_string(), - ), - Self::Operation { - pkg_name, - service_name, - } => ( - pkg_name.to_string(), - tasks::template::TemplateType::Operation, - service_name.to_string(), - ), - Self::Standalone { - pkg_name, - service_name, - } => ( - pkg_name.to_string(), - tasks::template::TemplateType::Standalone, - service_name.to_string(), - ), - Self::Worker { - pkg_name, - service_name, - } => ( - pkg_name.to_string(), - tasks::template::TemplateType::Worker, - service_name.to_string(), - ), - }; - - assert!( - !pkg_name.contains('_'), - "package name should not contain underscores, use dashes" - ); - - assert!( - !service_name.contains('_'), - "service name should not contain underscores, use dashes" - ); - - tasks::template::generate( - &mut ctx, - tasks::template::TemplateOpts { - root, - create_pkg, - pkg_name, - template_type, - service_name, - }, - ) - .await?; - - Ok(()) - } -} diff --git a/lib/bolt/cli/src/commands/mod.rs b/lib/bolt/cli/src/commands/mod.rs index 04078453d8..35295dc034 100644 --- a/lib/bolt/cli/src/commands/mod.rs +++ b/lib/bolt/cli/src/commands/mod.rs @@ -2,7 +2,6 @@ pub mod admin; pub mod check; pub mod cluster; pub mod config; -pub mod create; pub mod db; pub mod generate; pub mod infra; diff --git a/lib/bolt/cli/src/main.rs b/lib/bolt/cli/src/main.rs index a6d8247784..e88bf21a5c 100644 --- a/lib/bolt/cli/src/main.rs +++ b/lib/bolt/cli/src/main.rs @@ -36,8 +36,6 @@ enum SubCommand { Logs(logs::LogsOpts), /// Deploys and tests Rivet services. Test(test::TestOpts), - /// Creates a new service. - Create(create::CreateOpts), /// Generates files required for the Rivet project. Seldom used. #[clap(hide(true), alias = "gen")] Generate { @@ -120,7 +118,6 @@ async fn main_inner() -> Result { SubCommand::Check(command) => command.execute(ctx).await?, SubCommand::Logs(command) => command.execute(ctx).await?, SubCommand::Test(command) => command.execute(ctx).await?, - SubCommand::Create(command) => command.execute(ctx).await?, SubCommand::Generate { command } => command.execute(ctx).await?, SubCommand::Secret { command } => command.execute(ctx).await?, SubCommand::Output { command } => command.execute(ctx).await?, diff --git a/lib/bolt/core/src/tasks/mod.rs b/lib/bolt/core/src/tasks/mod.rs index 310c86104e..0512a2fd53 100644 --- a/lib/bolt/core/src/tasks/mod.rs +++ b/lib/bolt/core/src/tasks/mod.rs @@ -7,6 +7,5 @@ pub mod gen; pub mod infra; pub mod migrate; pub mod ssh; -pub mod template; pub mod test; pub mod up; diff --git a/lib/bolt/core/src/tasks/template.rs b/lib/bolt/core/src/tasks/template.rs deleted file mode 100644 index db263af492..0000000000 --- a/lib/bolt/core/src/tasks/template.rs +++ /dev/null @@ -1,468 +0,0 @@ -use std::{ - fmt, - path::{Path, PathBuf}, -}; - -use anyhow::*; -use async_recursion::async_recursion; -use tokio::fs; - -use crate::context::ProjectContext; - -pub enum TemplateType { - Api, - Bucket, - Database, - Operation, - Standalone, - Worker, -} - -impl fmt::Display for TemplateType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - TemplateType::Api => write!(f, "API"), - TemplateType::Bucket => write!(f, "bucket"), - TemplateType::Database => write!(f, "database"), - TemplateType::Operation => write!(f, "operation"), - TemplateType::Standalone => write!(f, "standalone"), - TemplateType::Worker => write!(f, "worker"), - } - } -} - -pub struct TemplateOpts { - pub root: Option, - pub create_pkg: bool, - pub pkg_name: String, - pub template_type: TemplateType, - pub service_name: String, -} - -pub async fn generate(ctx: &mut ProjectContext, opts: TemplateOpts) -> Result<()> { - let TemplateOpts { - root, - create_pkg, - pkg_name, - template_type, - service_name, - } = opts; - - // Create base path based on selected root - let base_path = if let Some(root) = root { - let root_path = &ctx - .config() - .additional_roots - .get(&root) - .ok_or_else(|| anyhow!("Root `{}` not found in local config", root))? - .path; - - ctx.path().join(root_path) - } else { - ctx.path().to_owned() - }; - - if !create_pkg - && !matches!(template_type, TemplateType::Api) - && fs::metadata(base_path.join("svc").join("pkg").join(&pkg_name)) - .await - .is_err() - { - bail!( - "Package `{}` does not exist under the `{}` root. Try a different root, create the package folder yourself, or use `--create-pkg` to automatically create it.", - pkg_name, - base_path.display(), - ); - } - - // Check for package service type - if matches!( - template_type, - TemplateType::Operation | TemplateType::Worker - ) && fs::metadata( - base_path - .join("svc") - .join("pkg") - .join(&pkg_name) - .join("Service.toml"), - ) - .await - .is_ok() - { - bail!( - "Creating operations or workers in the new refactored packages ({pkg_name}) is not yet supported.", - ); - } - - // Touch types lib to force it to rebuild generated proto when making a new package - if create_pkg { - let lib_file = base_path - .join("lib") - .join("types") - .join("build") - .join("src") - .join("lib.rs"); - let alt_lib_file = base_path - .join("lib") - .join("types") - .join("src") - .join("lib.rs"); - - if let Err(err) = fs::OpenOptions::new() - .create(true) - .write(true) - .open(lib_file) - .await - { - if !matches!(err.kind(), std::io::ErrorKind::NotFound) { - return Err(err.into()); - } - } - - if let Err(err) = fs::OpenOptions::new() - .create(true) - .write(true) - .open(alt_lib_file) - .await - { - if !matches!(err.kind(), std::io::ErrorKind::NotFound) { - return Err(err.into()); - } - } - } - - // Build templating manager - let mut hb = handlebars::Handlebars::new(); - hb.register_helper("snake", Box::new(handlebars_helpers::snake)); - hb.register_helper( - "screaming_snake", - Box::new(handlebars_helpers::screaming_snake), - ); - let render_data = handlebars_helpers::RenderData { - pkg: pkg_name.clone(), - name: service_name.clone(), - }; - - // Get template directory - let input_path = match template_type { - TemplateType::Api => base_path.join("svc").join("templates").join("api"), - TemplateType::Bucket => base_path.join("svc").join("templates").join("bucket"), - TemplateType::Database => base_path.join("svc").join("templates").join("database"), - TemplateType::Operation => base_path.join("svc").join("templates").join("operation"), - TemplateType::Standalone => base_path.join("svc").join("templates").join("standalone"), - TemplateType::Worker => base_path.join("svc").join("templates").join("worker"), - }; - let output_path = match template_type { - TemplateType::Api => base_path.join("svc").join("api").join(&service_name), - TemplateType::Bucket => base_path - .join("svc") - .join("pkg") - .join(&pkg_name) - .join("buckets") - .join(&service_name), - TemplateType::Database => base_path - .join("svc") - .join("pkg") - .join(&pkg_name) - .join("db") - .join(&service_name), - TemplateType::Operation => base_path - .join("svc") - .join("pkg") - .join(&pkg_name) - .join("ops") - .join(&service_name), - TemplateType::Standalone => base_path - .join("svc") - .join("pkg") - .join(&pkg_name) - .join("standalone") - .join(&service_name), - TemplateType::Worker => base_path - .join("svc") - .join("pkg") - .join(&pkg_name) - .join("worker"), - }; - - rivet_term::status::progress(format!("Creating new {} service...", template_type), ""); - eprintln!(""); - - // Generate new service - match template_type { - TemplateType::Worker => { - let proto_path = base_path - .join("svc") - .join("pkg") - .join(pkg_name) - .join("proto") - .join("msg"); - let proto_file_path = proto_path.join(format!("{}.proto", service_name)); - - // Check if proto exists - if fs::metadata(&proto_file_path).await.is_ok() { - bail!( - "Worker protobuf definition already exists at {}", - proto_file_path.display() - ); - } - - // Check if worker parent already exists - if check_service_exists(&output_path).await.is_err() { - generate_worker_partial( - &mut hb, - &render_data, - input_path, - output_path, - service_name, - ) - .await?; - } else { - generate_dir(&mut hb, &render_data, input_path, output_path).await?; - } - - // Generate proto file - fs::create_dir_all(&proto_path).await?; - generate_file( - &mut hb, - &render_data, - base_path - .join("svc") - .join("templates") - .join("proto") - .join("msg") - .join("{{ name }}.proto"), - proto_path, - ) - .await?; - } - TemplateType::Operation => { - // Check if proto exists - let proto_path = base_path - .join("svc") - .join("pkg") - .join(pkg_name) - .join("proto"); - let proto_file_path = proto_path.join(format!("{}.proto", service_name)); - if fs::metadata(&proto_file_path).await.is_ok() { - bail!( - "Operation protobuf definition already exists at {}", - proto_file_path.display() - ); - } - - check_service_exists(&output_path).await?; - generate_dir(&mut hb, &render_data, input_path, output_path).await?; - - // Generate proto file - fs::create_dir_all(&proto_path).await?; - generate_file( - &mut hb, - &render_data, - base_path - .join("svc") - .join("templates") - .join("proto") - .join("{{ name }}.proto"), - proto_path, - ) - .await?; - } - _ => { - check_service_exists(&output_path).await?; - generate_dir(&mut hb, &render_data, input_path, output_path).await?; - } - }; - - eprintln!(); - rivet_term::status::success("Done", ""); - - Ok(()) -} - -async fn generate_worker_partial( - hb: &mut handlebars::Handlebars<'_>, - render_data: &handlebars_helpers::RenderData, - input_path: PathBuf, - output_path: PathBuf, - service_name: String, -) -> Result<()> { - let snake_name = service_name.replace('-', "_"); - - // Create directories - let workers_root = output_path.join("src").join("workers"); - let tests_root = output_path.join("tests"); - fs::create_dir_all(&workers_root).await?; - fs::create_dir_all(&tests_root).await?; - - rivet_term::status::progress("Worker parent already exists, skipping initiation...", ""); - - // Check if source code exists - let worker_file_path = workers_root.join(format!("{}.rs", snake_name)); - if fs::metadata(&worker_file_path).await.is_ok() { - bail!( - "Worker file already exists at {}", - worker_file_path.display() - ); - } - - generate_file( - hb, - render_data, - input_path - .join("src") - .join("workers") - .join("{{ snake name }}.rs"), - workers_root, - ) - .await?; - generate_file( - hb, - render_data, - input_path.join("tests").join("{{ snake name }}.rs"), - tests_root, - ) - .await?; - - // Update worker mod.rs - { - let worker_mod_path = output_path.join("src").join("workers").join("mod.rs"); - rivet_term::status::progress("Editing", worker_mod_path.display()); - let worker_mod_str = fs::read_to_string(&worker_mod_path).await?; - - let Some(bracket_idx) = worker_mod_str.find('[') else { - bail!("malformed mod.rs file"); - }; - - fs::write( - worker_mod_path, - &format!( - "pub mod {};\n{}\n\t{},{}", - snake_name, - &worker_mod_str[..bracket_idx + 1], - snake_name, - &worker_mod_str[bracket_idx + 1..] - ), - ) - .await?; - } - - Ok(()) -} - -async fn check_service_exists(output_path: &Path) -> Result<()> { - // Check if service directory already exists - if fs::metadata(&output_path).await.is_ok() { - bail!("Service already exists at {}", output_path.display()); - } - - Ok(()) -} - -#[async_recursion] -async fn generate_dir( - hb: &mut handlebars::Handlebars<'_>, - render_data: &handlebars_helpers::RenderData, - input_path: PathBuf, - output_path: PathBuf, -) -> Result<()> { - // Make sure output directory exists - fs::create_dir_all(&output_path).await?; - - // Read each file in directory to either template or recursively call this - // function - let mut entries = fs::read_dir(input_path.as_path()).await?; - while let Some(entry) = entries.next_entry().await? { - let metadata = entry.metadata().await?; - if metadata.is_file() { - generate_file(hb, render_data, entry.path(), output_path.clone()).await?; - } else if metadata.is_dir() { - // Recursively generate next directory - generate_dir( - hb, - render_data, - input_path.join(entry.file_name()), - output_path.join(entry.file_name()), - ) - .await?; - } - } - - Ok(()) -} - -async fn generate_file( - hb: &mut handlebars::Handlebars<'_>, - render_data: &handlebars_helpers::RenderData, - input_file_path: PathBuf, - output_path: PathBuf, -) -> Result<()> { - let output_file_path = output_path.join(hb.render_template( - input_file_path.file_name().unwrap().to_str().unwrap(), - render_data, - )?); - rivet_term::status::progress( - "Templating", - format!( - "{} -> {}", - input_file_path.display(), - output_file_path.display(), - ), - ); - - // Template the file and write to output - let template_name = input_file_path.to_string_lossy().to_string(); - hb.register_template_file(template_name.as_str(), input_file_path)?; - let output = hb.render(template_name.as_str(), render_data)?; - fs::write(output_file_path, output).await?; - - Ok(()) -} - -mod handlebars_helpers { - use handlebars::{ - Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError, - }; - use serde::Serialize; - - #[derive(Serialize)] - pub struct RenderData { - pub pkg: String, - pub name: String, - } - - pub fn snake( - h: &Helper, - _: &Handlebars, - _: &Context, - _: &mut RenderContext, - out: &mut dyn Output, - ) -> HelperResult { - let param = h.param(0).unwrap(); - let value = param - .value() - .as_str() - .ok_or_else(|| RenderError::new("Could not convert value to string"))? - .replace('-', "_"); - out.write(value.as_str())?; - Ok(()) - } - - pub fn screaming_snake( - h: &Helper, - _: &Handlebars, - _: &Context, - _: &mut RenderContext, - out: &mut dyn Output, - ) -> HelperResult { - let param = h.param(0).unwrap(); - let value = param - .value() - .as_str() - .ok_or_else(|| RenderError::new("Could not convert value to string"))? - .replace('-', "_") - .to_uppercase(); - out.write(value.as_str())?; - Ok(()) - } -} diff --git a/svc/templates/README.md b/svc/templates/README.md deleted file mode 100644 index 11ac4f1799..0000000000 --- a/svc/templates/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Templates - -This folder contains templates for package services and api services used by `bolt create`. diff --git a/svc/templates/api/Cargo.toml b/svc/templates/api/Cargo.toml deleted file mode 100644 index de651e1748..0000000000 --- a/svc/templates/api/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "api-{{name}}" -version = "0.0.1" -authors = ["Rivet Gaming, LLC "] -edition = "2021" -license = "Apache-2.0" - -[dependencies] -api-helper = { path = "../../../lib/api-helper/build" } -chirp-client = { path = "../../../lib/chirp/client" } -rivet-operation = { path = "../../../lib/operation/core" } -chrono = "0.4" -http = "0.2" -hyper = { version = "0.14", features = ["server", "http1", "stream", "tcp"] } -rivet-api = { path = "../../../sdks/full/rust" } -rivet-cache = { path = "../../../lib/cache/build" } -rivet-claims = { path = "../../../lib/claims" } -rivet-health-checks = { path = "../../../lib/health-checks" } -rivet-pools = { path = "../../../lib/pools" } -s3-util = { path = "../../../lib/s3-util" } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -tokio = { version = "1.29" } -tracing = "0.1" -tracing-futures = "0.2" -tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "json", "ansi"] } -url = "2.2.2" -uuid = { version = "1", features = ["v4"] } - -[dev-dependencies] -rivet-connection = { path = "../../../lib/connection" } diff --git a/svc/templates/api/Service.toml b/svc/templates/api/Service.toml deleted file mode 100644 index 469417c41d..0000000000 --- a/svc/templates/api/Service.toml +++ /dev/null @@ -1,7 +0,0 @@ -[service] -name = "api-{{name}}" - -[runtime] -kind = "rust" - -[api-routes] diff --git a/svc/templates/api/src/auth.rs b/svc/templates/api/src/auth.rs deleted file mode 100644 index 9421b0cee4..0000000000 --- a/svc/templates/api/src/auth.rs +++ /dev/null @@ -1,25 +0,0 @@ -use api_helper::auth::{ApiAuth, AuthRateLimitCtx}; -use proto::claims::Claims; -use rivet_operation::prelude::*; - -pub struct Auth { - _claims: Option, -} - -#[async_trait] -impl ApiAuth for Auth { - async fn new( - api_token: Option, - rate_limit_ctx: AuthRateLimitCtx<'_>, - ) -> GlobalResult { - Self::rate_limit(rate_limit_ctx).await?; - - todo!(); - - Ok(Auth { _claims: None }) - } - - async fn rate_limit(_rate_limit_ctx: AuthRateLimitCtx<'_>) -> GlobalResult<()> { - Ok(()) - } -} diff --git a/svc/templates/api/src/lib.rs b/svc/templates/api/src/lib.rs deleted file mode 100644 index eeaeaaafb7..0000000000 --- a/svc/templates/api/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod auth; -pub mod route; diff --git a/svc/templates/api/src/main.rs b/svc/templates/api/src/main.rs deleted file mode 100644 index 593feef4a1..0000000000 --- a/svc/templates/api/src/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -use api_helper::start; - -fn main() { - start(api_{{snake name}}::route::handle); -} diff --git a/svc/templates/api/src/route/example.rs b/svc/templates/api/src/route/example.rs deleted file mode 100644 index 35d342c1a1..0000000000 --- a/svc/templates/api/src/route/example.rs +++ /dev/null @@ -1,17 +0,0 @@ -use api_helper::ctx::Ctx; -use proto::backend::pkg::*; -use rivet_operation::prelude::*; -use serde_json::json; - -use crate::auth::Auth; - -// MARK: POST /foo/{}/bar -pub async fn endpoint( - ctx: Ctx, - parameter: String, - _body: serde_json::Value, -) -> GlobalResult { - todo!(); - - Ok(json!({})) -} diff --git a/svc/templates/api/src/route/mod.rs b/svc/templates/api/src/route/mod.rs deleted file mode 100644 index 04cb80de04..0000000000 --- a/svc/templates/api/src/route/mod.rs +++ /dev/null @@ -1,28 +0,0 @@ -use api_helper::define_router; -use hyper::{Body, Request, Response}; -use uuid::Uuid; - -pub mod example; - -pub async fn handle( - shared_client: chirp_client::SharedClientHandle, - pools: rivet_pools::Pools, - cache: rivet_cache::Cache, - ray_id: uuid::Uuid, - request: Request, -) -> Result, http::Error> { - let response = Response::builder(); - - // Handle route - Router::handle(shared_client, pools, cache, ray_id, request, response).await -} - -define_router! { - routes: { - "foo" / String / "bar": { - POST: example::endpoint( - body: serde_json::Value, - ), - }, - }, -} diff --git a/svc/templates/api/tests/basic.rs b/svc/templates/api/tests/basic.rs deleted file mode 100644 index a8bd083d42..0000000000 --- a/svc/templates/api/tests/basic.rs +++ /dev/null @@ -1,59 +0,0 @@ -use std::sync::Once; - -use rivet_operation::prelude::*; - -static GLOBAL_INIT: Once = Once::new(); - -struct Ctx { - op_ctx: OperationContext<()>, -} - -impl Ctx { - async fn init() -> Ctx { - GLOBAL_INIT.call_once(|| { - tracing_subscriber::fmt() - .pretty() - .with_max_level(tracing::Level::INFO) - .with_target(false) - .init(); - }); - - let pools = rivet_pools::from_env("api-{{name}}-test").await.unwrap(); - let cache = rivet_cache::CacheInner::new( - "api-{{name}}-test".to_string(), - util::env::var("RIVET_SOURCE_HASH").unwrap(), - pools.redis_cache().unwrap(), - ); - let client = chirp_client::SharedClient::from_env(pools.clone()) - .expect("create client") - .wrap_new("api-{{name}}-test"); - let conn = rivet_connection::Connection::new(client, pools, cache); - let op_ctx = OperationContext::new( - "api-{{name}}-test".to_string(), - std::time::Duration::from_secs(60), - conn, - Uuid::new_v4(), - Uuid::new_v4(), - util::timestamp::now(), - util::timestamp::now(), - (), - ); - - Ctx { op_ctx } - } - - fn chirp(&self) -> &chirp_client::Client { - self.op_ctx.chirp() - } - - fn op_ctx(&self) -> &OperationContext<()> { - &self.op_ctx - } -} - -#[tokio::test(flavor = "multi_thread")] -async fn basic() { - let ctx = Ctx::init().await; - - todo!() -} diff --git a/svc/templates/bucket/Service.toml b/svc/templates/bucket/Service.toml deleted file mode 100644 index 575f31ba8c..0000000000 --- a/svc/templates/bucket/Service.toml +++ /dev/null @@ -1,8 +0,0 @@ -[service] -name = "bucket-{{pkg}}-{{name}}" - -[runtime] -kind = "s3" -upload_policy = "todo" - -[database] diff --git a/svc/templates/database/Service.toml b/svc/templates/database/Service.toml deleted file mode 100644 index 7dc7bf9da7..0000000000 --- a/svc/templates/database/Service.toml +++ /dev/null @@ -1,7 +0,0 @@ -[service] -name = "db-{{pkg}}-{{name}}" - -[runtime] -kind = "crdb" - -[database] diff --git a/svc/templates/operation/Cargo.toml b/svc/templates/operation/Cargo.toml deleted file mode 100644 index f473793686..0000000000 --- a/svc/templates/operation/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "{{pkg}}-{{name}}" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -chirp-client = { path = "../../../../../lib/chirp/client" } -rivet-operation = { path = "../../../../../lib/operation/core" } - -[dependencies.sqlx] -git = "https://github.com/rivet-gg/sqlx" -rev = "08d6e61aa0572e7ec557abbedb72cebb96e1ac5b" -default-features = false - -[dev-dependencies] -chirp-worker = { path = "../../../../../lib/chirp/worker" } diff --git a/svc/templates/operation/Service.toml b/svc/templates/operation/Service.toml deleted file mode 100644 index 2fdcda397d..0000000000 --- a/svc/templates/operation/Service.toml +++ /dev/null @@ -1,7 +0,0 @@ -[service] -name = "{{pkg}}-{{name}}" - -[runtime] -kind = "rust" - -[operation] diff --git a/svc/templates/operation/src/lib.rs b/svc/templates/operation/src/lib.rs deleted file mode 100644 index a012f438ff..0000000000 --- a/svc/templates/operation/src/lib.rs +++ /dev/null @@ -1,13 +0,0 @@ -use proto::backend::{self, pkg::*}; -use rivet_operation::prelude::*; - -#[operation(name = "{{pkg}}-{{name}}")] -pub async fn handle( - ctx: OperationContext<{{snake pkg}}::{{snake name}}::Request>, -) -> GlobalResult<{{snake pkg}}::{{snake name}}::Response> { - todo!(); - - Ok({{snake pkg}}::{{snake name}}::Response { - - }) -} diff --git a/svc/templates/operation/tests/integration.rs b/svc/templates/operation/tests/integration.rs deleted file mode 100644 index d7d641e21e..0000000000 --- a/svc/templates/operation/tests/integration.rs +++ /dev/null @@ -1,6 +0,0 @@ -use chirp_worker::prelude::*; - -#[worker_test] -async fn basic(ctx: TestCtx) { - // TODO: -} diff --git a/svc/templates/proto/msg/{{ name }}.proto b/svc/templates/proto/msg/{{ name }}.proto deleted file mode 100644 index ba11bb5cb2..0000000000 --- a/svc/templates/proto/msg/{{ name }}.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.{{snake pkg}}.msg.{{snake name}}; - -import "proto/common.proto"; - -/// name = "msg-{{pkg}}-{{name}}" -/// parameters = [ -/// { name = "user_id" }, -/// ] -message Message { - -} diff --git a/svc/templates/proto/{{ name }}.proto b/svc/templates/proto/{{ name }}.proto deleted file mode 100644 index 440ecdd481..0000000000 --- a/svc/templates/proto/{{ name }}.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.{{snake pkg}}.{{snake name}}; - -import "proto/common.proto"; - -message Request { - -} - -message Response { - -} diff --git a/svc/templates/standalone/Cargo.toml b/svc/templates/standalone/Cargo.toml deleted file mode 100644 index 838692b86c..0000000000 --- a/svc/templates/standalone/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "{{pkg}}-{{name}}" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -chirp-client = { path = "../../../../../lib/chirp/client" } -rivet-operation = { path = "../../../../../lib/operation/core" } -rivet-connection = { path = "../../../../../lib/connection" } -rivet-runtime = { path = "../../../../../lib/runtime" } -tokio = { version = "1.29", features = ["full"] } -tracing = "0.1" -tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "json", "ansi"] } -tracing-logfmt = "0.3" - -[dev-dependencies] -chirp-worker = { path = "../../../../../lib/chirp/worker" } diff --git a/svc/templates/standalone/Service.toml b/svc/templates/standalone/Service.toml deleted file mode 100644 index 04c97716cc..0000000000 --- a/svc/templates/standalone/Service.toml +++ /dev/null @@ -1,9 +0,0 @@ -[service] -name = "{{pkg}}-{{name}}" - -[runtime] -kind = "rust" - -[periodic] -cron = "0 0 * * *" - diff --git a/svc/templates/standalone/src/lib.rs b/svc/templates/standalone/src/lib.rs deleted file mode 100644 index 8b67c55860..0000000000 --- a/svc/templates/standalone/src/lib.rs +++ /dev/null @@ -1,23 +0,0 @@ -use rivet_operation::prelude::*; - -#[tracing::instrument(skip_all)] -pub async fn run_from_env(ts: i64) -> GlobalResult<()> { - let pools = rivet_pools::from_env("{{pkg}}-{{name}}").await?; - let client = - chirp_client::SharedClient::from_env(pools.clone())?.wrap_new("{{pkg}}-{{name}}"); - let cache = rivet_cache::CacheInner::from_env(pools.clone())?; - let ctx = OperationContext::new( - "{{pkg}}-{{name}}".into(), - std::time::Duration::from_secs(60), - rivet_connection::Connection::new(client, pools, cache), - Uuid::new_v4(), - Uuid::new_v4(), - util::timestamp::now(), - util::timestamp::now(), - (), - ); - - todo!(); - - Ok(()) -} diff --git a/svc/templates/standalone/src/main.rs b/svc/templates/standalone/src/main.rs deleted file mode 100644 index b9c11e0fca..0000000000 --- a/svc/templates/standalone/src/main.rs +++ /dev/null @@ -1,11 +0,0 @@ -use rivet_operation::prelude::*; - -fn main() -> GlobalResult<()> { - rivet_runtime::run(start()).unwrap() -} - -async fn start() -> GlobalResult<()> { - {{snake pkg}}_{{snake name}}::run_from_env(util::timestamp::now()).await?; - - Ok(()) -} diff --git a/svc/templates/standalone/tests/integration.rs b/svc/templates/standalone/tests/integration.rs deleted file mode 100644 index 1fef5b6aac..0000000000 --- a/svc/templates/standalone/tests/integration.rs +++ /dev/null @@ -1,18 +0,0 @@ -use chirp_worker::prelude::*; -use tracing_subscriber::prelude::*; - -use ::{{snake pkg}}_{{snake name}}::run_from_env; - -#[tokio::test(flavor = "multi_thread")] -async fn basic() { - tracing_subscriber::registry() - .with( - tracing_logfmt::builder() - .layer() - .with_filter(tracing_subscriber::filter::LevelFilter::INFO), - ) - .init(); - - // TODO: - run_from_env(util::timestamp::now()).await.unwrap(); -} diff --git a/svc/templates/worker/Cargo.toml b/svc/templates/worker/Cargo.toml deleted file mode 100644 index 6b1dad2add..0000000000 --- a/svc/templates/worker/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "{{pkg}}-worker" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -rivet-convert = { path = "../../../../lib/convert" } -chirp-client = { path = "../../../../lib/chirp/client" } -chirp-worker = { path = "../../../../lib/chirp/worker" } -chrono = "0.4" -lazy_static = "1.4.0" -rivet-health-checks = { path = "../../../../lib/health-checks" } -rivet-metrics = { path = "../../../../lib/metrics" } -rivet-runtime = { path = "../../../../lib/runtime" } - -[dev-dependencies] -chirp-worker = { path = "../../../../lib/chirp/worker" } diff --git a/svc/templates/worker/Service.toml b/svc/templates/worker/Service.toml deleted file mode 100644 index b77514517d..0000000000 --- a/svc/templates/worker/Service.toml +++ /dev/null @@ -1,8 +0,0 @@ -[service] -name = "{{pkg}}-worker" - -[runtime] -kind = "rust" - -[consumer] - diff --git a/svc/templates/worker/src/lib.rs b/svc/templates/worker/src/lib.rs deleted file mode 100644 index 3719b10aa8..0000000000 --- a/svc/templates/worker/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod workers; diff --git a/svc/templates/worker/src/workers/mod.rs b/svc/templates/worker/src/workers/mod.rs deleted file mode 100644 index a723ed444b..0000000000 --- a/svc/templates/worker/src/workers/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod {{snake name}}; - -chirp_worker::workers![ - {{snake name}}, -]; diff --git a/svc/templates/worker/src/workers/{{ snake name }}.rs b/svc/templates/worker/src/workers/{{ snake name }}.rs deleted file mode 100644 index 75ac2afe16..0000000000 --- a/svc/templates/worker/src/workers/{{ snake name }}.rs +++ /dev/null @@ -1,9 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::pkg::*; - -#[worker(name = "{{pkg}}-{{name}}")] -async fn worker(ctx: &OperationContext<{{snake pkg}}::msg::{{snake name}}::Message>) -> GlobalResult<()> { - todo!(); - - Ok(()) -} diff --git a/svc/templates/worker/tests/{{ snake name }}.rs b/svc/templates/worker/tests/{{ snake name }}.rs deleted file mode 100644 index 738b1e9b27..0000000000 --- a/svc/templates/worker/tests/{{ snake name }}.rs +++ /dev/null @@ -1,13 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::pkg::*; - -#[worker_test] -async fn {{snake name}}(ctx: TestCtx) { - // msg!([ctx] {{snake pkg}}::msg::{{snake name}}() { - - // }) - // .await - // .unwrap(); - - todo!(); -}