diff --git a/errors/module/error-status.md b/errors/module/error-status.md deleted file mode 100644 index 5920550d1a..0000000000 --- a/errors/module/error-status.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name = "MODULE_ERROR_STATUS" -description = "Module returned an error status code: {status}" -description_basic = "Module returned an error status code." -http_status = 500 ---- - -# Module Error Status - -The module returned a non-200 status code. - -If you are writing a driver from scratch, validate the module returns a successful status code. diff --git a/errors/module/instance-destroyed.md b/errors/module/instance-destroyed.md deleted file mode 100644 index 00dba6d63f..0000000000 --- a/errors/module/instance-destroyed.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -name = "MODULE_INSTANCE_DESTROYED" -description = "Module instance destroyed." -http_status = 500 -experimental = true ---- - -# Module Instance Destroyed - -The module you were trying to call was destroyed. diff --git a/errors/module/instance-not-initiated.md b/errors/module/instance-not-initiated.md deleted file mode 100644 index 6aea0764f3..0000000000 --- a/errors/module/instance-not-initiated.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -name = "MODULE_INSTANCE_STARTING" -description = "Module instance is still started." -http_status = 500 -experimental = true ---- - -# Module Instance Still Starting - -The module instance is still started. Try again later. diff --git a/errors/module/malformed-response.md b/errors/module/malformed-response.md deleted file mode 100644 index 453e45beae..0000000000 --- a/errors/module/malformed-response.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name = "MODULE_MALFORMED_RESPONSE" -description = "Module returned malformed response." -http_status = 500 -experimental = true ---- - -# Module Malformed Response - -The module returned a response with an invalid format. - -If you are writing a driver from scratch, validate the response returns the correct data structure. diff --git a/errors/module/not-found.md b/errors/module/not-found.md deleted file mode 100644 index 02702a2789..0000000000 --- a/errors/module/not-found.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -name = "MODULE_KEY_NOT_FOUND" -description = "Module not found for key: {key}" -description_basic = "Module not found." -http_status = 400 -experimental = true ---- - -# Module Not Found - -Cannot find a module matching the given key. diff --git a/errors/module/request-failed.md b/errors/module/request-failed.md deleted file mode 100644 index b7f9a38b1f..0000000000 --- a/errors/module/request-failed.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name = "MODULE_REQUEST_FAILED" -description = "Failed to make request to module." -http_status = 500 -experimental = true ---- - -# Module Request Failed - -The request to the module failed to complete. - -If you are writing a driver from scratch, validate that the port is accessible. diff --git a/errors/module/script-not-found.md b/errors/module/script-not-found.md deleted file mode 100644 index 6e6dad064d..0000000000 --- a/errors/module/script-not-found.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -name = "MODULE_SCRIPT_NOT_FOUND" -description = "Module script not found: {script}" -description_basic = "Module script not found: {}" -http_status = 400 -experimental = true ---- - -# Module Script Not Found - -Cannot find the provided script. diff --git a/fern/definition/module/__package__.yml b/fern/definition/module/__package__.yml deleted file mode 100644 index e4c33bf975..0000000000 --- a/fern/definition/module/__package__.yml +++ /dev/null @@ -1,28 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json - -service: - auth: true - base-path: /module/modules - endpoints: - call: - path: /{module}/scripts/{script}/call - method: POST - path-parameters: - module: string - script: string - docs: | - Makes a request to a module's script. - request: - headers: - origin: optional - name: FindLobbyRequest - body: - properties: - namespace_id: optional - data: unknown - response: CallResponse - -types: - CallResponse: - properties: - data: unknown diff --git a/lib/bolt/cli/src/commands/ssh.rs b/lib/bolt/cli/src/commands/ssh.rs index 3c2d57796e..0acd25c113 100644 --- a/lib/bolt/cli/src/commands/ssh.rs +++ b/lib/bolt/cli/src/commands/ssh.rs @@ -44,25 +44,17 @@ impl SubCommand { let ssh_key = TempSshKey::new(&ctx, &ssh_key.map_or_else(|| "server".to_string(), |x| x)) .await?; - bolt_core::tasks::ssh::ip( - &ctx, - &ip, - &ssh_key, - command.as_deref(), - ) - .await?; + bolt_core::tasks::ssh::ip(&ctx, &ip, &ssh_key, command.as_deref()).await?; } Self::Id { server_id, command } => { - bolt_core::tasks::ssh::id(&ctx, &server_id, command.as_deref()) - .await?; + bolt_core::tasks::ssh::id(&ctx, &server_id, command.as_deref()).await?; } Self::Pool { pool, command, all } => { if all { let command = command.context("must provide command with --all")?; bolt_core::tasks::ssh::pool_all(&ctx, &pool, &command).await?; } else { - bolt_core::tasks::ssh::pool(&ctx, &pool, command.as_deref()) - .await?; + bolt_core::tasks::ssh::pool(&ctx, &pool, command.as_deref()).await?; } } } diff --git a/lib/bolt/core/src/dep/terraform/cli.rs b/lib/bolt/core/src/dep/terraform/cli.rs index 84570762ae..7d7c7eb058 100644 --- a/lib/bolt/core/src/dep/terraform/cli.rs +++ b/lib/bolt/core/src/dep/terraform/cli.rs @@ -60,7 +60,10 @@ pub async fn init_if_needed_quiet(ctx: &ProjectContext, plan_id: &str, quiet: bo .read_secret(&["terraform", "pg_backend", "conn_str"]) .await .unwrap(); - vec![format!("-backend-config=conn_str={tf_conn_str}")] + vec![ + format!("-backend-config=conn_str={tf_conn_str}"), + "-reconfigure".to_string(), + ] } }; diff --git a/lib/bolt/core/src/dep/terraform/gen.rs b/lib/bolt/core/src/dep/terraform/gen.rs index e72c6fa014..9e7a8e4b1e 100644 --- a/lib/bolt/core/src/dep/terraform/gen.rs +++ b/lib/bolt/core/src/dep/terraform/gen.rs @@ -43,19 +43,19 @@ pub async fn gen_bolt_tf(ctx: &ProjectContext, plan_id: &str) -> Result<()> { // Configure the backend let backend = match ctx.ns().terraform.backend { ns::TerraformBackend::Local {} => indoc!( - " + r#" terraform { - backend \"local\" {} + backend "local" {} } - " + "# ) .to_string(), ns::TerraformBackend::Postgres {} => indoc!( - " + r#" terraform { - backend \"pg\" {} + backend "pg" {} } - " + "# ) .to_string(), }; diff --git a/lib/convert/src/impls/cloud/version/mod.rs b/lib/convert/src/impls/cloud/version/mod.rs index 2cea54c848..e060deef59 100644 --- a/lib/convert/src/impls/cloud/version/mod.rs +++ b/lib/convert/src/impls/cloud/version/mod.rs @@ -34,8 +34,6 @@ pub async fn config_to_proto( }, kv: value.kv.map(|_| backend::kv::VersionConfig {}), identity: value.identity.map(|x| (*x).api_try_into()).transpose()?, - // TODO: - module: None, }) } diff --git a/proto/backend/cloud.proto b/proto/backend/cloud.proto index 1484c87616..a5c712edca 100644 --- a/proto/backend/cloud.proto +++ b/proto/backend/cloud.proto @@ -7,7 +7,6 @@ import "proto/backend/matchmaker.proto"; import "proto/backend/cdn.proto"; import "proto/backend/kv.proto"; import "proto/backend/identity.proto"; -import "proto/backend/module.proto"; message Game { rivet.common.Uuid game_id = 1; @@ -19,11 +18,12 @@ message GameNamespace { } message NamespaceConfig { + reserved 105; + optional rivet.backend.cdn.NamespaceConfig cdn = 101; optional rivet.backend.matchmaker.NamespaceConfig matchmaker = 102; optional rivet.backend.kv.NamespaceConfig kv = 103; optional rivet.backend.identity.NamespaceConfig identity = 104; - optional rivet.backend.module.GameNamespaceConfig module = 105; } message GameVersion { @@ -34,9 +34,10 @@ message GameVersion { // Represents how a game version will be published. This is a data type that will be used // before the version is actually inserted in to the database. message VersionConfig { + reserved 105; + optional rivet.backend.cdn.VersionConfig cdn = 101; optional rivet.backend.matchmaker.VersionConfig matchmaker = 102; optional rivet.backend.kv.VersionConfig kv = 103; optional rivet.backend.identity.VersionConfig identity = 104; - optional rivet.backend.module.GameVersionConfig module = 105; } diff --git a/proto/backend/module.proto b/proto/backend/module.proto deleted file mode 100644 index b3926052f9..0000000000 --- a/proto/backend/module.proto +++ /dev/null @@ -1,88 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.module; - -import "proto/common.proto"; -import "proto/backend/module/script.proto"; - -// MARK: Game Namespace Config -message GameNamespaceConfig { -} - -// MARK: Game Version Config -message GameVersionConfig { - message Dependency { - string key = 1; - rivet.common.Uuid module_version_id = 2; - } - - repeated Dependency dependencies = 1; -} - -// MARK: Game Version Config Context -message GameVersionConfigCtx { - -} - -// MARK: Game Version Config Meta -message GameVersionConfigMeta { - -} - -// Module -message Module { - enum Publicity { - PRIVATE = 0; - PUBLIC = 1; - } - - rivet.common.Uuid module_id = 1; - string name_id = 2; - rivet.common.Uuid team_id = 3; - int64 create_ts = 4; - Publicity publicity = 5; -} - -// Version -message Version { - rivet.common.Uuid version_id = 1; - rivet.common.Uuid module_id = 2; - int64 create_ts = 3; - - uint64 major = 101; - uint64 minor = 102; - uint64 patch = 103; - - repeated rivet.backend.module.Script scripts = 201; - - message Docker { - // TODO: Auth? - string image_tag = 1; - } - - oneof image { - Docker docker = 301; - } -} - -// Instance -message Instance { - rivet.common.Uuid instance_id = 1; - rivet.common.Uuid module_version_id = 2; - int64 create_ts = 3; - optional int64 destroy_ts = 4; - - message Dummy { - - } - - message Fly { - /// Null if app not created yet. - optional string fly_app_id = 1; - } - - oneof driver { - Dummy dummy = 101; - Fly fly = 102; - }; -} diff --git a/proto/backend/module/script.proto b/proto/backend/module/script.proto deleted file mode 100644 index 7f0cf3d65f..0000000000 --- a/proto/backend/module/script.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.module; - -import "proto/common.proto"; - -message Script { - message Callable { - - } - - string name = 1; - string request_schema = 2; - string response_schema = 3; - optional Callable callable = 4; -} - diff --git a/svc/Cargo.lock b/svc/Cargo.lock index df50f6f998..61d809f42b 100644 --- a/svc/Cargo.lock +++ b/svc/Cargo.lock @@ -695,62 +695,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "api-module" -version = "0.0.1" -dependencies = [ - "api-helper", - "async-trait", - "chirp-client", - "chrono", - "cloud-game-token-create", - "cloud-namespace-token-public-create", - "faker-build", - "faker-game", - "faker-game-namespace", - "faker-game-version", - "faker-region", - "futures-util", - "game-get", - "game-namespace-get", - "game-user-get", - "http 0.2.12", - "hyper", - "lazy_static", - "mm-lobby-get", - "module-game-version-get", - "module-instance-call", - "module-ns-instance-get", - "prost 0.10.4", - "rand", - "regex", - "region-get", - "reqwest", - "rivet-api", - "rivet-cache", - "rivet-claims", - "rivet-connection", - "rivet-convert", - "rivet-health-checks", - "rivet-operation", - "rivet-pools", - "rivet-util-mm", - "serde", - "serde_json", - "thiserror", - "token-create", - "token-revoke", - "tokio", - "tracing", - "tracing-subscriber", - "url", - "urlencoding", - "user-get", - "user-identity-get", - "user-team-list", - "uuid", -] - [[package]] name = "api-monolith" version = "0.0.1" @@ -765,7 +709,6 @@ dependencies = [ "api-job", "api-kv", "api-matchmaker", - "api-module", "api-portal", "api-status", "async-trait", @@ -2311,7 +2254,6 @@ dependencies = [ "identity-config-version-get", "kv-config-version-get", "mm-config-version-get", - "module-game-version-get", "prost 0.10.4", "rivet-operation", "rivet-util-mm", @@ -2337,8 +2279,6 @@ dependencies = [ "kv-config-version-publish", "mm-config-version-prepare", "mm-config-version-publish", - "module-game-version-prepare", - "module-game-version-publish", "prost 0.10.4", "region-list", "rivet-operation", @@ -4045,7 +3985,6 @@ dependencies = [ "game-version-get", "game-version-list", "mm-config-game-get", - "module-version-get", "prost 0.10.4", "region-get", "rivet-operation", @@ -5795,133 +5734,6 @@ dependencies = [ "user-identity-create", ] -[[package]] -name = "module-game-version-get" -version = "0.0.1" -dependencies = [ - "chirp-client", - "chirp-worker", - "faker-game", - "faker-game-version", - "prost 0.10.4", - "rivet-operation", - "sqlx", -] - -[[package]] -name = "module-game-version-prepare" -version = "0.0.1" -dependencies = [ - "chirp-client", - "chirp-worker", - "faker-game", - "prost 0.10.4", - "rivet-operation", -] - -[[package]] -name = "module-game-version-publish" -version = "0.0.1" -dependencies = [ - "chirp-client", - "chirp-worker", - "faker-game", - "itertools 0.10.5", - "module-game-version-get", - "prost 0.10.4", - "rivet-operation", - "sqlx", -] - -[[package]] -name = "module-get" -version = "0.0.1" -dependencies = [ - "chirp-client", - "chirp-worker", - "prost 0.10.4", - "rand", - "rivet-operation", - "sqlx", -] - -[[package]] -name = "module-instance-call" -version = "0.0.1" -dependencies = [ - "chirp-client", - "chirp-worker", - "module-instance-get", - "module-version-get", - "prost 0.10.4", - "rand", - "reqwest", - "rivet-operation", - "serde", - "sqlx", -] - -[[package]] -name = "module-instance-get" -version = "0.0.1" -dependencies = [ - "chirp-client", - "chirp-worker", - "prost 0.10.4", - "rand", - "rivet-operation", - "sqlx", -] - -[[package]] -name = "module-ns-instance-get" -version = "0.0.1" -dependencies = [ - "chirp-client", - "chirp-worker", - "prost 0.10.4", - "rand", - "rivet-operation", - "sqlx", -] - -[[package]] -name = "module-version-get" -version = "0.0.1" -dependencies = [ - "chirp-client", - "chirp-worker", - "module-get", - "prost 0.10.4", - "rand", - "rivet-operation", - "sqlx", -] - -[[package]] -name = "module-worker" -version = "0.0.1" -dependencies = [ - "chirp-client", - "chirp-worker", - "chrono", - "faker-game", - "faker-game-version", - "module-game-version-get", - "module-instance-get", - "module-version-get", - "reqwest", - "rivet-convert", - "rivet-health-checks", - "rivet-metrics", - "rivet-runtime", - "rivet-util-module", - "serde", - "sqlx", - "upload-get", - "upload-prepare", -] - [[package]] name = "monolith-worker" version = "0.0.1" @@ -5938,7 +5750,6 @@ dependencies = [ "kv-worker", "linode-worker", "mm-worker", - "module-worker", "rivet-connection", "rivet-health-checks", "rivet-metrics", @@ -7607,14 +7418,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "rivet-util-module" -version = "0.1.0" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "rivet-util-nsfw" version = "0.1.0" diff --git a/svc/Cargo.toml b/svc/Cargo.toml index d7d1e8705e..8cf0d285fa 100644 --- a/svc/Cargo.toml +++ b/svc/Cargo.toml @@ -13,7 +13,6 @@ members = [ "api/job", "api/kv", "api/matchmaker", - "api/module", "api/monolith", "api/portal", "api/provision", @@ -189,15 +188,6 @@ members = [ "pkg/mm/ops/player-get", "pkg/mm/standalone/gc", "pkg/mm/worker", - "pkg/module/ops/game-version-get", - "pkg/module/ops/game-version-prepare", - "pkg/module/ops/game-version-publish", - "pkg/module/ops/get", - "pkg/module/ops/instance-call", - "pkg/module/ops/instance-get", - "pkg/module/ops/ns-instance-get", - "pkg/module/ops/version-get", - "pkg/module/worker", "pkg/monolith/standalone/worker", "pkg/nomad/standalone/monitor", "pkg/nsfw/ops/image-score", diff --git a/svc/api/cloud/src/route/games/mod.rs b/svc/api/cloud/src/route/games/mod.rs index 129d3848a1..7dffac4361 100644 --- a/svc/api/cloud/src/route/games/mod.rs +++ b/svc/api/cloud/src/route/games/mod.rs @@ -206,9 +206,6 @@ async fn gen_default_version_config( custom_display_names: Vec::new(), custom_avatars: Vec::new(), }), - module: Some(backend::module::GameVersionConfig { - dependencies: Vec::new(), - }), }) } diff --git a/svc/api/module/Cargo.toml b/svc/api/module/Cargo.toml deleted file mode 100644 index 67644b4d93..0000000000 --- a/svc/api/module/Cargo.toml +++ /dev/null @@ -1,67 +0,0 @@ -[package] -name = "api-module" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -rivet-convert = { path = "../../../lib/convert" } -api-helper = { path = "../../../lib/api-helper/build" } -async-trait = "0.1" -chirp-client = { path = "../../../lib/chirp/client" } -rivet-operation = { path = "../../../lib/operation/core" } -chrono = "0.4" -futures-util = "0.3" -http = "0.2" -hyper = { version = "0.14", features = ["server", "http1", "stream", "tcp"] } -lazy_static = "1.4" -prost = "0.10" -regex = "1.5" -rivet-cache = { path = "../../../lib/cache/build" } -rivet-claims = { path = "../../../lib/claims" } -rivet-health-checks = { path = "../../../lib/health-checks" } -rivet-api = { path = "../../../sdks/full/rust" } -rivet-pools = { path = "../../../lib/pools" } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -thiserror = "1.0" -tokio = { version = "1.29" } -tracing = "0.1" -tracing-subscriber = { version = "0.3", default-features = false, features = [ - "fmt", - "json", - "ansi", -] } -url = "2.2.2" -urlencoding = "2.1.0" -uuid = { version = "1", features = ["v4"] } -reqwest = "0.11" - -game-get = { path = "../../pkg/game/ops/get" } -game-namespace-get = { path = "../../pkg/game/ops/namespace-get" } -game-user-get = { path = "../../pkg/game-user/ops/get" } -mm-lobby-get = { path = "../../pkg/mm/ops/lobby-get" } -module-game-version-get = { path = "../../pkg/module/ops/game-version-get" } -module-instance-call = { path = "../../pkg/module/ops/instance-call" } -module-ns-instance-get = { path = "../../pkg/module/ops/ns-instance-get" } -token-revoke = { path = "../../pkg/token/ops/revoke" } -user-get = { path = "../../pkg/user/ops/get" } -user-identity-get = { path = "../../pkg/user-identity/ops/get" } -user-team-list = { path = "../../pkg/user/ops/team-list" } - -[dev-dependencies] -rivet-connection = { path = "../../../lib/connection" } -util-mm = { package = "rivet-util-mm", path = "../../pkg/mm/util" } -rand = "0.8" -reqwest = "0.11" - -cloud-game-token-create = { path = "../../pkg/cloud/ops/game-token-create" } -faker-build = { path = "../../pkg/faker/ops/build" } -faker-game = { path = "../../pkg/faker/ops/game" } -faker-game-namespace = { path = "../../pkg/faker/ops/game-namespace" } -faker-game-version = { path = "../../pkg/faker/ops/game-version" } -faker-region = { path = "../../pkg/faker/ops/region" } -region-get = { path = "../../pkg/region/ops/get" } -token-create = { path = "../../pkg/token/ops/create" } -cloud-namespace-token-public-create = { path = "../../pkg/cloud/ops/namespace-token-public-create" } diff --git a/svc/api/module/Service.toml b/svc/api/module/Service.toml deleted file mode 100644 index 008545dbaf..0000000000 --- a/svc/api/module/Service.toml +++ /dev/null @@ -1,8 +0,0 @@ -[service] -name = "api-module" - -[runtime] -kind = "rust" - -[api-routes] - diff --git a/svc/api/module/src/assert.rs b/svc/api/module/src/assert.rs deleted file mode 100644 index 25847c4138..0000000000 --- a/svc/api/module/src/assert.rs +++ /dev/null @@ -1,15 +0,0 @@ -use rivet_operation::prelude::*; - -/// Validates that a given user ID is registered. -pub async fn user_registered(ctx: &OperationContext<()>, user_id: Uuid) -> GlobalResult<()> { - // If the user has at least one identity they are considered registered - let identity = op!([ctx] user_identity_get { - user_ids: vec![user_id.into()] - }) - .await?; - - let identities = &unwrap_ref!(identity.users.first()).identities; - ensure_with!(!identities.is_empty(), IDENTITY_NOT_REGISTERED); - - Ok(()) -} diff --git a/svc/api/module/src/auth.rs b/svc/api/module/src/auth.rs deleted file mode 100644 index 5305044f0d..0000000000 --- a/svc/api/module/src/auth.rs +++ /dev/null @@ -1,209 +0,0 @@ -use api_helper::{ - auth::{ApiAuth, AuthRateLimitCtx}, - util::{as_auth_expired, basic_rate_limit}, -}; -use proto::claims::Claims; -use rivet_claims::ClaimsDecode; -use rivet_operation::prelude::*; - -use crate::{assert, utils}; - -/// Information derived from the authentication middleware. -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?; - - Ok(Auth { - claims: if let Some(api_token) = api_token { - Some(as_auth_expired(rivet_claims::decode(&api_token)?)?) - } else { - None - }, - }) - } - - async fn rate_limit(rate_limit_ctx: AuthRateLimitCtx<'_>) -> GlobalResult<()> { - basic_rate_limit(rate_limit_ctx).await - } -} - -impl Auth { - pub fn claims(&self) -> Result<&Claims, GlobalError> { - self.claims - .as_ref() - .ok_or_else(|| err_code!(API_UNAUTHORIZED)) - } - - pub async fn user(&self, ctx: &OperationContext<()>) -> GlobalResult { - let claims = self.claims()?; - let user_ent = claims.as_user()?; - - let user_res = op!([ctx] user_get { - user_ids: vec![user_ent.user_id.into()], - }) - .await?; - let user = unwrap!(user_res.users.first()); - - // Verify user is not deleted - if user.delete_complete_ts.is_some() { - let jti = unwrap!(claims.jti); - op!([ctx] token_revoke { - jtis: vec![jti], - }) - .await?; - - bail_with!(TOKEN_REVOKED); - } - - Ok(user_ent) - } - - pub fn namespace_public(&self) -> Result { - self.claims()?.as_game_namespace_public() - } - - pub fn game_ns_dev_option( - &self, - ) -> Result, GlobalError> { - if let Some(claims) = &self.claims { - Ok(claims.as_game_namespace_development_option()?) - } else { - Ok(None) - } - } - - /// Validates that the agent can write to a given game. - pub async fn namespace( - &self, - ctx: &OperationContext<()>, - namespace_id: Option, - ) -> GlobalResult { - if let Some(namespace_id) = namespace_id { - self.namespace_from_cloud(ctx, namespace_id).await - } else if let Some(x) = self.game_ns_dev_option()? { - Ok(x.namespace_id) - } else { - self.namespace_from_user_or_lobby(ctx).await - } - } - - /// Validates that the agent can write to a given game. - pub async fn namespace_from_user_or_lobby( - &self, - ctx: &OperationContext<()>, - ) -> GlobalResult { - let claims = self.claims()?; - let namespace_id = if let Some(ns_ent) = claims.as_game_namespace_public_option()? { - ns_ent.namespace_id - } else if let Some(lobby_ent) = claims.as_matchmaker_lobby_option()? { - let lobbies_res = op!([ctx] mm_lobby_get { - lobby_ids: vec![lobby_ent.lobby_id.into()], - include_stopped: false, - }) - .await?; - - let lobby = unwrap!(lobbies_res.lobbies.first()); - - unwrap_ref!(lobby.namespace_id).as_uuid() - } else if let Some(game_user_ent) = claims.as_game_user_option()? { - let game_users_res = op!([ctx] game_user_get { - game_user_ids: vec![game_user_ent.game_user_id.into()], - }) - .await?; - let game_user = unwrap!(game_users_res.game_users.first()); - - // Verify that game user is not deleted - if game_user.deleted_ts.is_some() { - let jti = unwrap!(claims.jti); - op!([ctx] token_revoke { - jtis: vec![jti], - }) - .await?; - - bail_with!(TOKEN_REVOKED); - } - - unwrap_ref!(game_user.namespace_id).as_uuid() - } else { - bail_with!(API_UNAUTHORIZED) - }; - - utils::validate_config(ctx, namespace_id).await?; - - Ok(namespace_id) - } - - /// Validates that the agent can write to a given game. - pub async fn namespace_from_cloud( - &self, - ctx: &OperationContext<()>, - namespace_id: Uuid, - ) -> GlobalResult { - let claims = self.claims()?; - - // Pre-fetch entitlements so we don't fetch the namespace if there is no ent - let (user_ent, cloud_ent) = if let Ok(ent) = self.user(ctx).await { - (Some(ent), None) - } else if let Ok(ent) = claims.as_game_cloud() { - (None, Some(ent)) - } else { - bail_with!(API_UNAUTHORIZED); - }; - - let namespaces_res = op!([ctx] game_namespace_get { - namespace_ids: vec![namespace_id.into()], - }) - .await?; - let namespace = unwrap!(namespaces_res.namespaces.first()); - let game_id = unwrap_ref!(namespace.game_id); - - if let Some(user_ent) = user_ent { - assert::user_registered(ctx, user_ent.user_id).await?; - - // Find the game's development team - let dev_team_id = { - let games_res = op!([ctx] game_get { - game_ids: vec![*game_id], - }) - .await?; - let game = unwrap!(games_res.games.first(), "game not found"); - let dev_team_id = unwrap_ref!(game.developer_team_id); - - *dev_team_id - }; - - // Validate can write to the team - let user_team_list_res = op!([ctx] user_team_list { - user_ids: vec![user_ent.user_id.into()], - }) - .await?; - let user = unwrap!(user_team_list_res.users.first()); - - let has_team = user - .teams - .iter() - .any(|t| t.team_id.as_ref() == Some(&dev_team_id)); - - ensure_with!(has_team, GROUP_NOT_MEMBER); - } else if let Some(cloud_ent) = cloud_ent { - ensure_eq_with!( - cloud_ent.game_id, - game_id.as_uuid(), - API_FORBIDDEN, - reason = "Game cloud token cannot write to this game", - ); - } - - utils::validate_config(ctx, namespace_id).await?; - - Ok(namespace_id) - } -} diff --git a/svc/api/module/src/lib.rs b/svc/api/module/src/lib.rs deleted file mode 100644 index 309c8f56dc..0000000000 --- a/svc/api/module/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod assert; -pub mod auth; -pub mod route; -pub mod utils; diff --git a/svc/api/module/src/main.rs b/svc/api/module/src/main.rs deleted file mode 100644 index 27d22c5818..0000000000 --- a/svc/api/module/src/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -use api_helper::start; - -fn main() { - start(api_module::route::handle); -} diff --git a/svc/api/module/src/route/mod.rs b/svc/api/module/src/route/mod.rs deleted file mode 100644 index e839e160df..0000000000 --- a/svc/api/module/src/route/mod.rs +++ /dev/null @@ -1,27 +0,0 @@ -use api_helper::{define_router, util::CorsConfigBuilder}; -use hyper::{Body, Request, Response}; -use rivet_api::models; - -mod modules; - -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! { - cors: CorsConfigBuilder::public().build(), - routes: { - "modules" / String / "scripts" / String / "call": { - POST: modules::script_call(body: models::ModuleCallRequest), - }, - }, -} diff --git a/svc/api/module/src/route/modules.rs b/svc/api/module/src/route/modules.rs deleted file mode 100644 index bccd295b9b..0000000000 --- a/svc/api/module/src/route/modules.rs +++ /dev/null @@ -1,39 +0,0 @@ -use api_helper::ctx::Ctx; -use rivet_api::models; -use rivet_operation::prelude::*; - -use crate::auth::Auth; - -// MARK: POST /modules/{}/scripts/{}/call -pub async fn script_call( - ctx: Ctx, - module: String, - func: String, - body: models::ModuleCallRequest, -) -> GlobalResult { - let namespace_id = ctx - .auth() - .namespace(ctx.op_ctx(), body.namespace_id) - .await?; - - // Get the associated instance ID - let instance_res = op!([ctx] module_ns_instance_get { - namespace_id: Some(namespace_id.into()), - key: module.clone(), - }) - .await?; - let Some(instance) = instance_res.instance else { - bail_with!(MODULE_KEY_NOT_FOUND, key = module); - }; - - // Get the module - let res = op!([ctx] module_instance_call { - instance_id: instance.instance_id, - script_name: func, - request_json: serde_json::to_string(&body.data)?, - }) - .await?; - let data = serde_json::from_str(&res.response_json)?; - - Ok(models::ModuleCallResponse { data }) -} diff --git a/svc/api/module/src/utils.rs b/svc/api/module/src/utils.rs deleted file mode 100644 index 5b5a56b0b8..0000000000 --- a/svc/api/module/src/utils.rs +++ /dev/null @@ -1,24 +0,0 @@ -use rivet_operation::prelude::*; - -pub async fn validate_config(ctx: &OperationContext<()>, namespace_id: Uuid) -> GlobalResult<()> { - let namespaces_res = op!([ctx] game_namespace_get { - namespace_ids: vec![namespace_id.into()], - }) - .await?; - let namespace = unwrap!(namespaces_res.namespaces.first()); - - let version_id = unwrap_ref!(namespace.version_id); - let config_res = op!([ctx] module_game_version_get { - version_ids: vec![*version_id], - }) - .await?; - - if config_res.versions.first().is_none() { - bail_with!( - API_FORBIDDEN, - reason = "modulesfnot enabled for this namespace" - ); - } - - Ok(()) -} diff --git a/svc/api/module/tests/basic.rs b/svc/api/module/tests/basic.rs deleted file mode 100644 index 1b04d2d6d1..0000000000 --- a/svc/api/module/tests/basic.rs +++ /dev/null @@ -1,346 +0,0 @@ -// TODO: Modules were removed - -// use proto::backend::{self, pkg::*}; -// use rivet_operation::prelude::*; -// use serde_json::json; -// use std::{str::FromStr, sync::Once}; - -// use rivet_api::{ -// apis::{configuration::Configuration, *}, -// models, -// }; - -// const LOBBY_GROUP_NAME_ID: &str = "test"; - -// static GLOBAL_INIT: Once = Once::new(); - -// struct Ctx { -// op_ctx: OperationContext<()>, -// game_id: Uuid, -// primary_region_id: Uuid, -// namespace_id: Uuid, -// mm_config_meta: backend::matchmaker::VersionConfigMeta, -// } - -// 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-module-test").await.unwrap(); -// let cache = rivet_cache::CacheInner::new( -// "api-module-test".to_string(), -// std::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-module-test"); -// let conn = rivet_connection::Connection::new(client, pools, cache); -// let op_ctx = OperationContext::new( -// "api-module-test".to_string(), -// std::time::Duration::from_secs(60), -// conn, -// Uuid::new_v4(), -// Uuid::new_v4(), -// util::timestamp::now(), -// util::timestamp::now(), -// (), -// Vec::new(), -// ); - -// let (primary_region_id, _) = Self::setup_region(&op_ctx).await; -// let (_, module_version_id) = Self::setup_module(&op_ctx).await; -// let (game_id, _, namespace_id, _, mm_config_meta) = -// Self::setup_game(&op_ctx, primary_region_id, module_version_id).await; - -// Ctx { -// op_ctx, -// game_id, -// primary_region_id, -// namespace_id, -// mm_config_meta, -// } -// } - -// fn config(&self, bearer_token: &str) -> Configuration { -// Configuration { -// base_path: "http://traefik.traefik.svc.cluster.local:80".into(), -// bearer_access_token: Some(bearer_token.to_string()), -// ..Default::default() -// } -// } - -// async fn issue_ns_token(&self) -> String { -// let token_res = op!([self.op_ctx] cloud_namespace_token_public_create { -// namespace_id: Some(self.namespace_id.into()), -// }) -// .await -// .unwrap(); - -// token_res.token -// } - -// async fn issue_lobby_token(&self) -> String { -// // Create lobby -// let lobby_group_meta = &self.mm_config_meta.lobby_groups[0]; -// let lobby_id = Uuid::new_v4(); - -// msg!([self.op_ctx] mm::msg::lobby_create(lobby_id) -> mm::msg::lobby_create_complete { -// lobby_id: Some(lobby_id.into()), -// namespace_id: Some(self.namespace_id.into()), -// lobby_group_id: lobby_group_meta.lobby_group_id, -// region_id: Some(self.primary_region_id.into()), -// create_ray_id: None, -// preemptively_created: false, -// ..Default::default() -// }) -// .await -// .unwrap(); - -// lobby_token(&self.op_ctx, lobby_id.to_string().as_str()).await -// } - -// async fn issue_cloud_token(&self) -> String { -// let res = op!([self.op_ctx] cloud_game_token_create { -// game_id: Some(self.game_id.into()), -// }) -// .await -// .unwrap(); - -// res.token -// } - -// async fn setup_region(ctx: &OperationContext<()>) -> (Uuid, String) { -// tracing::info!("setup region"); - -// let region_res = op!([ctx] faker_region {}).await.unwrap(); -// let region_id = region_res.region_id.as_ref().unwrap().as_uuid(); - -// let get_res = op!([ctx] region_get { -// region_ids: vec![region_id.into()], -// }) -// .await -// .unwrap(); -// let region_data = get_res.regions.first().unwrap(); - -// (region_id, region_data.name_id.clone()) -// } - -// async fn setup_module(ctx: &OperationContext<()>) -> (Uuid, Uuid) { -// let module_id = Uuid::new_v4(); -// let version_id = Uuid::new_v4(); - -// msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete { -// module_id: Some(module_id.into()), -// name_id: "test".into(), -// team_id: Some(Uuid::new_v4().into()), -// creator_user_id: None, -// }) -// .await -// .unwrap(); - -// msg!([ctx] module::msg::version_create(version_id) -> module::msg::version_create_complete { -// version_id: Some(version_id.into()), -// module_id: Some(module_id.into()), -// creator_user_id: None, - -// major: 1, -// minor: 0, -// patch: 0, - -// scripts: vec![ -// backend::module::Script { -// name: "foo".into(), -// request_schema: "{}".into(), -// response_schema: "{}".into(), -// callable: Some(backend::module::script::Callable {}), -// }, -// ], - -// image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { -// image_tag: "ghcr.io/rivet-gg/rivet-module-hello-world:0.0.1".into(), -// })), -// }).await.unwrap(); - -// (module_id, version_id) -// } - -// async fn setup_game( -// ctx: &OperationContext<()>, -// region_id: Uuid, -// module_version_id: Uuid, -// ) -> ( -// Uuid, -// Uuid, -// Uuid, -// backend::matchmaker::VersionConfig, -// backend::matchmaker::VersionConfigMeta, -// ) { -// let game_res = op!([ctx] faker_game { -// ..Default::default() -// }) -// .await -// .unwrap(); - -// let build_res = op!([ctx] faker_build { -// game_id: game_res.game_id, -// image: backend::faker::Image::MmLobbyAutoReady as i32, -// }) -// .await -// .unwrap(); - -// let game_version_res = op!([ctx] faker_game_version { -// game_id: game_res.game_id, -// override_cdn_config: Some(faker::game_version::request::OverrideCdnConfig { -// config: None, -// }), -// override_module_config: Some(faker::game_version::request::OverrideModuleConfig { -// config: Some(backend::module::GameVersionConfig { -// dependencies: vec![ -// backend::module::game_version_config::Dependency { -// key: "hello-world".into(), -// module_version_id: Some(module_version_id.into()), -// } -// ] -// }) -// }), -// override_lobby_groups: Some(faker::game_version::request::OverrideLobbyGroups { -// lobby_groups: vec![backend::matchmaker::LobbyGroup { -// name_id: LOBBY_GROUP_NAME_ID.into(), - -// regions: vec![backend::matchmaker::lobby_group::Region { -// region_id: Some(region_id.into()), -// tier_name_id: util_mm::test::TIER_NAME_ID.to_owned(), -// idle_lobbies: None, -// }], -// max_players_normal: 8, -// max_players_direct: 10, -// max_players_party: 12, - -// runtime: Some(backend::matchmaker::lobby_runtime::Docker { -// build_id: build_res.build_id, -// args: Vec::new(), -// env_vars: Vec::new(), -// network_mode: backend::matchmaker::lobby_runtime::NetworkMode::Bridge as i32, -// ports: vec![ -// backend::matchmaker::lobby_runtime::Port { -// label: "test-80-http".into(), -// target_port: Some(80), -// port_range: None, -// proxy_protocol: backend::matchmaker::lobby_runtime::ProxyProtocol::Http as i32, -// proxy_kind: backend::matchmaker::lobby_runtime::ProxyKind::GameGuard as i32, -// }, -// backend::matchmaker::lobby_runtime::Port { -// label: "test-80-https".into(), -// target_port: Some(80), -// port_range: None, -// proxy_protocol: backend::matchmaker::lobby_runtime::ProxyProtocol::Https as i32, -// proxy_kind: backend::matchmaker::lobby_runtime::ProxyKind::GameGuard as i32, -// }, -// backend::matchmaker::lobby_runtime::Port { -// label: "test-5050-https".into(), -// target_port: Some(5050), -// port_range: None, -// proxy_protocol: backend::matchmaker::lobby_runtime::ProxyProtocol::Https as i32, -// proxy_kind: backend::matchmaker::lobby_runtime::ProxyKind::GameGuard as i32, -// }, -// ], -// }.into()), -// ..Default::default() -// }], -// }), -// ..Default::default() -// }) -// .await -// .unwrap(); - -// let mut module_ns_version_set_complete = -// subscribe!([ctx] module::msg::ns_version_set_complete("*")) -// .await -// .unwrap(); -// let namespace_res = op!([ctx] faker_game_namespace { -// game_id: game_res.game_id, -// version_id: game_version_res.version_id, -// ..Default::default() -// }) -// .await -// .unwrap(); -// module_ns_version_set_complete.next().await.unwrap(); - -// ( -// game_res.game_id.as_ref().unwrap().as_uuid(), -// game_version_res.version_id.as_ref().unwrap().as_uuid(), -// namespace_res.namespace_id.as_ref().unwrap().as_uuid(), -// game_version_res.mm_config.clone().unwrap(), -// game_version_res.mm_config_meta.clone().unwrap(), -// ) -// } -// } - -// #[tokio::test(flavor = "multi_thread")] -// async fn call() { -// let ctx = Ctx::init().await; -// let token = ctx.issue_ns_token().await; - -// let res = module_api::module_call( -// &ctx.config(&token), -// "hello-world", -// "foo", -// models::ModuleCallRequest { -// namespace_id: None, -// data: Some(json!({ -// "x": 5 -// })), -// }, -// None, -// ) -// .await -// .unwrap(); -// assert_eq!( -// 10, -// res.data -// .unwrap() -// .as_object() -// .unwrap() -// .get("y") -// .unwrap() -// .as_i64() -// .unwrap() -// ); -// } - -// /// Issues a testing lobby token. We use this since we can't access the lobby token issued -// /// on the lobby creation. -// async fn lobby_token(ctx: &OperationContext<()>, lobby_id: &str) -> String { -// let token_res = op!([ctx] token_create { -// issuer: "test".into(), -// token_config: Some(token::create::request::TokenConfig { -// ttl: util::duration::days(365), -// }), -// refresh_token_config: None, -// client: None, -// kind: Some(token::create::request::Kind::New(token::create::request::KindNew { -// entitlements: vec![ -// proto::claims::Entitlement { -// kind: Some( -// proto::claims::entitlement::Kind::MatchmakerLobby(proto::claims::entitlement::MatchmakerLobby { -// lobby_id: Some(Uuid::from_str(lobby_id).unwrap().into()), -// }) -// ) -// } -// ], -// })), -// label: Some("lobby".into()), -// ..Default::default() -// }) -// .await -// .unwrap(); - -// token_res.token.as_ref().unwrap().token.clone() -// } diff --git a/svc/api/monolith/Cargo.toml b/svc/api/monolith/Cargo.toml index 40a107ecf3..0d8132676a 100644 --- a/svc/api/monolith/Cargo.toml +++ b/svc/api/monolith/Cargo.toml @@ -30,6 +30,5 @@ api-identity = { path = "../identity" } api-job = { path = "../job" } api-kv = { path = "../kv" } api-matchmaker = { path = "../matchmaker" } -api-module = { path = "../module" } api-portal = { path = "../portal" } api-status = { path = "../status" } diff --git a/svc/api/monolith/Service.toml b/svc/api/monolith/Service.toml index 842fb7456d..acb426ed2a 100644 --- a/svc/api/monolith/Service.toml +++ b/svc/api/monolith/Service.toml @@ -76,12 +76,6 @@ subdomain = "matchmaker.api" strip-prefix = "/v1" add-path = "/matchmaker" -[[api.router.mounts]] -deprecated = true -subdomain = "module.api" -strip-prefix = "/v1" -add-path = "/module" - [[api.router.mounts]] deprecated = true subdomain = "portal.api" diff --git a/svc/api/monolith/src/route/mod.rs b/svc/api/monolith/src/route/mod.rs index 43120f8ddf..8d5905e4c0 100644 --- a/svc/api/monolith/src/route/mod.rs +++ b/svc/api/monolith/src/route/mod.rs @@ -54,10 +54,6 @@ define_router! { path: api_matchmaker::route::Router, prefix: "matchmaker", }, - { - path: api_module::route::Router, - prefix: "module", - }, { path: api_portal::route::Router, prefix: "portal", diff --git a/svc/pkg/cloud/ops/namespace-get/src/lib.rs b/svc/pkg/cloud/ops/namespace-get/src/lib.rs index 95c74193af..12ca9cd449 100644 --- a/svc/pkg/cloud/ops/namespace-get/src/lib.rs +++ b/svc/pkg/cloud/ops/namespace-get/src/lib.rs @@ -109,7 +109,6 @@ async fn handle( tracing::warn!(namespace_id = %cloud_namespace.namespace_id, "missing identity for ns"); return None; }, - module: Some(backend::module::GameNamespaceConfig {}), }), }) }) diff --git a/svc/pkg/cloud/ops/version-get/Cargo.toml b/svc/pkg/cloud/ops/version-get/Cargo.toml index 3af0adfae2..e12f326459 100644 --- a/svc/pkg/cloud/ops/version-get/Cargo.toml +++ b/svc/pkg/cloud/ops/version-get/Cargo.toml @@ -15,7 +15,6 @@ cdn-version-get = { path = "../../../cdn/ops/version-get" } identity-config-version-get = { path = "../../../identity-config/ops/version-get" } kv-config-version-get = { path = "../../../kv-config/ops/version-get" } mm-config-version-get = { path = "../../../mm-config/ops/version-get" } -module-game-version-get = { path = "../../../module/ops/game-version-get" } [dependencies.sqlx] version = "0.7" diff --git a/svc/pkg/cloud/ops/version-get/src/lib.rs b/svc/pkg/cloud/ops/version-get/src/lib.rs index 28df04ed2a..0b8dd8b6d5 100644 --- a/svc/pkg/cloud/ops/version-get/src/lib.rs +++ b/svc/pkg/cloud/ops/version-get/src/lib.rs @@ -37,24 +37,20 @@ async fn handle( .collect::>(); // Fetch all dependent configs - let (cdn_configs_res, mm_configs_res, kv_configs_res, identity_configs_res, module_configs_res) = - tokio::try_join!( - op!([ctx] cdn_version_get { - version_ids: all_version_ids_proto.clone(), - }), - op!([ctx] mm_config_version_get { - version_ids: all_version_ids_proto.clone(), - }), - op!([ctx] kv_config_version_get { - version_ids: all_version_ids_proto.clone(), - }), - op!([ctx] identity_config_version_get { - version_ids: all_version_ids_proto.clone(), - }), - op!([ctx] module_game_version_get { - version_ids: all_version_ids_proto.clone(), - }), - )?; + let (cdn_configs_res, mm_configs_res, kv_configs_res, identity_configs_res) = tokio::try_join!( + op!([ctx] cdn_version_get { + version_ids: all_version_ids_proto.clone(), + }), + op!([ctx] mm_config_version_get { + version_ids: all_version_ids_proto.clone(), + }), + op!([ctx] kv_config_version_get { + version_ids: all_version_ids_proto.clone(), + }), + op!([ctx] identity_config_version_get { + version_ids: all_version_ids_proto.clone(), + }), + )?; let versions = cloud_versions .iter() @@ -91,13 +87,6 @@ async fn handle( identity_version.version_id.as_ref() == Some(&version_id_proto) }) .map(|v| v.config.clone().unwrap()), - module: module_configs_res - .versions - .iter() - .find(|module_version| { - module_version.version_id.as_ref() == Some(&version_id_proto) - }) - .map(|v| v.config.clone().unwrap()), }), } }) diff --git a/svc/pkg/cloud/ops/version-get/tests/integration.rs b/svc/pkg/cloud/ops/version-get/tests/integration.rs index a06f675dfa..4756801d3e 100644 --- a/svc/pkg/cloud/ops/version-get/tests/integration.rs +++ b/svc/pkg/cloud/ops/version-get/tests/integration.rs @@ -75,9 +75,6 @@ async fn empty(ctx: TestCtx) { }], custom_avatars: Vec::new(), }), - module: Some(backend::module::GameVersionConfig { - dependencies: Vec::new(), - }), }) }) .await diff --git a/svc/pkg/cloud/ops/version-publish/Cargo.toml b/svc/pkg/cloud/ops/version-publish/Cargo.toml index dde2b08b5d..a588da9d48 100644 --- a/svc/pkg/cloud/ops/version-publish/Cargo.toml +++ b/svc/pkg/cloud/ops/version-publish/Cargo.toml @@ -21,8 +21,6 @@ kv-config-version-prepare = { path = "../../../kv-config/ops/version-prepare" } kv-config-version-publish = { path = "../../../kv-config/ops/version-publish" } mm-config-version-prepare = { path = "../../../mm-config/ops/version-prepare" } mm-config-version-publish = { path = "../../../mm-config/ops/version-publish" } -module-game-version-prepare = { path = "../../../module/ops/game-version-prepare" } -module-game-version-publish = { path = "../../../module/ops/game-version-publish" } [dependencies.sqlx] version = "0.7" diff --git a/svc/pkg/cloud/ops/version-publish/src/lib.rs b/svc/pkg/cloud/ops/version-publish/src/lib.rs index 9683096d43..ddd3db0b04 100644 --- a/svc/pkg/cloud/ops/version-publish/src/lib.rs +++ b/svc/pkg/cloud/ops/version-publish/src/lib.rs @@ -81,17 +81,6 @@ async fn handle( } else { None }; - let module_config_ctx = if let Some(module_config) = &config.module { - let prepare_res = op!([ctx] module_game_version_prepare { - game_id: Some(game_id.into()), - config: Some(module_config.clone()), - }) - .await?; - - Some(unwrap_ref!(prepare_res.config_ctx).clone()) - } else { - None - }; // Create the game version let version_create_res = op!([ctx] game_version_create { @@ -147,14 +136,6 @@ async fn handle( }) .await?; } - if let (Some(module_config), Some(module_config_ctx)) = (&config.module, &module_config_ctx) { - op!([ctx] module_game_version_publish { - version_id: Some(version_id.into()), - config: Some(module_config.clone()), - config_ctx: Some((*module_config_ctx).clone()), - }) - .await?; - } // Send game update { diff --git a/svc/pkg/cloud/ops/version-publish/tests/integration.rs b/svc/pkg/cloud/ops/version-publish/tests/integration.rs index 722abc9e3e..f676b89ef7 100644 --- a/svc/pkg/cloud/ops/version-publish/tests/integration.rs +++ b/svc/pkg/cloud/ops/version-publish/tests/integration.rs @@ -82,9 +82,6 @@ async fn empty(ctx: TestCtx) { }], custom_avatars: Vec::new(), }), - module: Some(backend::module::GameVersionConfig { - dependencies: Vec::new(), - }) }) }) .await diff --git a/svc/pkg/faker/ops/game-version/src/lib.rs b/svc/pkg/faker/ops/game-version/src/lib.rs index 2fe1e5ec41..8602bd89ec 100644 --- a/svc/pkg/faker/ops/game-version/src/lib.rs +++ b/svc/pkg/faker/ops/game-version/src/lib.rs @@ -133,13 +133,6 @@ async fn handle( custom_avatars: Vec::new(), }) }, - module: if let Some(config) = ctx.override_module_config.clone() { - config.config - } else { - Some(backend::module::GameVersionConfig { - dependencies: Vec::new(), - }) - }, } }; diff --git a/svc/pkg/faker/types/game-version.proto b/svc/pkg/faker/types/game-version.proto index 0b4f9c72be..727c721a53 100644 --- a/svc/pkg/faker/types/game-version.proto +++ b/svc/pkg/faker/types/game-version.proto @@ -8,7 +8,6 @@ import "proto/backend/cdn.proto"; import "proto/backend/matchmaker.proto"; import "proto/backend/kv.proto"; import "proto/backend/identity.proto"; -import "proto/backend/module.proto"; import "proto/backend/captcha.proto"; message Request { @@ -28,10 +27,6 @@ message Request { optional rivet.backend.identity.VersionConfig config = 1; } - message OverrideModuleConfig { - optional rivet.backend.module.GameVersionConfig config = 1; - } - message OverrideLobbyGroups { repeated rivet.backend.matchmaker.LobbyGroup lobby_groups = 1; @@ -50,7 +45,6 @@ message Request { optional OverrideMatchmakerConfig override_mm_config = 102; optional OverrideKvConfig override_kv_config = 106; optional OverrideIdentityConfig override_identity_config = 107; - optional OverrideModuleConfig override_module_config = 108; optional OverrideLobbyGroups override_lobby_groups = 103; optional OverrideCaptcha override_captcha = 105; diff --git a/svc/pkg/game/ops/version-validate/Cargo.toml b/svc/pkg/game/ops/version-validate/Cargo.toml index 89928503cc..63df358c66 100644 --- a/svc/pkg/game/ops/version-validate/Cargo.toml +++ b/svc/pkg/game/ops/version-validate/Cargo.toml @@ -15,7 +15,6 @@ external-request-validate = { path = "../../../external/ops/request-validate" } game-version-get = { path = "../version-get" } game-version-list = { path = "../version-list" } mm-config-game-get = { path = "../../../mm-config/ops/game-get" } -module-version-get = { path = "../../../module/ops/version-get" } region-get = { path = "../../../region/ops/get" } tier-list = { path = "../../../tier/ops/list" } diff --git a/svc/pkg/game/ops/version-validate/src/lib.rs b/svc/pkg/game/ops/version-validate/src/lib.rs index e925349526..c910091527 100644 --- a/svc/pkg/game/ops/version-validate/src/lib.rs +++ b/svc/pkg/game/ops/version-validate/src/lib.rs @@ -1253,64 +1253,6 @@ async fn handle( // } // } - // Module config validation - if let Some(module) = &proto_config.module { - if module.dependencies.len() > 32 { - errors.push(util::err_path![ - "config", - "module", - "dependencies", - "too-many" - ]); - } - - for (i, dependency) in module.dependencies.iter().enumerate() { - let version_id = unwrap_ref!(dependency.module_version_id).as_uuid(); - - // Validate ident - if util::check::ident(&dependency.key) { - if module - .dependencies - .iter() - .enumerate() - .any(|(j, x)| i != j && dependency.key == x.key) - { - errors.push(util::err_path![ - "config", - "modules", - "dependencies", - dependency.key, - "not-unique", - ]); - } - } else { - errors.push(util::err_path![ - "config", - "module", - "dependencies", - dependency.key, - "key-invalid", - ]); - } - - // TODO: Validate the version belongs to the owner - // Validate version ID - let versions = op!([ctx] module_version_get { - version_ids: vec![version_id.into()], - }) - .await?; - if versions.versions.is_empty() { - errors.push(util::err_path![ - "config", - "module", - "dependencies", - dependency.key, - "version-not-found", - ]); - } - } - } - Ok(game::version_validate::Response { errors: errors .into_iter() diff --git a/svc/pkg/game/ops/version-validate/tests/integration.rs b/svc/pkg/game/ops/version-validate/tests/integration.rs index ba7b8da8f0..1694e367e5 100644 --- a/svc/pkg/game/ops/version-validate/tests/integration.rs +++ b/svc/pkg/game/ops/version-validate/tests/integration.rs @@ -181,10 +181,6 @@ async fn empty(ctx: TestCtx) { }], custom_avatars: Vec::new(), }), - module: Some(backend::module::GameVersionConfig { - dependencies: Vec::new(), - ..Default::default() - }), }), }) .await diff --git a/svc/pkg/module/db/module/Service.toml b/svc/pkg/module/db/module/Service.toml deleted file mode 100644 index 1873972a48..0000000000 --- a/svc/pkg/module/db/module/Service.toml +++ /dev/null @@ -1,7 +0,0 @@ -[service] -name = "db-module" - -[runtime] -kind = "crdb" - -[database] diff --git a/svc/pkg/module/db/module/migrations/20200101000000_init.down.sql b/svc/pkg/module/db/module/migrations/20200101000000_init.down.sql deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/svc/pkg/module/db/module/migrations/20200101000000_init.up.sql b/svc/pkg/module/db/module/migrations/20200101000000_init.up.sql deleted file mode 100644 index 732f18d077..0000000000 --- a/svc/pkg/module/db/module/migrations/20200101000000_init.up.sql +++ /dev/null @@ -1,77 +0,0 @@ --- Modules -CREATE TABLE modules ( - module_id UUID PRIMARY KEY, - name_id STRING NOT NULL, - team_id UUID NOT NULL, -- References db-team.teams - create_ts INT NOT NULL, - creator_user_id UUID, -- References db-user.users - publicity INT NOT NULL DEFAULT 0, - UNIQUE INDEX (team_id, name_id ASC) -); - --- Version -CREATE TABLE versions ( - version_id UUID PRIMARY KEY, - module_id UUID NOT NULL REFERENCES modules (module_id), - create_ts INT NOT NULL, - creator_user_id UUID, -- References db-user.users - - major INT NOT NULL, - minor INT NOT NULL, - patch INT NOT NULL, - - INDEX (module_id, create_ts ASC), - INDEX (module_id, major ASC, minor ASC, patch ASC) -); - -CREATE TABLE versions_image_docker ( - version_id UUID PRIMARY KEY REFERENCES versions (version_id), - image_tag STRING NOT NULL -); - --- Scripts -CREATE TABLE scripts ( - version_id UUID NOT NULL REFERENCES versions (version_id), - name STRING NOT NULL, - request_schema STRING NOT NULL, - response_schema STRING NOT NULL, - PRIMARY KEY (version_id, name) -); - -CREATE TABLE scripts_callable ( - version_id UUID NOT NULL REFERENCES versions (version_id), - name STRING NOT NULL, - PRIMARY KEY (version_id, name), - FOREIGN KEY (version_id, name) REFERENCES scripts (version_id, name) -); - --- Instance -CREATE TABLE instances ( - instance_id UUID PRIMARY KEY, - version_id UUID NOT NULL REFERENCES versions (version_id), - create_ts INT NOT NULL, - destroy_ts INT -); - -CREATE TABLE instances_driver_dummy ( - instance_id UUID PRIMARY KEY REFERENCES instances (instance_id) -); - -CREATE TABLE instances_driver_fly ( - instance_id UUID PRIMARY KEY REFERENCES instances (instance_id), - fly_app_id STRING -); - -CREATE TABLE namespace_instances ( - namespace_id UUID NOT NULL, -- References db-namespace.namespaces - key STRING NOT NULL, - instance_id UUID NOT NULL REFERENCES instances (instance_id), - PRIMARY KEY (namespace_id, key) -); - --- Game version -CREATE TABLE game_versions ( - version_id UUID PRIMARY KEY, -- References db-game.versions - config BYTES NOT NULL -); - diff --git a/svc/pkg/module/ops/game-version-get/Cargo.toml b/svc/pkg/module/ops/game-version-get/Cargo.toml deleted file mode 100644 index e4dc35e869..0000000000 --- a/svc/pkg/module/ops/game-version-get/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "module-game-version-get" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -rivet-operation = { path = "../../../../../lib/operation/core" } -chirp-client = { path = "../../../../../lib/chirp/client" } -prost = "0.10" - -[dependencies.sqlx] -version = "0.7" -default-features = false - -[dev-dependencies] -chirp-worker = { path = "../../../../../lib/chirp/worker" } - -faker-game = { path = "../../../faker/ops/game" } -faker-game-version = { path = "../../../faker/ops/game-version" } diff --git a/svc/pkg/module/ops/game-version-get/README.md b/svc/pkg/module/ops/game-version-get/README.md deleted file mode 100644 index 1a97187e6a..0000000000 --- a/svc/pkg/module/ops/game-version-get/README.md +++ /dev/null @@ -1 +0,0 @@ -# module-game-version-get diff --git a/svc/pkg/module/ops/game-version-get/Service.toml b/svc/pkg/module/ops/game-version-get/Service.toml deleted file mode 100644 index aa5bd904d7..0000000000 --- a/svc/pkg/module/ops/game-version-get/Service.toml +++ /dev/null @@ -1,10 +0,0 @@ -[service] -name = "module-game-version-get" - -[runtime] -kind = "rust" - -[operation] - -[databases] -db-module = {} diff --git a/svc/pkg/module/ops/game-version-get/src/lib.rs b/svc/pkg/module/ops/game-version-get/src/lib.rs deleted file mode 100644 index 3df9050792..0000000000 --- a/svc/pkg/module/ops/game-version-get/src/lib.rs +++ /dev/null @@ -1,42 +0,0 @@ -use proto::backend::{self, pkg::*}; -use rivet_operation::prelude::*; - -#[derive(sqlx::FromRow)] -struct GameVersion { - version_id: Uuid, - config: Vec, -} - -#[operation(name = "module-game-version-get")] -async fn handle( - ctx: OperationContext, -) -> GlobalResult { - let version_ids = ctx - .version_ids - .iter() - .map(common::Uuid::as_uuid) - .collect::>(); - - let versions = sql_fetch_all!( - [ctx, GameVersion] - " - SELECT version_id, config - FROM db_module.game_versions - WHERE version_id = ANY($1) - ", - &version_ids, - ) - .await? - .into_iter() - .map(|x| -> GlobalResult<_> { - let config = backend::module::GameVersionConfig::decode(x.config.as_slice())?; - Ok(module::game_version_get::response::Version { - version_id: Some(x.version_id.into()), - config: Some(config), - config_meta: Some(backend::module::GameVersionConfigMeta {}), - }) - }) - .collect::>()?; - - Ok(module::game_version_get::Response { versions }) -} diff --git a/svc/pkg/module/ops/game-version-get/tests/integration.rs b/svc/pkg/module/ops/game-version-get/tests/integration.rs deleted file mode 100644 index 80c1edf7ad..0000000000 --- a/svc/pkg/module/ops/game-version-get/tests/integration.rs +++ /dev/null @@ -1,25 +0,0 @@ -use chirp_worker::prelude::*; - -#[worker_test] -async fn empty(ctx: TestCtx) { - let game_res = op!([ctx] faker_game { - ..Default::default() - }) - .await - .unwrap(); - - let game_version_res = op!([ctx] faker_game_version { - game_id: game_res.game_id, - ..Default::default() - }) - .await - .unwrap(); - - let res = op!([ctx] module_game_version_get { - version_ids: vec![game_version_res.version_id.unwrap()] - }) - .await - .unwrap(); - - res.versions.first().expect("version not found"); -} diff --git a/svc/pkg/module/ops/game-version-prepare/Cargo.toml b/svc/pkg/module/ops/game-version-prepare/Cargo.toml deleted file mode 100644 index 78862789c0..0000000000 --- a/svc/pkg/module/ops/game-version-prepare/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "module-game-version-prepare" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -rivet-operation = { path = "../../../../../lib/operation/core" } -chirp-client = { path = "../../../../../lib/chirp/client" } -prost = "0.10" - -[dev-dependencies] -chirp-worker = { path = "../../../../../lib/chirp/worker" } -faker-game = { path = "../../../faker/ops/game" } diff --git a/svc/pkg/module/ops/game-version-prepare/README.md b/svc/pkg/module/ops/game-version-prepare/README.md deleted file mode 100644 index d224588905..0000000000 --- a/svc/pkg/module/ops/game-version-prepare/README.md +++ /dev/null @@ -1 +0,0 @@ -# module-game-version-prepare diff --git a/svc/pkg/module/ops/game-version-prepare/Service.toml b/svc/pkg/module/ops/game-version-prepare/Service.toml deleted file mode 100644 index 03041d5938..0000000000 --- a/svc/pkg/module/ops/game-version-prepare/Service.toml +++ /dev/null @@ -1,7 +0,0 @@ -[service] -name = "module-game-version-prepare" - -[runtime] -kind = "rust" - -[operation] diff --git a/svc/pkg/module/ops/game-version-prepare/src/lib.rs b/svc/pkg/module/ops/game-version-prepare/src/lib.rs deleted file mode 100644 index dc010b2da6..0000000000 --- a/svc/pkg/module/ops/game-version-prepare/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -use proto::backend::{self, pkg::*}; -use rivet_operation::prelude::*; - -#[operation(name = "module-game-version-prepare")] -async fn handle( - _ctx: OperationContext, -) -> GlobalResult { - Ok(module::game_version_prepare::Response { - config_ctx: Some(backend::module::GameVersionConfigCtx {}), - }) -} diff --git a/svc/pkg/module/ops/game-version-prepare/tests/integration.rs b/svc/pkg/module/ops/game-version-prepare/tests/integration.rs deleted file mode 100644 index f8f4917d76..0000000000 --- a/svc/pkg/module/ops/game-version-prepare/tests/integration.rs +++ /dev/null @@ -1,21 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend; - -#[worker_test] -async fn empty(ctx: TestCtx) { - let game_res = op!([ctx] faker_game { - ..Default::default() - }) - .await - .unwrap(); - let game_id = game_res.game_id.unwrap(); - - let _res = op!([ctx] module_game_version_prepare { - config: Some(backend::module::GameVersionConfig { - dependencies: Vec::new(), - }), - game_id: Some(game_id), - }) - .await - .unwrap(); -} diff --git a/svc/pkg/module/ops/game-version-publish/Cargo.toml b/svc/pkg/module/ops/game-version-publish/Cargo.toml deleted file mode 100644 index 4424e8623b..0000000000 --- a/svc/pkg/module/ops/game-version-publish/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "module-game-version-publish" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -rivet-operation = { path = "../../../../../lib/operation/core" } -chirp-client = { path = "../../../../../lib/chirp/client" } -prost = "0.10" -itertools = "0.10.5" - -[dependencies.sqlx] -version = "0.7" -default-features = false - -[dev-dependencies] -chirp-worker = { path = "../../../../../lib/chirp/worker" } -module-game-version-get = { path = "../game-version-get" } -faker-game = { path = "../../../faker/ops/game" } diff --git a/svc/pkg/module/ops/game-version-publish/README.md b/svc/pkg/module/ops/game-version-publish/README.md deleted file mode 100644 index f02e0e71fe..0000000000 --- a/svc/pkg/module/ops/game-version-publish/README.md +++ /dev/null @@ -1 +0,0 @@ -# module-game-version-publish diff --git a/svc/pkg/module/ops/game-version-publish/Service.toml b/svc/pkg/module/ops/game-version-publish/Service.toml deleted file mode 100644 index c577438934..0000000000 --- a/svc/pkg/module/ops/game-version-publish/Service.toml +++ /dev/null @@ -1,10 +0,0 @@ -[service] -name = "module-game-version-publish" - -[runtime] -kind = "rust" - -[operation] - -[databases] -db-module = {} diff --git a/svc/pkg/module/ops/game-version-publish/src/lib.rs b/svc/pkg/module/ops/game-version-publish/src/lib.rs deleted file mode 100644 index c8c536df20..0000000000 --- a/svc/pkg/module/ops/game-version-publish/src/lib.rs +++ /dev/null @@ -1,23 +0,0 @@ -use proto::backend::pkg::*; -use rivet_operation::prelude::*; - -#[operation(name = "module-game-version-publish")] -async fn handle( - ctx: OperationContext, -) -> GlobalResult { - let version_id = unwrap_ref!(ctx.version_id).as_uuid(); - let config = unwrap_ref!(ctx.config); - - let mut config_buf = Vec::with_capacity(config.encoded_len()); - config.encode(&mut config_buf)?; - - sql_execute!( - [ctx] - "INSERT INTO db_module.game_versions (version_id, config) VALUES ($1, $2)", - version_id, - config_buf, - ) - .await?; - - Ok(module::game_version_publish::Response {}) -} diff --git a/svc/pkg/module/ops/game-version-publish/tests/integration.rs b/svc/pkg/module/ops/game-version-publish/tests/integration.rs deleted file mode 100644 index 60fda82ca8..0000000000 --- a/svc/pkg/module/ops/game-version-publish/tests/integration.rs +++ /dev/null @@ -1,30 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::{self}; - -#[worker_test] -async fn empty(ctx: TestCtx) { - let _game_res = op!([ctx] faker_game { - ..Default::default() - }) - .await - .unwrap(); - - let version_id = Into::::into(Uuid::new_v4()); - - op!([ctx] module_game_version_publish { - version_id: Some(version_id), - config: Some(backend::module::GameVersionConfig { - dependencies: Vec::new() - }), - config_ctx: Some(backend::module::GameVersionConfigCtx {}), - }) - .await - .unwrap(); - - let res = op!([ctx] module_game_version_get { - version_ids: vec![version_id] - }) - .await - .unwrap(); - let _version = res.versions.first().expect("version not found"); -} diff --git a/svc/pkg/module/ops/get/Cargo.toml b/svc/pkg/module/ops/get/Cargo.toml deleted file mode 100644 index a2a6d2dea6..0000000000 --- a/svc/pkg/module/ops/get/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "module-get" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -chirp-client = { path = "../../../../../lib/chirp/client" } -prost = "0.10" -rivet-operation = { path = "../../../../../lib/operation/core" } - -[dependencies.sqlx] -version = "0.7" -default-features = false - -[dev-dependencies] -chirp-worker = { path = "../../../../../lib/chirp/worker" } -rand = "0.8" diff --git a/svc/pkg/module/ops/get/Service.toml b/svc/pkg/module/ops/get/Service.toml deleted file mode 100644 index 5c76b26208..0000000000 --- a/svc/pkg/module/ops/get/Service.toml +++ /dev/null @@ -1,10 +0,0 @@ -[service] -name = "module-get" - -[runtime] -kind = "rust" - -[operation] - -[databases] -db-module = {} diff --git a/svc/pkg/module/ops/get/src/lib.rs b/svc/pkg/module/ops/get/src/lib.rs deleted file mode 100644 index 4b0c74fdec..0000000000 --- a/svc/pkg/module/ops/get/src/lib.rs +++ /dev/null @@ -1,51 +0,0 @@ -use proto::backend::{self, pkg::*}; -use rivet_operation::prelude::*; - -#[derive(sqlx::FromRow)] -struct Module { - module_id: Uuid, - name_id: String, - team_id: Uuid, - create_ts: i64, - publicity: i64, -} - -#[operation(name = "module-get")] -pub async fn handle( - ctx: OperationContext, -) -> GlobalResult { - let module_ids = ctx - .module_ids - .iter() - .map(common::Uuid::as_uuid) - .collect::>(); - - let modules = sql_fetch_all!( - [ctx, Module] - " - SELECT - module_id, - name_id, - team_id, - create_ts, - publicity - FROM db_module.modules - WHERE module_id = ANY($1) - ", - module_ids, - ) - .await?; - - Ok(module::get::Response { - modules: modules - .into_iter() - .map(|module| backend::module::Module { - module_id: Some(module.module_id.into()), - name_id: module.name_id, - team_id: Some(module.team_id.into()), - create_ts: module.create_ts, - publicity: module.publicity as i32, - }) - .collect::>(), - }) -} diff --git a/svc/pkg/module/ops/get/tests/integration.rs b/svc/pkg/module/ops/get/tests/integration.rs deleted file mode 100644 index e397965af6..0000000000 --- a/svc/pkg/module/ops/get/tests/integration.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::collections::HashSet; - -use chirp_worker::prelude::*; -use proto::backend::pkg::*; - -#[worker_test] -async fn empty(ctx: TestCtx) { - let res = op!([ctx] module_get { - module_ids: Vec::new(), - }) - .await - .unwrap(); - assert!(res.modules.is_empty()); -} - -#[worker_test] -async fn fetch(ctx: TestCtx) { - // Generate test modules - let module_ids = std::iter::repeat_with(Uuid::new_v4) - .take(8) - .collect::>(); - - // Insert test modules - for module_id in &module_ids { - msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete(module_id) { - module_id: Some((*module_id).into()), - name_id: "test".into(), - team_id: Some(Uuid::new_v4().into()), - creator_user_id: None, - }) - .await - .unwrap(); - } - - // Fetch the modules - let res = op!([ctx] module_get { - module_ids: module_ids.iter().cloned().map(|x| x.into()).collect(), - }) - .await - .unwrap(); - - // Validate the modules - assert_eq!(module_ids.len(), res.modules.len()); -} diff --git a/svc/pkg/module/ops/instance-call/Cargo.toml b/svc/pkg/module/ops/instance-call/Cargo.toml deleted file mode 100644 index 00dc8441e3..0000000000 --- a/svc/pkg/module/ops/instance-call/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "module-instance-call" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -chirp-client = { path = "../../../../../lib/chirp/client" } -prost = "0.10" -rivet-operation = { path = "../../../../../lib/operation/core" } - -module-instance-get = { path = "../instance-get" } -module-version-get = { path = "../version-get" } -serde = { version = "1.0", features = ["derive"] } -reqwest = { version = "0.11", features = ["json"] } - -[dependencies.sqlx] -version = "0.7" -default-features = false - -[dev-dependencies] -chirp-worker = { path = "../../../../../lib/chirp/worker" } -rand = "0.8" diff --git a/svc/pkg/module/ops/instance-call/Service.toml b/svc/pkg/module/ops/instance-call/Service.toml deleted file mode 100644 index f9162ba502..0000000000 --- a/svc/pkg/module/ops/instance-call/Service.toml +++ /dev/null @@ -1,7 +0,0 @@ -[service] -name = "module-instance-call" - -[runtime] -kind = "rust" - -[operation] diff --git a/svc/pkg/module/ops/instance-call/src/lib.rs b/svc/pkg/module/ops/instance-call/src/lib.rs deleted file mode 100644 index c226285cbb..0000000000 --- a/svc/pkg/module/ops/instance-call/src/lib.rs +++ /dev/null @@ -1,107 +0,0 @@ -use std::time::Duration; - -use proto::backend::{self, pkg::*}; -use rivet_operation::prelude::*; -use serde::{Deserialize, Serialize}; - -#[derive(Serialize)] -struct CallRequest<'a> { - script_name: String, - request: &'a serde_json::Value, -} - -#[derive(Deserialize)] -struct CallResponse { - response: serde_json::Value, -} - -#[operation(name = "module-instance-call")] -pub async fn handle( - ctx: OperationContext, -) -> GlobalResult { - let instance_id = unwrap_ref!(ctx.instance_id).as_uuid(); - - // Get instance - let instances = op!([ctx] module_instance_get { - instance_ids: vec![instance_id.into()], - }) - .await?; - let instance = unwrap!(instances.instances.first()); - let version_id = unwrap_ref!(instance.module_version_id).as_uuid(); - ensure_with!(instance.destroy_ts.is_none(), MODULE_INSTANCE_DESTROYED); - - // Get version - let versions = op!([ctx] module_version_get { - version_ids: vec![version_id.into()], - }) - .await?; - let version = unwrap!(versions.versions.first()); - - // Validate script exists - ensure_with!( - version.scripts.iter().any(|x| x.name == ctx.script_name), - MODULE_SCRIPT_NOT_FOUND, - script = ctx.script_name, - ); - - // TODO: Validate JSON request schema - - // Handle driver - let url = match unwrap_ref!(instance.driver) { - backend::module::instance::Driver::Dummy(_) => { - return Ok(module::instance_call::Response { - response_json: "{}".into(), - }) - } - backend::module::instance::Driver::Fly(driver) => { - if let Some(app_id) = &driver.fly_app_id { - format!("https://{}.fly.dev/call", app_id) - } else { - bail_with!(MODULE_INSTANCE_STARTING) - } - } - }; - - let request_json = serde_json::from_str::(&ctx.request_json)?; - - // Call module - // - // Use backoff for this call because Fly.io can be _special_ sometimes. - let mut backoff = util::Backoff::new(3, Some(3), 500, 100); - let response = loop { - let response = reqwest::Client::new() - .post(&url) - .timeout(Duration::from_secs(5)) - .json(&CallRequest { - script_name: ctx.script_name.clone(), - request: &request_json, - }) - .send() - .await; - match response { - Ok(x) => break x, - Err(err) => { - tracing::error!(?err, "failed to call module"); - if backoff.tick().await { - bail_with!(MODULE_REQUEST_FAILED) - } - } - } - }; - if !response.status().is_success() { - tracing::warn!(status = ?response.status(), "module error status"); - bail_with!(MODULE_ERROR_STATUS, status = response.status().to_string()); - } - let res_body = match response.json::().await { - Ok(x) => x, - Err(err) => { - tracing::warn!(?err, "malformed module response"); - bail_with!(MODULE_MALFORMED_RESPONSE) - } - }; - let response_json = serde_json::to_string(&res_body.response)?; - - // TODO: Validate JSON response schema - - Ok(module::instance_call::Response { response_json }) -} diff --git a/svc/pkg/module/ops/instance-call/tests/integration.rs b/svc/pkg/module/ops/instance-call/tests/integration.rs deleted file mode 100644 index 17656ef851..0000000000 --- a/svc/pkg/module/ops/instance-call/tests/integration.rs +++ /dev/null @@ -1,70 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::{self, pkg::*}; -use serde_json::json; - -#[worker_test] -async fn fetch(ctx: TestCtx) { - if !util::feature::fly() { - return; - } - - let module_id = Uuid::new_v4(); - let version_id = Uuid::new_v4(); - let instance_id = Uuid::new_v4(); - - msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete { - module_id: Some(module_id.into()), - name_id: "test".into(), - team_id: Some(Uuid::new_v4().into()), - creator_user_id: None, - }) - .await - .unwrap(); - - msg!([ctx] module::msg::version_create(version_id) -> module::msg::version_create_complete { - version_id: Some(version_id.into()), - module_id: Some(module_id.into()), - creator_user_id: None, - - major: 1, - minor: 0, - patch: 0, - - scripts: vec![ - backend::module::Script { - name: "foo".into(), - request_schema: "{}".into(), - response_schema: "{}".into(), - callable: Some(backend::module::script::Callable {}), - }, - ], - - image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { - image_tag: "ghcr.io/rivet-gg/rivet-module-hello-world:0.0.1".into(), - })), - }).await.unwrap(); - - // Insert test modules - msg!([ctx] module::msg::instance_create(instance_id) -> module::msg::instance_create_complete { - instance_id: Some(instance_id.into()), - module_version_id: Some(version_id.into()), - driver: Some(module::msg::instance_create::message::Driver::Fly(module::msg::instance_create::message::Fly {})), - }) - .await - .unwrap(); - - // Call request - let res = op!([ctx] module_instance_call { - instance_id: Some(instance_id.into()), - script_name: "foo".into(), - request_json: serde_json::to_string(&json!({ - "x": 5 - })).unwrap(), - }) - .await - .unwrap(); - - // Validate response - let response_json = serde_json::from_str::(&res.response_json).unwrap(); - assert_eq!(response_json["y"], 10); -} diff --git a/svc/pkg/module/ops/instance-get/Cargo.toml b/svc/pkg/module/ops/instance-get/Cargo.toml deleted file mode 100644 index 23fa6c7239..0000000000 --- a/svc/pkg/module/ops/instance-get/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "module-instance-get" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -chirp-client = { path = "../../../../../lib/chirp/client" } -prost = "0.10" -rivet-operation = { path = "../../../../../lib/operation/core" } - -[dependencies.sqlx] -version = "0.7" -default-features = false - -[dev-dependencies] -chirp-worker = { path = "../../../../../lib/chirp/worker" } -rand = "0.8" diff --git a/svc/pkg/module/ops/instance-get/Service.toml b/svc/pkg/module/ops/instance-get/Service.toml deleted file mode 100644 index bb073073c4..0000000000 --- a/svc/pkg/module/ops/instance-get/Service.toml +++ /dev/null @@ -1,10 +0,0 @@ -[service] -name = "module-instance-get" - -[runtime] -kind = "rust" - -[operation] - -[databases] -db-module = {} diff --git a/svc/pkg/module/ops/instance-get/src/lib.rs b/svc/pkg/module/ops/instance-get/src/lib.rs deleted file mode 100644 index c466a74b94..0000000000 --- a/svc/pkg/module/ops/instance-get/src/lib.rs +++ /dev/null @@ -1,71 +0,0 @@ -use proto::backend::{self, pkg::*}; -use rivet_operation::prelude::*; - -#[derive(sqlx::FromRow)] -struct Instance { - instance_id: Uuid, - version_id: Uuid, - create_ts: i64, - destroy_ts: Option, - - driver_dummy: bool, - - driver_fly: bool, - driver_fly_app_id: Option, -} - -#[operation(name = "module-instance-get")] -pub async fn handle( - ctx: OperationContext, -) -> GlobalResult { - let instance_ids = ctx - .instance_ids - .iter() - .map(common::Uuid::as_uuid) - .collect::>(); - - let instances = sql_fetch_all!( - [ctx, Instance] - " - SELECT - i.instance_id, - i.version_id, - i.create_ts, - i.destroy_ts, - idd.instance_id IS NOT NULL AS driver_dummy, - idv.instance_id IS NOT NULL AS driver_fly, - idv.fly_app_id AS driver_fly_app_id - FROM db_module.instances AS i - LEFT JOIN db_module.instances_driver_dummy AS idd ON idd.instance_id = i.instance_id - LEFT JOIN db_module.instances_driver_fly AS idv ON idv.instance_id = i.instance_id - WHERE i.instance_id = ANY($1) - ", - &instance_ids, - ) - .await?; - - Ok(module::instance_get::Response { - instances: instances - .into_iter() - .map(|instance| { - let driver = if instance.driver_dummy { - backend::module::instance::Driver::Dummy(backend::module::instance::Dummy {}) - } else if instance.driver_fly { - backend::module::instance::Driver::Fly(backend::module::instance::Fly { - fly_app_id: instance.driver_fly_app_id, - }) - } else { - bail!("instance has no driver") - }; - - GlobalResult::Ok(backend::module::Instance { - instance_id: Some(instance.instance_id.into()), - module_version_id: Some(instance.version_id.into()), - create_ts: instance.create_ts, - destroy_ts: instance.destroy_ts, - driver: Some(driver), - }) - }) - .collect::>>()?, - }) -} diff --git a/svc/pkg/module/ops/instance-get/tests/integration.rs b/svc/pkg/module/ops/instance-get/tests/integration.rs deleted file mode 100644 index 5f1c365600..0000000000 --- a/svc/pkg/module/ops/instance-get/tests/integration.rs +++ /dev/null @@ -1,82 +0,0 @@ -use std::collections::HashSet; - -use chirp_worker::prelude::*; -use proto::backend::{self, pkg::*}; - -#[worker_test] -async fn empty(ctx: TestCtx) { - let res = op!([ctx] module_instance_get { - instance_ids: Vec::new(), - }) - .await - .unwrap(); - assert!(res.instances.is_empty()); -} - -#[worker_test] -async fn fetch(ctx: TestCtx) { - if !util::feature::fly() { - return; - } - - let module_id = Uuid::new_v4(); - let version_id = Uuid::new_v4(); - - msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete { - module_id: Some(module_id.into()), - name_id: "test".into(), - team_id: Some(Uuid::new_v4().into()), - creator_user_id: None, - }) - .await - .unwrap(); - - msg!([ctx] module::msg::version_create(version_id) -> module::msg::version_create_complete { - version_id: Some(version_id.into()), - module_id: Some(module_id.into()), - creator_user_id: None, - - major: 1, - minor: 0, - patch: 0, - - scripts: vec![ - backend::module::Script { - name: "foo".into(), - request_schema: "{}".into(), - response_schema: "{}".into(), - callable: Some(backend::module::script::Callable {}), - }, - ], - - image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { - image_tag: "ghcr.io/rivet-gg/rivet-module-hello-world:latest".into(), - })), - }).await.unwrap(); - - // Generate test instances - let instance_ids = std::iter::repeat_with(Uuid::new_v4) - .take(8) - .collect::>(); - - // Insert test modules - for instance_id in &instance_ids { - msg!([ctx] module::msg::instance_create(instance_id) -> module::msg::instance_create_complete { - instance_id: Some((*instance_id).into()), - module_version_id: Some(version_id.into()), - driver: Some(module::msg::instance_create::message::Driver::Dummy(module::msg::instance_create::message::Dummy {})), - }) - .await - .unwrap(); - } - - // Fetch the versions - let res = op!([ctx] module_instance_get { - instance_ids: instance_ids.iter().cloned().map(|x| x.into()).collect(), - }) - .await - .unwrap(); - - // Validate the modules - assert_eq!(instance_ids.len(), res.instances.len()); -} diff --git a/svc/pkg/module/ops/ns-instance-get/Cargo.toml b/svc/pkg/module/ops/ns-instance-get/Cargo.toml deleted file mode 100644 index 51ed860657..0000000000 --- a/svc/pkg/module/ops/ns-instance-get/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "module-ns-instance-get" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -chirp-client = { path = "../../../../../lib/chirp/client" } -prost = "0.10" -rivet-operation = { path = "../../../../../lib/operation/core" } - -[dependencies.sqlx] -version = "0.7" -default-features = false - -[dev-dependencies] -chirp-worker = { path = "../../../../../lib/chirp/worker" } -rand = "0.8" diff --git a/svc/pkg/module/ops/ns-instance-get/Service.toml b/svc/pkg/module/ops/ns-instance-get/Service.toml deleted file mode 100644 index 0e3ce2fd90..0000000000 --- a/svc/pkg/module/ops/ns-instance-get/Service.toml +++ /dev/null @@ -1,10 +0,0 @@ -[service] -name = "module-ns-instance-get" - -[runtime] -kind = "rust" - -[operation] - -[databases] -db-module = {} diff --git a/svc/pkg/module/ops/ns-instance-get/src/lib.rs b/svc/pkg/module/ops/ns-instance-get/src/lib.rs deleted file mode 100644 index ac461574f5..0000000000 --- a/svc/pkg/module/ops/ns-instance-get/src/lib.rs +++ /dev/null @@ -1,29 +0,0 @@ -use proto::backend::pkg::*; -use rivet_operation::prelude::*; - -#[operation(name = "module-ns-instance-get")] -pub async fn handle( - ctx: OperationContext, -) -> GlobalResult { - let namespace_id = unwrap_ref!(ctx.namespace_id).as_uuid(); - - let instance = sql_fetch_optional!( - [ctx, (Uuid,)] - " - SELECT instance_id - FROM db_module.namespace_instances - WHERE namespace_id = $1 AND key = $2 - ", - namespace_id, - &ctx.key, - ) - .await?; - - Ok(module::ns_instance_get::Response { - instance: instance.map( - |(instance_id,)| module::ns_instance_get::response::Instance { - instance_id: Some(instance_id.into()), - }, - ), - }) -} diff --git a/svc/pkg/module/ops/ns-instance-get/tests/integration.rs b/svc/pkg/module/ops/ns-instance-get/tests/integration.rs deleted file mode 100644 index d2939f861e..0000000000 --- a/svc/pkg/module/ops/ns-instance-get/tests/integration.rs +++ /dev/null @@ -1,6 +0,0 @@ -use chirp_worker::prelude::*; - -#[worker_test] -async fn empty(_ctx: TestCtx) { - // TODO: -} diff --git a/svc/pkg/module/ops/version-get/Cargo.toml b/svc/pkg/module/ops/version-get/Cargo.toml deleted file mode 100644 index 46eb7d5619..0000000000 --- a/svc/pkg/module/ops/version-get/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "module-version-get" -version = "0.0.1" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -chirp-client = { path = "../../../../../lib/chirp/client" } -prost = "0.10" -rivet-operation = { path = "../../../../../lib/operation/core" } - -module-get = { path = "../get" } - -[dependencies.sqlx] -version = "0.7" -default-features = false - -[dev-dependencies] -chirp-worker = { path = "../../../../../lib/chirp/worker" } -rand = "0.8" diff --git a/svc/pkg/module/ops/version-get/Service.toml b/svc/pkg/module/ops/version-get/Service.toml deleted file mode 100644 index f60ddc2cda..0000000000 --- a/svc/pkg/module/ops/version-get/Service.toml +++ /dev/null @@ -1,10 +0,0 @@ -[service] -name = "module-version-get" - -[runtime] -kind = "rust" - -[operation] - -[databases] -db-module = {} diff --git a/svc/pkg/module/ops/version-get/src/lib.rs b/svc/pkg/module/ops/version-get/src/lib.rs deleted file mode 100644 index 40f99e4e51..0000000000 --- a/svc/pkg/module/ops/version-get/src/lib.rs +++ /dev/null @@ -1,106 +0,0 @@ -use proto::backend::{self, pkg::*}; -use rivet_operation::prelude::*; - -#[derive(sqlx::FromRow)] -struct Version { - version_id: Uuid, - module_id: Uuid, - create_ts: i64, - major: i64, - minor: i64, - patch: i64, - image_docker_image_tag: Option, -} - -#[derive(sqlx::FromRow)] -struct Script { - version_id: Uuid, - name: String, - request_schema: String, - response_schema: String, - callable: bool, -} - -#[operation(name = "module-version-get")] -pub async fn handle( - ctx: OperationContext, -) -> GlobalResult { - let version_ids = ctx - .version_ids - .iter() - .map(common::Uuid::as_uuid) - .collect::>(); - - let versions = sql_fetch_all!( - [ctx, Version] - " - SELECT - v.version_id, - v.module_id, - v.create_ts, - v.major, - v.minor, - v.patch, - vid.image_tag AS image_docker_image_tag - FROM db_module.versions AS v - LEFT JOIN db_module.versions_image_docker AS vid ON vid.version_id = v.version_id - WHERE v.version_id = ANY($1) - ", - &version_ids, - ) - .await?; - - let scripts = sql_fetch_all!( - [ctx, Script] - " - SELECT - f.version_id, - f.name, - f.request_schema, - f.response_schema, - fc.version_id IS NOT NULL AS callable - FROM db_module.scripts AS f - LEFT JOIN db_module.scripts_callable AS fc ON fc.version_id = f.version_id AND fc.name = f.name - WHERE f.version_id = ANY($1) - ", - version_ids, - ) - .await?; - - Ok(module::version_get::Response { - versions: versions - .into_iter() - .map(|version| { - let scripts = scripts - .iter() - .filter(|script| script.version_id == version.version_id) - .map(|script| backend::module::Script { - name: script.name.clone(), - request_schema: script.request_schema.clone(), - response_schema: script.response_schema.clone(), - callable: if script.callable { - Some(backend::module::script::Callable {}) - } else { - None - }, - }) - .collect::>(); - - backend::module::Version { - version_id: Some(version.version_id.into()), - module_id: Some(version.module_id.into()), - create_ts: version.create_ts, - major: version.major as u64, - minor: version.minor as u64, - patch: version.patch as u64, - scripts, - image: version.image_docker_image_tag.map(|image_tag| { - backend::module::version::Image::Docker(backend::module::version::Docker { - image_tag, - }) - }), - } - }) - .collect::>(), - }) -} diff --git a/svc/pkg/module/ops/version-get/tests/integration.rs b/svc/pkg/module/ops/version-get/tests/integration.rs deleted file mode 100644 index 542ce7ee8b..0000000000 --- a/svc/pkg/module/ops/version-get/tests/integration.rs +++ /dev/null @@ -1,68 +0,0 @@ -use std::collections::HashSet; - -use chirp_worker::prelude::*; -use proto::backend::{self, pkg::*}; - -#[worker_test] -async fn empty(ctx: TestCtx) { - let res = op!([ctx] module_get { - module_ids: Vec::new(), - }) - .await - .unwrap(); - assert!(res.modules.is_empty()); -} - -#[worker_test] -async fn fetch(ctx: TestCtx) { - let module_id = Uuid::new_v4(); - msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete(module_id) { - module_id: Some(module_id.into()), - name_id: "test".into(), - team_id: Some(Uuid::new_v4().into()), - creator_user_id: None, - }) - .await - .unwrap(); - - // Generate test versions - let version_ids = std::iter::repeat_with(Uuid::new_v4) - .take(8) - .collect::>(); - - // Insert test modules - for version_id in &version_ids { - msg!([ctx] module::msg::version_create(version_id) -> module::msg::version_create_complete { - version_id: Some((*version_id).into()), - module_id: Some(module_id.into()), - creator_user_id: None, - - major: 1, - minor: 0, - patch: 0, - - scripts: vec![ - backend::module::Script { - name: "foo".into(), - request_schema: "{}".into(), - response_schema: "{}".into(), - callable: Some(backend::module::script::Callable {}), - }, - ], - - image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { - image_tag: "test".into(), - })), - }).await.unwrap(); - } - - // Fetch the versions - let res = op!([ctx] module_version_get { - version_ids: version_ids.iter().cloned().map(|x| x.into()).collect(), - }) - .await - .unwrap(); - - // Validate the modules - assert_eq!(version_ids.len(), res.versions.len()); -} diff --git a/svc/pkg/module/types/game-version-get.proto b/svc/pkg/module/types/game-version-get.proto deleted file mode 100644 index 05e7d42838..0000000000 --- a/svc/pkg/module/types/game-version-get.proto +++ /dev/null @@ -1,20 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.game_version_get; - -import "proto/common.proto"; -import "proto/backend/module.proto"; - -message Request { - repeated rivet.common.Uuid version_ids = 1; -} - -message Response { - message Version { - rivet.common.Uuid version_id = 1; - rivet.backend.module.GameVersionConfig config = 2; - rivet.backend.module.GameVersionConfigMeta config_meta = 3; - } - - repeated Version versions = 1; -} diff --git a/svc/pkg/module/types/game-version-prepare.proto b/svc/pkg/module/types/game-version-prepare.proto deleted file mode 100644 index 2cf3131afc..0000000000 --- a/svc/pkg/module/types/game-version-prepare.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.game_version_prepare; - -import "proto/common.proto"; -import "proto/backend/module.proto"; - -message Request { - rivet.backend.module.GameVersionConfig config = 1; - rivet.common.Uuid game_id = 2; -} - -message Response { - rivet.backend.module.GameVersionConfigCtx config_ctx = 1; -} diff --git a/svc/pkg/module/types/game-version-publish.proto b/svc/pkg/module/types/game-version-publish.proto deleted file mode 100644 index 802adb90fd..0000000000 --- a/svc/pkg/module/types/game-version-publish.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.game_version_publish; - -import "proto/common.proto"; -import "proto/backend/module.proto"; - -message Request { - rivet.common.Uuid version_id = 1; - rivet.backend.module.GameVersionConfig config = 2; - rivet.backend.module.GameVersionConfigCtx config_ctx = 3; -} - -message Response { - -} diff --git a/svc/pkg/module/types/get.proto b/svc/pkg/module/types/get.proto deleted file mode 100644 index 284fb4434c..0000000000 --- a/svc/pkg/module/types/get.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.get; - -import "proto/common.proto"; -import "proto/backend/module.proto"; - -message Request { - repeated rivet.common.Uuid module_ids = 1; -} - -message Response { - repeated rivet.backend.module.Module modules = 1; -} diff --git a/svc/pkg/module/types/instance-call.proto b/svc/pkg/module/types/instance-call.proto deleted file mode 100644 index b217523341..0000000000 --- a/svc/pkg/module/types/instance-call.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.instance_call; - -import "proto/common.proto"; - -message Request { - rivet.common.Uuid instance_id = 1; - string script_name = 2; - string request_json = 3; -} - -message Response { - string response_json = 1; -} - diff --git a/svc/pkg/module/types/instance-get.proto b/svc/pkg/module/types/instance-get.proto deleted file mode 100644 index a719d49483..0000000000 --- a/svc/pkg/module/types/instance-get.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.instance_get; - -import "proto/common.proto"; -import "proto/backend/module.proto"; - -message Request { - repeated rivet.common.Uuid instance_ids = 1; -} - -message Response { - repeated rivet.backend.module.Instance instances = 1; -} diff --git a/svc/pkg/module/types/msg/create-complete.proto b/svc/pkg/module/types/msg/create-complete.proto deleted file mode 100644 index 852fb97c78..0000000000 --- a/svc/pkg/module/types/msg/create-complete.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.create_complete; - -import "proto/common.proto"; - -/// name = "msg-module-create-complete" -/// parameters = [ -/// { name = "module_id" }, -/// ] -message Message { - rivet.common.Uuid module_id = 1; -} - diff --git a/svc/pkg/module/types/msg/create.proto b/svc/pkg/module/types/msg/create.proto deleted file mode 100644 index f4988ea32d..0000000000 --- a/svc/pkg/module/types/msg/create.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.create; - -import "proto/common.proto"; - -/// name = "msg-module-create" -/// parameters = [ -/// { name = "module_id" }, -/// ] -message Message { - rivet.common.Uuid module_id = 1; - string name_id = 2; - rivet.common.Uuid team_id = 3; - optional rivet.common.Uuid creator_user_id = 4; -} - diff --git a/svc/pkg/module/types/msg/instance-create-complete.proto b/svc/pkg/module/types/msg/instance-create-complete.proto deleted file mode 100644 index d094ebaba8..0000000000 --- a/svc/pkg/module/types/msg/instance-create-complete.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.instance_create_complete; - -import "proto/common.proto"; -import "proto/backend/module.proto"; -import "proto/backend/module/script.proto"; - -/// name = "msg-module-instance-create-complete" -/// parameters = [ -/// { name = "instance_id" }, -/// ] -message Message { - rivet.common.Uuid instance_id = 1; -} - diff --git a/svc/pkg/module/types/msg/instance-create.proto b/svc/pkg/module/types/msg/instance-create.proto deleted file mode 100644 index b3bb5b7f2d..0000000000 --- a/svc/pkg/module/types/msg/instance-create.proto +++ /dev/null @@ -1,29 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.instance_create; - -import "proto/common.proto"; -import "proto/backend/module.proto"; -import "proto/backend/module/script.proto"; - -/// name = "msg-module-instance-create" -/// parameters = [ -/// { name = "instance_id" }, -/// ] -message Message { - rivet.common.Uuid instance_id = 1; - rivet.common.Uuid module_version_id = 2; - - message Dummy { - - } - - message Fly { - - } - - oneof driver { - Dummy dummy = 101; - Fly fly = 102; - }; -} diff --git a/svc/pkg/module/types/msg/instance-destroy-complete.proto b/svc/pkg/module/types/msg/instance-destroy-complete.proto deleted file mode 100644 index 14e9457795..0000000000 --- a/svc/pkg/module/types/msg/instance-destroy-complete.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.instance_destroy_complete; - -import "proto/common.proto"; - -/// name = "msg-module-instance-destroy-complete" -/// parameters = [ -/// { name = "instance_id" }, -/// ] -message Message { - rivet.common.Uuid instance_id = 1; -} - diff --git a/svc/pkg/module/types/msg/instance-destroy.proto b/svc/pkg/module/types/msg/instance-destroy.proto deleted file mode 100644 index 7bedffe498..0000000000 --- a/svc/pkg/module/types/msg/instance-destroy.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.instance_destroy; - -import "proto/common.proto"; - -/// name = "msg-module-instance-destroy" -/// parameters = [ -/// { name = "instance_id" }, -/// ] -message Message { - rivet.common.Uuid instance_id = 1; -} - diff --git a/svc/pkg/module/types/msg/instance-version-set-complete.proto b/svc/pkg/module/types/msg/instance-version-set-complete.proto deleted file mode 100644 index 106358958f..0000000000 --- a/svc/pkg/module/types/msg/instance-version-set-complete.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.instance_version_set_complete; - -import "proto/common.proto"; - -/// name = "msg-module-instance-version-set-complete" -/// parameters = [ -/// { name = "instance_id" }, -/// ] -message Message { - rivet.common.Uuid instance_id = 1; - rivet.common.Uuid version_id = 2; -} - diff --git a/svc/pkg/module/types/msg/instance-version-set.proto b/svc/pkg/module/types/msg/instance-version-set.proto deleted file mode 100644 index 04bb7896a9..0000000000 --- a/svc/pkg/module/types/msg/instance-version-set.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.instance_version_set; - -import "proto/common.proto"; - -/// name = "msg-module-instance-version-set" -/// parameters = [ -/// { name = "instance_id" }, -/// ] -message Message { - rivet.common.Uuid instance_id = 1; - rivet.common.Uuid version_id = 2; -} - diff --git a/svc/pkg/module/types/msg/ns-version-set-complete.proto b/svc/pkg/module/types/msg/ns-version-set-complete.proto deleted file mode 100644 index fa9234416f..0000000000 --- a/svc/pkg/module/types/msg/ns-version-set-complete.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.ns_version_set_complete; - -import "proto/common.proto"; - -/// name = "msg-module-ns-version-set-complete" -/// parameters = [ -/// { name = "namespace_id" }, -/// ] -message Message { - rivet.common.Uuid namespace_id = 1; - rivet.common.Uuid version_id = 2; -} - diff --git a/svc/pkg/module/types/msg/version-create-complete.proto b/svc/pkg/module/types/msg/version-create-complete.proto deleted file mode 100644 index f5350a8ab7..0000000000 --- a/svc/pkg/module/types/msg/version-create-complete.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.version_create_complete; - -import "proto/common.proto"; -import "proto/backend/module.proto"; -import "proto/backend/module/script.proto"; - -/// name = "msg-module-version-create-complete" -/// parameters = [ -/// { name = "version_id" }, -/// ] -message Message { - rivet.common.Uuid version_id = 1; -} - diff --git a/svc/pkg/module/types/msg/version-create.proto b/svc/pkg/module/types/msg/version-create.proto deleted file mode 100644 index 2acdd8ca17..0000000000 --- a/svc/pkg/module/types/msg/version-create.proto +++ /dev/null @@ -1,31 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.msg.version_create; - -import "proto/common.proto"; -import "proto/backend/module.proto"; -import "proto/backend/module/script.proto"; - -/// name = "msg-module-version-create" -/// parameters = [ -/// { name = "version_id" }, -/// ] -message Message { - rivet.common.Uuid version_id = 1; - rivet.common.Uuid module_id = 2; - rivet.common.Uuid creator_user_id = 3; - repeated rivet.backend.module.Script scripts = 4; - - uint64 major = 101; - uint64 minor = 102; - uint64 patch = 103; - - message Docker { - string image_tag = 1; - } - - oneof image { - Docker docker = 201; - } -} - diff --git a/svc/pkg/module/types/ns-instance-get.proto b/svc/pkg/module/types/ns-instance-get.proto deleted file mode 100644 index 2afda10c02..0000000000 --- a/svc/pkg/module/types/ns-instance-get.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.ns_instance_get; - -import "proto/common.proto"; - -message Request { - rivet.common.Uuid namespace_id = 1; - string key = 2; -} - -message Response { - message Instance { - rivet.common.Uuid instance_id = 1; - } - - optional Instance instance = 1; -} diff --git a/svc/pkg/module/types/version-get.proto b/svc/pkg/module/types/version-get.proto deleted file mode 100644 index 42ad1f5d11..0000000000 --- a/svc/pkg/module/types/version-get.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; - -package rivet.backend.pkg.module.version_get; - -import "proto/common.proto"; -import "proto/backend/module.proto"; - -message Request { - repeated rivet.common.Uuid version_ids = 1; -} - -message Response { - repeated rivet.backend.module.Version versions = 1; -} diff --git a/svc/pkg/module/util/Cargo.toml b/svc/pkg/module/util/Cargo.toml deleted file mode 100644 index 7ad746a36e..0000000000 --- a/svc/pkg/module/util/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "rivet-util-module" -version = "0.1.0" -edition = "2021" -authors = ["Rivet Gaming, LLC "] -license = "Apache-2.0" - -[dependencies] -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" diff --git a/svc/pkg/module/util/src/fly.rs b/svc/pkg/module/util/src/fly.rs deleted file mode 100644 index f6d90f7f1c..0000000000 --- a/svc/pkg/module/util/src/fly.rs +++ /dev/null @@ -1,57 +0,0 @@ -use serde_json::json; - -pub struct MachineConfig<'a> { - pub image: &'a str, -} - -impl MachineConfig<'_> { - /// Builds the JSON config for the Fly machine. - pub fn build_machine_config(&self) -> serde_json::Value { - json!({ - "services": [ - { - "protocol": "tcp", - "internal_port": 80, - "autostop": true, - "autostart": true, - "ports": [ - { - "port": 80, - "handlers": ["http"], - "force_https": true - }, - { - "port": 443, - "handlers": ["http", "tls"] - } - ], - "force_instance_key": null - } - ], - "checks": { - "alive": { - "type": "tcp", - "port": 80, - "interval": "15s", - "timeout": "2s", - "grace_period": "5s" - }, - "health": { - "type": "http", - "port": 80, - "path": "/healthz", - "interval": "15s", - "timeout": "2s", - "grace_period": "5s" - } - }, - "image": self.image, - "restart": {}, - "guest": { - "cpu_kind": "shared", - "cpus": 1, - "memory_mb": 512 - } - }) - } -} diff --git a/svc/pkg/module/util/src/lib.rs b/svc/pkg/module/util/src/lib.rs deleted file mode 100644 index 20b6c6321b..0000000000 --- a/svc/pkg/module/util/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod fly; diff --git a/svc/pkg/module/worker/Cargo.toml b/svc/pkg/module/worker/Cargo.toml deleted file mode 100644 index 4ba8a5380b..0000000000 --- a/svc/pkg/module/worker/Cargo.toml +++ /dev/null @@ -1,34 +0,0 @@ -[package] -name = "module-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" -rivet-health-checks = { path = "../../../../lib/health-checks" } -rivet-metrics = { path = "../../../../lib/metrics" } -rivet-runtime = { path = "../../../../lib/runtime" } -reqwest = "0.11" -serde = { version = "1.0", features = ["derive"] } -util-module = { package = "rivet-util-module", path = "../util" } - -module-version-get = { path = "../ops/version-get" } -module-instance-get = { path = "../ops/instance-get" } -module-game-version-get = { path = "../ops/game-version-get" } - -[dependencies.sqlx] -version = "0.7" -default-features = false - -[dev-dependencies] -chirp-worker = { path = "../../../../lib/chirp/worker" } - -faker-game = { path = "../../faker/ops/game" } -faker-game-version = { path = "../../faker/ops/game-version" } -upload-get = { path = "../../upload/ops/get" } -upload-prepare = { path = "../../upload/ops/prepare" } diff --git a/svc/pkg/module/worker/Service.toml b/svc/pkg/module/worker/Service.toml deleted file mode 100644 index a56f7a9b99..0000000000 --- a/svc/pkg/module/worker/Service.toml +++ /dev/null @@ -1,13 +0,0 @@ -[service] -name = "module-worker" - -[runtime] -kind = "rust" - -[consumer] - -[databases] -db-module = {} - -[secrets] -"fly/auth_token" = { optional = true } diff --git a/svc/pkg/module/worker/src/lib.rs b/svc/pkg/module/worker/src/lib.rs deleted file mode 100644 index 3719b10aa8..0000000000 --- a/svc/pkg/module/worker/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod workers; diff --git a/svc/pkg/module/worker/src/workers/create.rs b/svc/pkg/module/worker/src/workers/create.rs deleted file mode 100644 index ef55a0db00..0000000000 --- a/svc/pkg/module/worker/src/workers/create.rs +++ /dev/null @@ -1,47 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::pkg::*; -use serde_json::json; - -#[worker(name = "module-create")] -async fn worker(ctx: &OperationContext) -> Result<(), GlobalError> { - let module_id = unwrap_ref!(ctx.module_id).as_uuid(); - let team_id = unwrap_ref!(ctx.team_id).as_uuid(); - let creator_user_id = ctx.creator_user_id.map(|x| x.as_uuid()); - - sql_execute!( - [ctx] - " - INSERT INTO db_module.modules (module_id, name_id, team_id, create_ts, creator_user_id) - VALUES ($1, $2, $3, $4, $5) - ", - module_id, - &ctx.name_id, - team_id, - ctx.ts(), - creator_user_id, - ) - .await?; - - msg!([ctx] module::msg::create_complete(module_id) { - module_id: ctx.module_id, - }) - .await?; - - msg!([ctx] analytics::msg::event_create() { - events: vec![ - analytics::msg::event_create::Event { - event_id: Some(Uuid::new_v4().into()), - name: "module.create".into(), - properties_json: Some(serde_json::to_string(&json!({ - "user_id": ctx.creator_user_id.map(|x| x.as_uuid()), - "module_id": module_id, - "name_id": ctx.name_id, - }))?), - ..Default::default() - }, - ], - }) - .await?; - - Ok(()) -} diff --git a/svc/pkg/module/worker/src/workers/instance_create.rs b/svc/pkg/module/worker/src/workers/instance_create.rs deleted file mode 100644 index 64957875d3..0000000000 --- a/svc/pkg/module/worker/src/workers/instance_create.rs +++ /dev/null @@ -1,517 +0,0 @@ -use std::{collections::HashSet, time::Duration}; - -use chirp_worker::prelude::*; -use futures_util::{StreamExt, TryStreamExt}; -use proto::backend::{self, pkg::*}; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use serde_json::json; - -#[derive(Serialize)] -struct Variables { - input: T, -} - -#[derive(Serialize)] -#[serde(rename_all = "camelCase")] -struct CreateAppInput { - name: String, - organization_id: String, - preferred_region: String, - machines: bool, -} - -#[derive(Serialize)] -#[serde(rename_all = "camelCase")] -struct CreateReleaseInput { - app_id: String, - image: String, - platform_version: String, - strategy: String, - definition: serde_json::Value, -} - -#[derive(Serialize)] -#[serde(rename_all = "camelCase")] -struct QueryBody { - query: &'static str, - variables: Variables, -} - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -struct CreateAppPayload { - app: App, -} - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -struct App { - id: String, -} - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -enum GraphQLResponse { - #[serde(rename = "data")] - Data(T), - #[serde(rename = "errors")] - Errors(Vec), -} - -impl GraphQLResponse { - fn data(self) -> GlobalResult { - match self { - GraphQLResponse::Data(data) => Ok(data), - GraphQLResponse::Errors(errors) => { - tracing::error!(?errors, "graphql errors"); - bail!("graphql errors") - } - } - } -} - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -struct CreateAppResponse { - create_app: CreateAppPayload, -} - -#[derive(Deserialize, Debug)] -#[allow(dead_code)] -struct FlyMachine { - id: String, - instance_id: String, - name: String, - checks: Vec, -} - -#[derive(Deserialize, Debug)] -#[allow(dead_code)] -struct CheckStatus { - name: String, - output: Option, - status: String, -} - -#[worker(name = "module-instance-create")] -async fn worker( - ctx: &OperationContext, -) -> Result<(), GlobalError> { - let (Ok(fly_org), Ok(fly_region)) = ( - std::env::var("FLY_ORGANIZATION_ID"), - std::env::var("FLY_REGION"), - ) else { - bail!("fly not enabled"); - }; - let fly_auth_token = util::env::read_secret(&["fly", "auth_token"]).await?; - - let instance_id = unwrap_ref!(ctx.instance_id).as_uuid(); - let version_id = unwrap_ref!(ctx.module_version_id).as_uuid(); - - // Read module version - let versions = op!([ctx] module_version_get { - version_ids: vec![version_id.into()], - }) - .await?; - let version = unwrap!(versions.versions.first()); - let module_id = unwrap!(version.module_id).as_uuid(); - - // Create transaction - rivet_pools::utils::crdb::tx(&ctx.crdb().await?, |tx| { - Box::pin(insert_instance(ctx.clone(), tx, ctx.ts())) - }) - .await?; - - // Create Fly app - if matches!( - ctx.driver, - Some(module::msg::instance_create::message::Driver::Fly(_)) - ) { - // Create app - // TODO: Handle failure - let image = match unwrap_ref!(version.image) { - backend::module::version::Image::Docker(docker) => docker.image_tag.clone(), - }; - let app_id = launch_app(LaunchAppOpts { - organization_id: fly_org.clone(), - name: build_app_name(instance_id), - preferred_region: fly_region.clone(), - auth_token: fly_auth_token.clone(), - image: image.clone(), - }) - .await?; - - // Update app ID - sql_execute!( - [ctx] - " - UPDATE db_module.instances_driver_fly - SET fly_app_id = $2 - WHERE instance_id = $1 - ", - instance_id, - app_id, - ) - .await?; - } - - // TODO: Find a 2PC system for releasing the app - - msg!([ctx] module::msg::instance_create_complete(instance_id) { - instance_id: ctx.instance_id, - }) - .await?; - - msg!([ctx] analytics::msg::event_create() { - events: vec![ - analytics::msg::event_create::Event { - event_id: Some(Uuid::new_v4().into()), - name: "module.create".into(), - properties_json: Some(serde_json::to_string(&json!({ - "module_id": module_id, - "module_instance_id": unwrap_ref!(ctx.instance_id).as_uuid(), - "module_version_id": unwrap_ref!(ctx.module_version_id).as_uuid(), - }))?), - ..Default::default() - }, - ], - }) - .await?; - - Ok(()) -} - -#[tracing::instrument(skip_all)] -async fn insert_instance( - ctx: OperationContext, - tx: &mut sqlx::Transaction<'_, sqlx::Postgres>, - now: i64, -) -> GlobalResult<()> { - let instance_id = unwrap_ref!(ctx.instance_id).as_uuid(); - let version_id = unwrap_ref!(ctx.module_version_id).as_uuid(); - - sql_execute!( - [ctx, @tx tx] - " - INSERT INTO db_module.instances (instance_id, version_id, create_ts) - VALUES ($1, $2, $3) - ", - instance_id, - version_id, - now, - ) - .await?; - - match unwrap_ref!(ctx.driver) { - module::msg::instance_create::message::Driver::Dummy(_) => { - sql_execute!( - [ctx, @tx tx] - " - INSERT INTO db_module.instances_driver_dummy (instance_id) - VALUES ($1) - ", - instance_id, - ) - .await?; - } - module::msg::instance_create::message::Driver::Fly(_) => { - sql_execute!( - [ctx, @tx tx] - " - INSERT INTO db_module.instances_driver_fly (instance_id) - VALUES ($1) - ", - instance_id, - ) - .await?; - } - } - - Ok(()) -} - -#[derive(Clone)] -struct LaunchAppOpts { - organization_id: String, - name: String, - preferred_region: String, - auth_token: String, - image: String, -} - -#[tracing::instrument(skip(opts))] -async fn launch_app(opts: LaunchAppOpts) -> GlobalResult { - // Create app - tracing::info!(organization_id = ?opts.organization_id, name = ?opts.name, preferred_region = ?opts.preferred_region, "creating fly app"); - let res = graphql_request::<_, CreateAppResponse>( - &opts.auth_token, - indoc!( - r#" - mutation CreateApp($input: CreateAppInput!) { - createApp(input: $input) { - app { - id - } - } - } - "# - ), - json!({ - "organizationId": opts.organization_id, - "name": opts.name, - "preferredRegion": opts.preferred_region, - "machines": true, - }), - ) - .await?; - let app_id = res.create_app.app.id; - - // Create ipv6 - tracing::info!("creating ipv6"); - graphql_request::<_, serde_json::Value>( - &opts.auth_token, - indoc!( - r#" - mutation($input: AllocateIPAddressInput!) { - allocateIpAddress(input: $input) { - ipAddress { - id - address - type - region - createdAt - } - } - } - "# - ), - json!({ - "appId": app_id, - "type": "v6" - }), - ) - .await?; - - // Create shared ipv4 - tracing::info!("creating shared ipv4"); - graphql_request::<_, serde_json::Value>( - &opts.auth_token, - indoc!( - r#" - mutation($input: AllocateIPAddressInput!) { - allocateIpAddress(input: $input) { - app { - sharedIpAddress - } - } - } - "# - ), - json!({ - "appId": app_id, - "type": "shared_v4" - }), - ) - .await?; - - // Create machines in parallel - let machines = futures_util::stream::iter(0..2) - .map({ - let opts = opts.clone(); - move |_| Ok(create_machine(opts.clone())) - }) - .try_buffer_unordered(8) - .try_collect::>() - .await?; - let machine_ids = machines - .iter() - .map(|x| x.id.clone()) - .collect::>(); - - // Wait for machines to show up in list - // - // We need to check this in order to prevent a race condition with deploying a new version when - // the machines are not registered yet. Deploying a new version relies on the machine list to - // know what machines to update. - let mut attempts = 0; - loop { - tokio::time::sleep(Duration::from_secs(1)).await; - attempts += 1; - - tracing::info!(?attempts, "listing machines"); - let res = reqwest::Client::new() - .get(format!( - "https://api.machines.dev/v1/apps/{}/machines", - opts.name - )) - .bearer_auth(&opts.auth_token) - .send() - .await? - .error_for_status()? - .json::>() - .await?; - - // Check if machine exists - let listed_machine_ids = res.iter().map(|x| x.id.clone()).collect::>(); - if listed_machine_ids.is_superset(&machine_ids) { - tracing::info!(?attempts, "machine lists match"); - break; - } else { - tracing::info!( - ?listed_machine_ids, - ?machine_ids, - "machines not in list yet" - ) - } - - // Tick - if attempts > 15 { - tracing::warn!("machine did not show up in list endpoint soon enough"); - break; - } - } - - // Wait for proxy to respond to health checks - // - // We don't use native health checks since that doesn't reflect if the proxy acknowledges the - // machines yet. - let mut attempts = 0; - loop { - tokio::time::sleep(Duration::from_millis(250)).await; - attempts += 1; - - tracing::info!(?attempts, "checking health"); - let res = reqwest::Client::new() - .get(format!("https://{}.fly.dev/healthz", opts.name)) - .bearer_auth(&opts.auth_token) - .send() - .await; - match res { - Ok(x) => match x.error_for_status() { - Ok(_) => { - tracing::info!(?attempts, "health check passed"); - break; - } - Err(err) => { - tracing::info!("health check request failed: {}", err); - } - }, - Err(err) => { - tracing::info!("health check request failed: {}", err); - } - } - - // TODO: Fail worker & roll back if checks do not pass - // Tick - if attempts > 15_000 / 250 { - tracing::warn!("health check did not pass"); - break; - } - } - - Ok(app_id) -} - -#[tracing::instrument(skip(opts))] -async fn create_machine(opts: LaunchAppOpts) -> GlobalResult { - tracing::info!("creating machine"); - - let config = util_module::fly::MachineConfig { image: &opts.image }.build_machine_config(); - - // Create machine - let machine = reqwest::Client::new() - .post(format!( - "https://api.machines.dev/v1/apps/{}/machines", - opts.name - )) - .bearer_auth(&opts.auth_token) - .json(&json!({ - "region": opts.preferred_region, - "config": config, - })) - .send() - .await? - .error_for_status()? - .json::() - .await?; - tracing::info!(?machine, "machine created"); - - // Wait for machine to start - tracing::info!("waiting for machine to start"); - reqwest::Client::new() - .get(format!( - "https://api.machines.dev/v1/apps/{}/machines/{}/wait?instance_id={}&timeout=45&state=started", - opts.name, machine.id, machine.instance_id - )) - .bearer_auth(&opts.auth_token) - .send() - .await? - .error_for_status()?; - tracing::info!("machine started"); - - // We run our own manual health checks. Even if these health checks show as passing, the proxy - // may not register the machine yet. - // // Wait for health checks to pass - // // https://github.com/superfly/flyctl/blob/903ee7d4e3bb5b85c535d05fccae9db94ddcd7b5/api/machine_types.go#L380 - // let mut attempts = 0; - // loop { - // tokio::time::sleep(Duration::from_secs(1)).await; - // attempts += 1; - - // tracing::info!(?attempts, id = ?machine.id, "checking health"); - // let res = reqwest::Client::new() - // .get(format!( - // "https://api.machines.dev/v1/apps/{}/machines/{}", - // opts.name, machine.id - // )) - // .bearer_auth(&opts.auth_token) - // .send() - // .await? - // .error_for_status()? - // .json::() - // .await?; - // tracing::info!(checks = ?res.checks, "health checks"); - - // // Check health checks - // if res.checks.iter().all(|x| x.status == "pass") { - // tracing::info!("machine health checks passed"); - // break; - // } else { - // tracing::info!("machine health checks not passed yet") - // } - - // // Tick - // if attempts > 15 { - // tracing::warn!("machine health checks did not pass soon enough"); - // break; - // } - // } - - Ok(machine) -} - -fn build_app_name(instance_id: Uuid) -> String { - format!("{}-mod-{}", util::env::namespace(), instance_id) -} - -async fn graphql_request( - auth_token: &str, - query: &'static str, - req: Req, -) -> GlobalResult { - let res = reqwest::Client::new() - .post("https://api.fly.io/graphql") - .bearer_auth(auth_token) - .json(&QueryBody { - query, - variables: Variables { input: req }, - }) - .send() - .await? - .error_for_status()? - .json::>() - .await? - .data()?; - - Ok(res) -} diff --git a/svc/pkg/module/worker/src/workers/instance_destroy.rs b/svc/pkg/module/worker/src/workers/instance_destroy.rs deleted file mode 100644 index f393aa41d6..0000000000 --- a/svc/pkg/module/worker/src/workers/instance_destroy.rs +++ /dev/null @@ -1,64 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::{self, pkg::*}; - -#[worker(name = "module-instance-destroy")] -async fn worker( - ctx: &OperationContext, -) -> Result<(), GlobalError> { - let instance_id = unwrap_ref!(ctx.instance_id).as_uuid(); - - let instances = op!([ctx] module_instance_get { - instance_ids: vec![instance_id.into()], - - }) - .await?; - let instance = unwrap!(instances.instances.first()); - - // Delete app - match unwrap_ref!(instance.driver) { - backend::module::instance::Driver::Fly(fly) => { - let app_id = unwrap_ref!(fly.fly_app_id, "fly machine not started yet"); - - delete_fly_app(app_id).await?; - } - backend::module::instance::Driver::Dummy(_) => { - tracing::info!("nothing to do for dummy driver"); - } - } - - // Update database - sql_execute!( - [ctx] - " - UPDATE db_module.instances - SET destroy_ts = $2 - WHERE instance_id = $1 - ", - instance_id, - ctx.ts(), - ) - .await?; - - msg!([ctx] module::msg::instance_destroy_complete(instance_id) { - instance_id: Some(instance_id.into()), - }) - .await?; - - Ok(()) -} - -#[tracing::instrument] -async fn delete_fly_app(app_id: &str) -> GlobalResult<()> { - let fly_auth_token = util::env::read_secret(&["fly", "auth_token"]).await?; - - tracing::info!("deleting app"); - - reqwest::Client::new() - .delete(format!("https://api.machines.dev/v1/apps/{app_id}",)) - .bearer_auth(&fly_auth_token) - .send() - .await? - .error_for_status()?; - - Ok(()) -} diff --git a/svc/pkg/module/worker/src/workers/instance_version_set.rs b/svc/pkg/module/worker/src/workers/instance_version_set.rs deleted file mode 100644 index 6f2d22d9a9..0000000000 --- a/svc/pkg/module/worker/src/workers/instance_version_set.rs +++ /dev/null @@ -1,121 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::{self, pkg::*}; -use serde::Deserialize; -use serde_json::json; - -#[worker(name = "module-instance-version-set")] -async fn worker( - ctx: &OperationContext, -) -> Result<(), GlobalError> { - let instance_id = unwrap_ref!(ctx.instance_id).as_uuid(); - let version_id = unwrap_ref!(ctx.version_id).as_uuid(); - - let (instances, versions) = tokio::try_join!( - op!([ctx] module_instance_get { - instance_ids: vec![instance_id.into()], - - }), - op!([ctx] module_version_get { - version_ids: vec![version_id.into()], - }), - )?; - let instance = unwrap!(instances.instances.first()); - let version = unwrap!(versions.versions.first()); - - // Get Docker image - let image = match unwrap_ref!(version.image) { - backend::module::version::Image::Docker(docker) => docker.image_tag.as_str(), - }; - - // Update instance - match unwrap_ref!(instance.driver) { - backend::module::instance::Driver::Fly(fly) => { - let app_id = unwrap_ref!(fly.fly_app_id, "fly machine not started yet"); - - update_fly_machines(app_id, image).await?; - } - backend::module::instance::Driver::Dummy(_) => { - tracing::info!("nothing to do for dummy driver"); - } - } - - // Update database - sql_execute!( - [ctx] - " - UPDATE db_module.instances - SET version_id = $2 - WHERE instance_id = $1 - ", - instance_id, - version_id, - ) - .await?; - - msg!([ctx] module::msg::instance_version_set_complete(instance_id) { - instance_id: Some(instance_id.into()), - version_id: Some(version_id.into()), - }) - .await?; - - Ok(()) -} - -#[tracing::instrument] -async fn update_fly_machines(app_id: &str, image: &str) -> GlobalResult<()> { - let fly_auth_token = util::env::read_secret(&["fly", "auth_token"]).await?; - - let client = reqwest::Client::new(); - - tracing::info!("listing machines"); - - #[derive(Deserialize, Debug)] - struct FlyMachine { - id: String, - config: FlyMachineConfig, - } - - #[derive(Deserialize, Debug)] - struct FlyMachineConfig { - // TODO: We should be using image_ref instead for more thorough comparisons - image: String, - } - - let machines = client - .get(format!( - "https://api.machines.dev/v1/apps/{app_id}/machines", - )) - .bearer_auth(&fly_auth_token) - .send() - .await? - .error_for_status()? - .json::>() - .await?; - tracing::info!(len = machines.len(), ?machines, "fetched machines"); - - for machine in &machines { - if machine.config.image == image { - tracing::info!(id = ?machine.id, "machine already up to date"); - continue; - } - - tracing::info!(id = ?machine.id, "updating machine"); - - let config = util_module::fly::MachineConfig { image }.build_machine_config(); - - reqwest::Client::new() - .post(format!( - "https://api.machines.dev/v1/apps/{app_id}/machines/{}", - machine.id, - )) - .bearer_auth(&fly_auth_token) - .json(&json!({ - "config": config, - })) - .send() - .await? - .error_for_status()?; - } - - Ok(()) -} diff --git a/svc/pkg/module/worker/src/workers/mod.rs b/svc/pkg/module/worker/src/workers/mod.rs deleted file mode 100644 index dcc162585f..0000000000 --- a/svc/pkg/module/worker/src/workers/mod.rs +++ /dev/null @@ -1,15 +0,0 @@ -mod create; -mod instance_create; -mod instance_destroy; -mod instance_version_set; -mod ns_version_set; -mod version_create; - -chirp_worker::workers![ - create, - instance_create, - instance_destroy, - instance_version_set, - ns_version_set, - version_create, -]; diff --git a/svc/pkg/module/worker/src/workers/ns_version_set.rs b/svc/pkg/module/worker/src/workers/ns_version_set.rs deleted file mode 100644 index 4450401d3d..0000000000 --- a/svc/pkg/module/worker/src/workers/ns_version_set.rs +++ /dev/null @@ -1,193 +0,0 @@ -use std::collections::HashSet; - -use chirp_worker::prelude::*; -use proto::backend::pkg::*; - -// A note on gradual deploys: -// -// We reuse the same Fly app for each unique namespace ID & key combination -// in order ot ensure version changes are made safely. -// -// We don't use namespace ID & module IDs because there might be multiple of the same module per namespace. -// -// We don't use namespace ID & version IDs because we want a gradual deploy when changing the version. - -#[derive(Debug, sqlx::FromRow)] -struct NamespaceInstances { - key: String, - instance_id: Uuid, -} - -#[worker(name = "module-ns-version-set")] -async fn worker( - ctx: &OperationContext, -) -> GlobalResult<()> { - let namespace_id = unwrap_ref!(ctx.namespace_id).as_uuid(); - let version_id = unwrap_ref!(ctx.version_id).as_uuid(); - - // TODO: Transaction - - // Get version config - let game_versions = op!([ctx] module_game_version_get { - version_ids: vec![version_id.into()], - }) - .await?; - let Some(game_version) = game_versions - .versions - .first() - .and_then(|x| x.config.as_ref()) - else { - tracing::info!("no game version found"); - return Ok(()); - }; - - let new_version_keys = game_version - .dependencies - .iter() - .map(|x| x.key.as_str()) - .collect::>(); - - // Find all existing instances for ns - let existing_instances = sql_fetch_all!( - [ctx, NamespaceInstances] - " - SELECT key, instance_id - FROM db_module.namespace_instances - WHERE namespace_id = $1 - ", - namespace_id, - ) - .await?; - let current_version_keys = existing_instances - .iter() - .map(|x| x.key.as_str()) - .collect::>(); - - // New instances - let new_dep_keys = new_version_keys - .difference(¤t_version_keys) - .collect::>(); - for dep_key in &new_dep_keys { - let version_id = game_version - .dependencies - .iter() - .find(|x| x.key == **dep_key) - .and_then(|x| x.module_version_id) - .map(|x| x.as_uuid()); - create_instances(ctx, namespace_id, dep_key, unwrap!(version_id)).await?; - } - - // Update instances - let update_dep_keys = new_version_keys - .intersection(¤t_version_keys) - .collect::>(); - for dep_key in &update_dep_keys { - let instance_id = existing_instances - .iter() - .find(|x| x.key == **dep_key) - .map(|x| x.instance_id); - let version_id = game_version - .dependencies - .iter() - .find(|x| x.key == **dep_key) - .and_then(|x| x.module_version_id) - .map(|x| x.as_uuid()); - - update_instance(ctx.chirp(), unwrap!(instance_id), unwrap!(version_id)).await?; - } - - // Delete instances - let delete_dep_keys = current_version_keys - .difference(&new_version_keys) - .collect::>(); - for dep_key in &delete_dep_keys { - let instance_id = existing_instances - .iter() - .find(|x| x.key == **dep_key) - .map(|x| x.instance_id); - - delete_instance(ctx, namespace_id, dep_key, unwrap!(instance_id)).await?; - } - - msg!([ctx] module::msg::ns_version_set_complete(namespace_id) { - namespace_id: Some(namespace_id.into()), - version_id: Some(version_id.into()), - }) - .await?; - - Ok(()) -} - -async fn create_instances( - ctx: &OperationContext, - namespace_id: Uuid, - dep_key: &str, - version_id: Uuid, -) -> GlobalResult<()> { - // Create instance - let instance_id = Uuid::new_v4(); - msg!([ctx] module::msg::instance_create(instance_id) -> module::msg::instance_create_complete { - instance_id: Some(instance_id.into()), - module_version_id: Some(version_id.into()), - driver: Some(module::msg::instance_create::message::Driver::Fly(module::msg::instance_create::message::Fly {})), - }) - .await?; - - // Insert instance - sql_execute!( - [ctx] - " - INSERT INTO db_module.namespace_instances (namespace_id, key, instance_id) - VALUES ($1, $2, $3) - ", - namespace_id, - dep_key, - instance_id, - ) - .await?; - - Ok(()) -} - -async fn update_instance( - client: &chirp_client::Client, - instance_id: Uuid, - version_id: Uuid, -) -> GlobalResult<()> { - // Update instance - msg!([client] module::msg::instance_version_set(instance_id) -> module::msg::instance_version_set_complete { - instance_id: Some(instance_id.into()), - version_id: Some(version_id.into()), - }) - .await?; - - Ok(()) -} - -async fn delete_instance( - ctx: &OperationContext, - namespace_id: Uuid, - dep_key: &str, - instance_id: Uuid, -) -> GlobalResult<()> { - // Delete instance - msg!([ctx] module::msg::instance_destroy(instance_id) -> module::msg::instance_destroy_complete { - instance_id: Some(instance_id.into()), - }) - .await?; - - // Remove instance - sql_execute!( - [ctx] - " - DELETE FROM namespace_instances - WHERE namespace_id = $1 AND key = $2 AND instance_id = $3 - ", - namespace_id, - dep_key, - instance_id, - ) - .await?; - - Ok(()) -} diff --git a/svc/pkg/module/worker/src/workers/version_create.rs b/svc/pkg/module/worker/src/workers/version_create.rs deleted file mode 100644 index 0ec83f2fe1..0000000000 --- a/svc/pkg/module/worker/src/workers/version_create.rs +++ /dev/null @@ -1,111 +0,0 @@ -use std::convert::TryInto; - -use chirp_worker::prelude::*; -use proto::backend::pkg::*; -use serde_json::json; - -#[worker(name = "module-version-create")] -async fn worker( - ctx: &OperationContext, -) -> Result<(), GlobalError> { - let version_id = unwrap_ref!(ctx.version_id).as_uuid(); - - rivet_pools::utils::crdb::tx(&ctx.crdb().await?, |tx| { - Box::pin(update_db(ctx.clone(), tx, ctx.ts())) - }) - .await?; - - msg!([ctx] module::msg::version_create_complete(version_id) { - version_id: ctx.version_id, - }) - .await?; - - msg!([ctx] analytics::msg::event_create() { - events: vec![ - analytics::msg::event_create::Event { - event_id: Some(Uuid::new_v4().into()), - name: "module.create".into(), - properties_json: Some(serde_json::to_string(&json!({ - "user_id": ctx.creator_user_id.map(|x| x.as_uuid()), - "module_id": unwrap_ref!(ctx.module_id).as_uuid(), - "module_version_id": unwrap_ref!(ctx.version_id).as_uuid(), - }))?), - ..Default::default() - }, - ], - }) - .await?; - - Ok(()) -} - -#[tracing::instrument(skip_all)] -async fn update_db( - ctx: OperationContext, - tx: &mut sqlx::Transaction<'_, sqlx::Postgres>, - now: i64, -) -> GlobalResult<()> { - let version_id = unwrap_ref!(ctx.version_id).as_uuid(); - let module_id = unwrap_ref!(ctx.module_id).as_uuid(); - - sql_execute!( - [ctx, @tx tx] - " - INSERT INTO db_module.versions (version_id, module_id, create_ts, creator_user_id, major, minor, patch) - VALUES ($1, $2, $3, $4, $5, $6, $7) - ", - version_id, - module_id, - now, - ctx.creator_user_id.map(|x| x.as_uuid()), - TryInto::::try_into(ctx.major)?, - TryInto::::try_into(ctx.minor)?, - TryInto::::try_into(ctx.patch)?, - ) - .await?; - - match unwrap_ref!(ctx.image) { - module::msg::version_create::message::Image::Docker(docker) => { - sql_execute!( - [ctx, @tx tx] - " - INSERT INTO db_module.versions_image_docker (version_id, image_tag) - VALUES ($1, $2) - ", - version_id, - &docker.image_tag, - ) - .await?; - } - } - - for script in &ctx.scripts { - sql_execute!( - [ctx, @tx tx] - " - INSERT INTO db_module.scripts (version_id, name, request_schema, response_schema) - VALUES ($1, $2, $3, $4) - ", - version_id, - &script.name, - &script.request_schema, - &script.response_schema, - ) - .await?; - - if script.callable.is_some() { - sql_execute!( - [ctx, @tx tx] - " - INSERT INTO db_module.scripts_callable (version_id, name) - VALUES ($1, $2) - ", - version_id, - &script.name, - ) - .await?; - } - } - - Ok(()) -} diff --git a/svc/pkg/module/worker/tests/create.rs b/svc/pkg/module/worker/tests/create.rs deleted file mode 100644 index a9c13de1af..0000000000 --- a/svc/pkg/module/worker/tests/create.rs +++ /dev/null @@ -1,23 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::pkg::*; - -#[worker_test] -async fn empty(ctx: TestCtx) { - let module_id = Uuid::new_v4(); - msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete { - module_id: Some(module_id.into()), - name_id: "test".into(), - team_id: Some(Uuid::new_v4().into()), - creator_user_id: None, - }) - .await - .unwrap(); - - let (exists,): (bool,) = - sqlx::query_as("SELECT EXISTS (SELECT 1 FROM db_module.modules WHERE module_id = $1)") - .bind(module_id) - .fetch_one(&ctx.crdb().await.unwrap()) - .await - .unwrap(); - assert!(exists, "module not created"); -} diff --git a/svc/pkg/module/worker/tests/instance_create.rs b/svc/pkg/module/worker/tests/instance_create.rs deleted file mode 100644 index 7e26881acb..0000000000 --- a/svc/pkg/module/worker/tests/instance_create.rs +++ /dev/null @@ -1,108 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::{self, pkg::*}; - -#[worker_test] -async fn instance_create_dummy(ctx: TestCtx) { - if !util::feature::fly() { - return; - } - - let module_id = Uuid::new_v4(); - let version_id = Uuid::new_v4(); - let instance_id = Uuid::new_v4(); - - msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete { - module_id: Some(module_id.into()), - name_id: "test".into(), - team_id: Some(Uuid::new_v4().into()), - creator_user_id: None, - }) - .await - .unwrap(); - - msg!([ctx] module::msg::version_create(version_id) -> module::msg::version_create_complete { - version_id: Some(version_id.into()), - module_id: Some(module_id.into()), - creator_user_id: None, - - major: 1, - minor: 0, - patch: 0, - - scripts: vec![ - backend::module::Script { - name: "foo".into(), - request_schema: "{}".into(), - response_schema: "{}".into(), - callable: Some(backend::module::script::Callable {}), - }, - ], - - image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { - image_tag: "ghcr.io/rivet-gg/rivet-module-hello-world:0.0.1".into(), - })), - }) - .await - .unwrap(); - - msg!([ctx] module::msg::instance_create(instance_id) -> module::msg::instance_create_complete { - instance_id: Some(instance_id.into()), - module_version_id: Some(version_id.into()), - driver: Some(module::msg::instance_create::message::Driver::Dummy(module::msg::instance_create::message::Dummy {})), - }) - .await - .unwrap(); -} - -#[worker_test] -async fn instance_create_fly(ctx: TestCtx) { - if !util::feature::fly() { - return; - } - - let module_id = Uuid::new_v4(); - let version_id = Uuid::new_v4(); - let instance_id = Uuid::new_v4(); - - msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete { - module_id: Some(module_id.into()), - name_id: "test".into(), - team_id: Some(Uuid::new_v4().into()), - creator_user_id: None, - }) - .await - .unwrap(); - - msg!([ctx] module::msg::version_create(version_id) -> module::msg::version_create_complete { - version_id: Some(version_id.into()), - module_id: Some(module_id.into()), - creator_user_id: None, - - major: 1, - minor: 0, - patch: 0, - - scripts: vec![ - backend::module::Script { - name: "foo".into(), - request_schema: "{}".into(), - response_schema: "{}".into(), - callable: Some(backend::module::script::Callable {}), - }, - ], - - image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { - image_tag: "ghcr.io/rivet-gg/rivet-module-hello-world:0.0.1".into(), - })), - }) - .await - .unwrap(); - - msg!([ctx] module::msg::instance_create(instance_id) -> module::msg::instance_create_complete { - instance_id: Some(instance_id.into()), - module_version_id: Some(version_id.into()), - driver: Some(module::msg::instance_create::message::Driver::Fly(module::msg::instance_create::message::Fly {})), - }) - .await - .unwrap(); -} diff --git a/svc/pkg/module/worker/tests/instance_destroy.rs b/svc/pkg/module/worker/tests/instance_destroy.rs deleted file mode 100644 index 8482c0223c..0000000000 --- a/svc/pkg/module/worker/tests/instance_destroy.rs +++ /dev/null @@ -1,61 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::{self, pkg::*}; - -#[worker_test] -async fn instance_destroy_fly(ctx: TestCtx) { - if !util::feature::fly() { - return; - } - - let module_id = Uuid::new_v4(); - let version_id = Uuid::new_v4(); - let instance_id = Uuid::new_v4(); - - msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete { - module_id: Some(module_id.into()), - name_id: "test".into(), - team_id: Some(Uuid::new_v4().into()), - creator_user_id: None, - }) - .await - .unwrap(); - - msg!([ctx] module::msg::version_create(version_id) -> module::msg::version_create_complete { - version_id: Some(version_id.into()), - module_id: Some(module_id.into()), - creator_user_id: None, - - major: 1, - minor: 0, - patch: 0, - - scripts: vec![ - backend::module::Script { - name: "foo".into(), - request_schema: "{}".into(), - response_schema: "{}".into(), - callable: Some(backend::module::script::Callable {}), - }, - ], - - image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { - image_tag: "ghcr.io/rivet-gg/rivet-module-hello-world:0.0.1".into(), - })), - }) - .await - .unwrap(); - - msg!([ctx] module::msg::instance_create(instance_id) -> module::msg::instance_create_complete { - instance_id: Some(instance_id.into()), - module_version_id: Some(version_id.into()), - driver: Some(module::msg::instance_create::message::Driver::Fly(module::msg::instance_create::message::Fly {})), - }) - .await - .unwrap(); - - msg!([ctx] module::msg::instance_destroy(instance_id) -> module::msg::instance_destroy_complete { - instance_id: Some(instance_id.into()), - }) - .await - .unwrap(); -} diff --git a/svc/pkg/module/worker/tests/instance_version_set.rs b/svc/pkg/module/worker/tests/instance_version_set.rs deleted file mode 100644 index aeb2a09124..0000000000 --- a/svc/pkg/module/worker/tests/instance_version_set.rs +++ /dev/null @@ -1,94 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::{self, pkg::*}; - -#[worker_test] -async fn instance_version_set_fly(ctx: TestCtx) { - if !util::feature::fly() { - return; - } - - let module_id = Uuid::new_v4(); - let instance_id = Uuid::new_v4(); - - msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete { - module_id: Some(module_id.into()), - name_id: "test".into(), - team_id: Some(Uuid::new_v4().into()), - creator_user_id: None, - }) - .await - .unwrap(); - - // Create initial instance - { - let version_id = Uuid::new_v4(); - msg!([ctx] module::msg::version_create(version_id) -> module::msg::version_create_complete { - version_id: Some(version_id.into()), - module_id: Some(module_id.into()), - creator_user_id: None, - - major: 1, - minor: 0, - patch: 0, - - scripts: vec![ - backend::module::Script { - name: "foo".into(), - request_schema: "{}".into(), - response_schema: "{}".into(), - callable: Some(backend::module::script::Callable {}), - }, - ], - - image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { - image_tag: "ghcr.io/rivet-gg/rivet-module-hello-world:0.0.1".into(), - })), - }) - .await - .unwrap(); - - msg!([ctx] module::msg::instance_create(instance_id) -> module::msg::instance_create_complete { - instance_id: Some(instance_id.into()), - module_version_id: Some(version_id.into()), - driver: Some(module::msg::instance_create::message::Driver::Fly(module::msg::instance_create::message::Fly {})), - }) - .await - .unwrap(); - } - - // Update version - { - let version_id = Uuid::new_v4(); - msg!([ctx] module::msg::version_create(version_id) -> module::msg::version_create_complete { - version_id: Some(version_id.into()), - module_id: Some(module_id.into()), - creator_user_id: None, - - major: 1, - minor: 0, - patch: 1, - - scripts: vec![ - backend::module::Script { - name: "foo".into(), - request_schema: "{}".into(), - response_schema: "{}".into(), - callable: Some(backend::module::script::Callable {}), - }, - ], - - image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { - image_tag: "ghcr.io/rivet-gg/rivet-module-hello-world:0.0.2".into(), - })), - }) - .await - .unwrap(); - - msg!([ctx] module::msg::instance_version_set(instance_id) -> module::msg::instance_version_set_complete { - instance_id: Some(instance_id.into()), - version_id: Some(version_id.into()), - }) - .await - .unwrap(); - } -} diff --git a/svc/pkg/module/worker/tests/ns_version_set.rs b/svc/pkg/module/worker/tests/ns_version_set.rs deleted file mode 100644 index 4a70052578..0000000000 --- a/svc/pkg/module/worker/tests/ns_version_set.rs +++ /dev/null @@ -1,262 +0,0 @@ -// TODO: Modules will be removed - -// use chirp_worker::prelude::*; -// use proto::backend::{self, pkg::*}; -// use std::collections::HashMap; - -// #[worker_test] -// async fn ns_version_set(ctx: TestCtx) { -// if !util::feature::job_run() { -// return; -// } - -// let module_id = Uuid::new_v4(); - -// // Create game -// let game_res = op!([ctx] faker_game { -// ..Default::default() -// }) -// .await -// .unwrap(); -// let game_id = game_res.game_id.unwrap().as_uuid(); -// let namespace_id = game_res.namespace_ids.first().unwrap().as_uuid(); - -// // Create module -// { -// msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete { -// module_id: Some(module_id.into()), -// name_id: "test".into(), -// team_id: Some(Uuid::new_v4().into()), -// creator_user_id: None, -// }) -// .await -// .unwrap(); -// } - -// // Create fake versions -// let mv_a = create_module_version( -// &ctx, -// module_id, -// "ghcr.io/rivet-gg/rivet-module-hello-world:0.0.1", -// (0, 0, 1), -// ) -// .await; -// let mv_b = create_module_version( -// &ctx, -// module_id, -// "ghcr.io/rivet-gg/rivet-module-hello-world:0.0.2", -// (0, 0, 2), -// ) -// .await; -// let mv_c = create_module_version( -// &ctx, -// module_id, -// "ghcr.io/rivet-gg/rivet-module-hello-world:0.0.3", -// (0, 0, 3), -// ) -// .await; - -// // Deploy initial version -// let versions_a = { -// let mut create_sub = subscribe!([ctx] module::msg::instance_create("*")) -// .await -// .unwrap(); -// deploy_game_version( -// &ctx, -// game_id, -// namespace_id, -// vec![("module-a".into(), mv_a), ("module-b".into(), mv_b)], -// ) -// .await; -// create_sub.next().await.unwrap(); -// create_sub.next().await.unwrap(); - -// // Check instances created -// let versions = get_namespace_module_version(&ctx, namespace_id).await; -// assert_eq!(2, versions.len()); -// assert_eq!(mv_a, versions["module-a"].module_version_id); -// assert_eq!(mv_b, versions["module-b"].module_version_id); - -// versions -// }; - -// // Deploy new version -// let versions_b = { -// let mut update_sub = -// subscribe!([ctx] module::msg::instance_version_set(versions_a["module-a"].instance_id)) -// .await -// .unwrap(); -// deploy_game_version( -// &ctx, -// game_id, -// namespace_id, -// vec![("module-a".into(), mv_a), ("module-b".into(), mv_c)], -// ) -// .await; -// update_sub.next().await.unwrap(); - -// // Check instances updated & using same instances -// let versions = get_namespace_module_version(&ctx, namespace_id).await; -// assert_eq!(2, versions.len()); -// assert_eq!(mv_a, versions["module-a"].module_version_id); -// assert_eq!(mv_c, versions["module-b"].module_version_id); -// assert_eq!( -// versions_a["module-a"].instance_id, -// versions["module-a"].instance_id -// ); -// assert_eq!( -// versions_a["module-b"].instance_id, -// versions["module-b"].instance_id -// ); - -// versions -// }; - -// // Remove version -// let versions_c = { -// let mut destroy_sub = -// subscribe!([ctx] module::msg::instance_destroy(versions_b["module-a"].instance_id)) -// .await -// .unwrap(); -// deploy_game_version(&ctx, game_id, namespace_id, vec![("module-b".into(), mv_c)]).await; -// destroy_sub.next().await.unwrap(); - -// // Check instance removed -// let versions = get_namespace_module_version(&ctx, namespace_id).await; -// assert_eq!(1, versions.len()); -// assert_eq!(mv_c, versions["module-b"].module_version_id); -// assert_eq!( -// versions_b["module-b"].instance_id, -// versions["module-b"].instance_id -// ); - -// versions -// }; - -// // Create module A again -// { -// let mut create_sub = subscribe!([ctx] module::msg::instance_create("*")) -// .await -// .unwrap(); -// deploy_game_version( -// &ctx, -// game_id, -// namespace_id, -// vec![("module-a".into(), mv_a), ("module-b".into(), mv_c)], -// ) -// .await; -// create_sub.next().await.unwrap(); - -// // Check new instance created for module_a -// let versions = get_namespace_module_version(&ctx, namespace_id).await; -// assert_eq!(2, versions.len()); -// assert_eq!(mv_a, versions["module-a"].module_version_id); -// assert_eq!(mv_c, versions["module-b"].module_version_id); -// assert_ne!( -// versions_a["module-a"].instance_id, -// versions["module-a"].instance_id -// ); -// assert_eq!( -// versions_c["module-b"].instance_id, -// versions["module-b"].instance_id -// ); -// } -// } - -// async fn create_module_version( -// ctx: &TestCtx, -// module_id: Uuid, -// tag: &str, -// (major, minor, patch): (u64, u64, u64), -// ) -> Uuid { -// // Create module version -// let module_version_id = Uuid::new_v4(); -// msg!([ctx] module::msg::version_create(module_version_id) -> module::msg::version_create_complete { -// version_id: Some(module_version_id.into()), -// module_id: Some(module_id.into()), -// creator_user_id: None, - -// major: major, -// minor: minor, -// patch: patch, - -// scripts: vec![], - -// image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { -// image_tag: tag.to_string(), -// })), -// }) -// .await -// .unwrap(); - -// module_version_id -// } - -// async fn deploy_game_version( -// ctx: &TestCtx, -// game_id: Uuid, -// namespace_id: Uuid, -// dependencies: Vec<(String, Uuid)>, -// ) { -// // Deploy version -// let mut complete_sub = subscribe!([ctx] module::msg::ns_version_set_complete(namespace_id)) -// .await -// .unwrap(); -// op!([ctx] faker_game_version { -// game_id: Some(game_id.into()), -// deploy_to_namespace_id: Some(namespace_id.into()), -// override_module_config: Some(faker::game_version::request::OverrideModuleConfig { -// config: Some(backend::module::GameVersionConfig { -// dependencies: dependencies.into_iter().map(|(key, module_version_id)| { -// backend::module::game_version_config::Dependency { -// key, -// module_version_id: Some(module_version_id.into()), -// } -// }).collect(), -// }) -// }), -// ..Default::default() -// }) -// .await -// .unwrap(); -// complete_sub.next().await.unwrap(); -// } - -// #[derive(Debug)] -// struct NamespaceModule { -// instance_id: Uuid, -// module_version_id: Uuid, -// } - -// async fn get_namespace_module_version( -// ctx: &TestCtx, -// namespace_id: Uuid, -// ) -> HashMap { -// let versions = sqlx::query_as::<_, (String, Uuid, Uuid)>(indoc!( -// " -// SELECT ni.key, ni.instance_id, i.version_id -// FROM db_module.namespace_instances AS ni -// INNER JOIN instances AS i ON i.instance_id = ni.instance_id -// WHERE ni.namespace_id = $1 -// " -// )) -// .bind(namespace_id) -// .fetch_all(&ctx.crdb().await.unwrap()) -// .await -// .unwrap() -// .into_iter() -// .map(|(key, instance_id, module_version_id)| { -// ( -// key, -// NamespaceModule { -// instance_id, -// module_version_id, -// }, -// ) -// }) -// .collect::>(); - -// tracing::info!(?versions, "namespace module versions"); - -// versions -// } diff --git a/svc/pkg/module/worker/tests/version_create.rs b/svc/pkg/module/worker/tests/version_create.rs deleted file mode 100644 index f1726a657d..0000000000 --- a/svc/pkg/module/worker/tests/version_create.rs +++ /dev/null @@ -1,68 +0,0 @@ -use chirp_worker::prelude::*; -use proto::backend::{self, pkg::*}; - -#[worker_test] -async fn empty(ctx: TestCtx) { - let module_id = Uuid::new_v4(); - let version_id = Uuid::new_v4(); - - msg!([ctx] module::msg::create(module_id) -> module::msg::create_complete { - module_id: Some(module_id.into()), - name_id: "test".into(), - team_id: Some(Uuid::new_v4().into()), - creator_user_id: None, - }) - .await - .unwrap(); - - msg!([ctx] module::msg::version_create(version_id) -> module::msg::version_create_complete { - version_id: Some(version_id.into()), - module_id: Some(module_id.into()), - creator_user_id: None, - - major: 1, - minor: 0, - patch: 0, - - scripts: vec![ - backend::module::Script { - name: "foo".into(), - request_schema: "{}".into(), - response_schema: "{}".into(), - callable: Some(backend::module::script::Callable {}), - }, - ], - - image: Some(module::msg::version_create::message::Image::Docker(module::msg::version_create::message::Docker { - image_tag: "ghcr.io/rivet-gg/rivet-module-hello-world:latest".into(), - })), - }) - .await - .unwrap(); - - let (exists,): (bool,) = - sqlx::query_as("SELECT EXISTS (SELECT 1 FROM db_module.versions WHERE version_id = $1)") - .bind(version_id) - .fetch_one(&ctx.crdb().await.unwrap()) - .await - .unwrap(); - assert!(exists, "version not created"); - - let (exists,): (bool,) = sqlx::query_as( - "SELECT EXISTS (SELECT 1 FROM db_module.scripts WHERE version_id = $1 AND name = 'foo')", - ) - .bind(version_id) - .fetch_one(&ctx.crdb().await.unwrap()) - .await - .unwrap(); - assert!(exists, "script not created"); - - let (exists,): (bool,) = sqlx::query_as( - "SELECT EXISTS (SELECT 1 FROM db_module.scripts_callable WHERE version_id = $1 AND name = 'foo')", - ) - .bind(version_id) - .fetch_one(&ctx.crdb().await.unwrap()) - .await - .unwrap(); - assert!(exists, "script not callable"); -} diff --git a/svc/pkg/monolith/standalone/worker/Cargo.toml b/svc/pkg/monolith/standalone/worker/Cargo.toml index a475dfa6eb..047dd4eadb 100644 --- a/svc/pkg/monolith/standalone/worker/Cargo.toml +++ b/svc/pkg/monolith/standalone/worker/Cargo.toml @@ -31,7 +31,6 @@ job-run-worker = { path = "../../../job-run/worker" } kv-worker = { path = "../../../kv/worker" } linode-worker = { path = "../../../linode/worker" } mm-worker = { path = "../../../mm/worker" } -module-worker = { path = "../../../module/worker" } team-invite-worker = { path = "../../../team-invite/worker" } team-worker = { path = "../../../team/worker" } upload-worker = { path = "../../../upload/worker" } diff --git a/svc/pkg/monolith/standalone/worker/src/lib.rs b/svc/pkg/monolith/standalone/worker/src/lib.rs index ef05786e62..4cb67dfb01 100644 --- a/svc/pkg/monolith/standalone/worker/src/lib.rs +++ b/svc/pkg/monolith/standalone/worker/src/lib.rs @@ -33,7 +33,6 @@ pub async fn run_from_env(pools: rivet_pools::Pools) -> GlobalResult<()> { kv_worker, linode_worker, mm_worker, - module_worker, team_invite_worker, team_worker, upload_worker,