Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
chore: add back loading config
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Jul 20, 2024
1 parent 8dc0d48 commit 88a8086
Show file tree
Hide file tree
Showing 480 changed files with 15,554 additions and 15,265 deletions.
13 changes: 11 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rivet-toolchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository = "https://github.com/rivet-gg/cli"
async-posthog = { git = "https://github.com/rivet-gg/posthog-rs.git", rev = "ef4e80e" }
async-stream = "0.3.3"
chrono = "0.4.21"
config = { version = "0.14", default-features = false, features = ["json", "async"] }
config = { git = "https://github.com/rivet-gg/config-rs", rev = "0f3c89b4770276e8db72ce962974a9a72c59c97a", default-features = false, features = ["json", "async"] }
console = "0.15"
ctrlc = { version = "3.2", features = ["termination"] }
dirs = "5.0"
Expand Down
28 changes: 28 additions & 0 deletions rivet-toolchain/src/tasks/check_requirements.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use global_error::prelude::*;
use serde::{Deserialize, Serialize};

use crate::util::task::TaskCtx;

#[derive(Deserialize)]
pub struct Input {
path: String,
}

#[derive(Serialize)]
pub struct Output {}

pub struct Task;

impl super::Task for Task {
type Input = Input;
type Output = Output;

fn name() -> &'static str {
"check_requirements"
}

async fn run(_task: TaskCtx, input: Self::Input) -> GlobalResult<Self::Output> {
// TODO:
Ok(Output {})
}
}
86 changes: 82 additions & 4 deletions rivet-toolchain/src/tasks/deploy/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ use std::{
};
use tokio::fs;

use crate::{backend, config, ctx::Ctx, util::net::upload, util::task::TaskCtx};
use crate::{
backend, config,
ctx::Ctx,
util::task::TaskCtx,
util::{net::upload, term},
};

pub struct DeployOpts {
/// Game ID being deployed to.
pub game_id: String,

/// The environment to deploy to.
pub environment_id: String,

Expand Down Expand Up @@ -39,6 +47,74 @@ pub async fn deploy(ctx: &Ctx, task: TaskCtx, opts: DeployOpts) -> GlobalResult<
.await?
.environment;

// TODO: re-apply both service token and endpoint if endpoint diff than one that's deployed
task.log_stdout(format!("[Fetching Environment Variables]"));
// let variables =
// apis::ee_cloud_backend_projects_envs_api::ee_cloud_backend_projects_envs_get_variables(
// &ctx.openapi_config_cloud,
// &project_id_str,
// &environment_id_str,
// )
// .await?
// .variables;
let mut update_variables = HashMap::<String, _>::new();
// if !variables.contains_key("OPENGB_PUBLIC_ENDPOINT") {
// TODO: pull this from the server
let public_endpoint = format!(
"https://{}--{}.backend.nathan16.gameinc.io",
project.name_id, env.name_id
);
update_variables.insert(
"OPENGB_PUBLIC_ENDPOINT".to_string(),
models::EeBackendUpdateVariable {
text: Some(public_endpoint),
..Default::default()
},
);
// }
// if !variables.contains_key("RIVET_API_ENDPOINT") {
update_variables.insert(
"RIVET_API_ENDPOINT".to_string(),
models::EeBackendUpdateVariable {
text: Some(ctx.api_endpoint.clone()),
..Default::default()
},
);
// }
// if !variables.contains_key("RIVET_SERVICE_TOKEN") {
let service_token = apis::cloud_games_tokens_api::cloud_games_tokens_create_service_token(
&ctx.openapi_config_cloud,
&opts.game_id,
)
.await?;
update_variables.insert(
"RIVET_SERVICE_TOKEN".to_string(),
models::EeBackendUpdateVariable {
secret: Some(service_token.token),
..Default::default()
},
);
// }
// if !update_variables.is_empty() {
task.log_stdout(format!(
"[Updating Environment Variables] {}",
update_variables
.keys()
.cloned()
.collect::<Vec<_>>()
.join(", ")
));
apis::ee_cloud_backend_projects_envs_api::ee_cloud_backend_projects_envs_update_variables(
&ctx.openapi_config_cloud,
&project_id_str,
&environment_id_str,
models::EeCloudBackendProjectsEnvsUpdateVariablesRequest {
variables: update_variables,
},
)
.await?;
// }

task.log_stdout(format!("[Building Project] {}", project_path.display()));

// Build
Expand Down Expand Up @@ -144,12 +220,13 @@ pub async fn deploy(ctx: &Ctx, task: TaskCtx, opts: DeployOpts) -> GlobalResult<

// Upload files
let reqwest_client = Arc::new(reqwest::Client::new());
// let pb = term::EitherProgressBar::Multi(indicatif::MultiProgress::new());
let pb = term::EitherProgressBar::Multi(term::multi_progress_bar(task.clone()));

futures_util::stream::iter(prepare_res.presigned_requests)
.map(Ok)
.try_for_each_concurrent(8, |presigned_req| {
// let pb = pb.clone();
let task = task.clone();
let pb = pb.clone();
let files = files.clone();
let reqwest_client = reqwest_client.clone();

Expand All @@ -161,11 +238,12 @@ pub async fn deploy(ctx: &Ctx, task: TaskCtx, opts: DeployOpts) -> GlobalResult<
);

upload::upload_file(
task.clone(),
&reqwest_client,
&presigned_req,
&file.absolute_path,
file.prepared.content_type.as_ref(),
// pb,
pb,
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion rivet-toolchain/src/tasks/deploy/game_server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use global_error::prelude::*;
use std::{path::Path};
use std::path::Path;
use uuid::Uuid;

use crate::{
Expand Down
2 changes: 2 additions & 0 deletions rivet-toolchain/src/tasks/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ impl super::Task for Task {
&ctx,
task.clone(),
backend::DeployOpts {
game_id: ctx.game_id.clone(),
environment_id: input.environment_id.clone(),
project_path: input.cwd.clone(),
// TODO:
skip_migrate: true,
},
)
Expand Down
13 changes: 8 additions & 5 deletions rivet-toolchain/src/util/docker/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use uuid::Uuid;
use crate::{
config,
ctx::Ctx,
util::{net::upload, task::TaskCtx},
util::{net::upload, task::TaskCtx, term},
};

use super::{BuildCompression, BuildKind};
Expand Down Expand Up @@ -85,22 +85,24 @@ pub async fn push_tar(ctx: &Ctx, task: TaskCtx, push_opts: &PushOpts) -> GlobalR
}
let build_res = unwrap!(build_res,);
let image_id = build_res.build_id;
// let pb = term::EitherProgressBar::Multi(indicatif::MultiProgress::new());
let pb = term::EitherProgressBar::Multi(term::multi_progress_bar(task.clone()));

if multipart_enabled {
// Upload chunks in parallel
futures_util::stream::iter(build_res.image_presigned_requests.unwrap())
.map(|presigned_request| {
let task = task.clone();
let reqwest_client = reqwest_client.clone();
// let pb = pb.clone();
let pb = pb.clone();

async move {
upload::upload_file(
task.clone(),
&reqwest_client,
&presigned_request,
&push_opts.path,
Some(content_type),
// pb,
pb,
)
.await
}
Expand All @@ -111,11 +113,12 @@ pub async fn push_tar(ctx: &Ctx, task: TaskCtx, push_opts: &PushOpts) -> GlobalR
} else {
// Upload file
upload::upload_file(
task.clone(),
&reqwest_client,
&build_res.image_presigned_request.unwrap(),
&push_opts.path,
Some(content_type),
// pb,
pb,
)
.await?;
}
Expand Down
2 changes: 2 additions & 0 deletions rivet-toolchain/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pub mod net;
pub mod os;
pub mod show_term;
pub mod task;
pub mod term;

Loading

0 comments on commit 88a8086

Please sign in to comment.