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

Commit

Permalink
chore: check system requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Jul 21, 2024
1 parent e4a227a commit 1ad47f6
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 28 deletions.
28 changes: 0 additions & 28 deletions rivet-toolchain/src/tasks/check_requirements.rs

This file was deleted.

95 changes: 95 additions & 0 deletions rivet-toolchain/src/tasks/check_system_requirements.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use global_error::prelude::*;
use serde::{Deserialize, Serialize};
use std::time::Duration;

use crate::util::{cmd::shell_cmd, task::TaskCtx};

#[derive(Deserialize)]
pub struct Input {}

#[derive(Serialize)]
pub struct Output {
errors: Vec<RequirementError>,
}

#[derive(Serialize)]
pub struct RequirementError {
title: String,
body: String,
docs_url: Option<String>,
}

pub struct Task;

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

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

async fn run(_task: TaskCtx, _input: Self::Input) -> GlobalResult<Self::Output> {
let mut errors = Vec::new();

// Docker
match tokio::time::timeout(
Duration::from_secs(5),
shell_cmd("docker").arg("info").kill_on_drop(true).output(),
)
.await
{
Ok(Ok(output)) => {
if !output.status.success() {
if output.status.code() == Some(127) {
errors.push(errors::docker_not_found());
} else {
errors.push(RequirementError {
title: "Docker Failed".into(),
body: format!(
"Exit code: {}\n\n{}",
output
.status
.code()
.map_or_else(|| "?".to_string(), |x| x.to_string()),
String::from_utf8_lossy(&output.stderr).to_string()
),
docs_url: None,
});
}
}
}
Ok(Err(err)) if err.kind() == std::io::ErrorKind::NotFound => {
errors.push(errors::docker_not_found())
}
Ok(Err(err)) => {
errors.push(RequirementError {
title: "Docker Command Error".into(),
body: err.to_string(),
docs_url: Some("https://docs.docker.com/get-docker/".into()),
});
}
Err(_) => {
errors.push(RequirementError {
title: "Docker Command Timed Out".into(),
body: "Docker may be paused. Try restarting Docker.".into(),
docs_url: None,
});
}
}

Ok(Output { errors })
}
}

mod errors {
use super::RequirementError;

pub fn docker_not_found() -> RequirementError {
RequirementError {
title: "Install Docker".into(),
body: "Docker is required to build & run the game server & backend.".into(),
docs_url: Some("https://docs.docker.com/get-docker/".into()),
}
}
}
2 changes: 2 additions & 0 deletions rivet-toolchain/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod backend_choose_local_port;
pub mod backend_dev;
pub mod backend_sdk_gen;
pub mod check_login_state;
pub mod check_system_requirements;
pub mod deploy;
pub mod exec_command;
pub mod get_bootstrap_data;
Expand Down Expand Up @@ -77,6 +78,7 @@ gen_run_task!(
backend_dev::Task,
backend_sdk_gen::Task,
check_login_state::Task,
check_system_requirements::Task,
deploy::Task,
exec_command::Task,
get_bootstrap_data::Task,
Expand Down

0 comments on commit 1ad47f6

Please sign in to comment.