diff --git a/bin/core/src/api/execute/stack.rs b/bin/core/src/api/execute/stack.rs index 8eabe4ab2..d7d86654d 100644 --- a/bin/core/src/api/execute/stack.rs +++ b/bin/core/src/api/execute/stack.rs @@ -16,7 +16,7 @@ use crate::{ interpolate_variables_secrets_into_environment, periphery_client, stack::{ execute::execute_compose, get_stack_and_server, - json::get_config_jsons, services::extract_services_into_res, + services::extract_services_into_res, }, update::update_update, }, @@ -91,11 +91,7 @@ impl Resolve for State { update.logs.extend(logs); let update_info = async { - let (latest_services, json, json_errors) = if !file_contents - .is_empty() - { - let (jsons, json_errors) = - get_config_jsons(&file_contents).await; + let latest_services = if !file_contents.is_empty() { let mut services = Vec::new(); for contents in &file_contents { if let Err(e) = extract_services_into_res( @@ -109,10 +105,10 @@ impl Resolve for State { ); } } - (services, jsons, json_errors) + services } else { // maybe better to do something else here for services. - (stack.info.latest_services.clone(), Vec::new(), Vec::new()) + stack.info.latest_services.clone() }; let project_name = stack.project_name(true); @@ -120,16 +116,12 @@ impl Resolve for State { let ( deployed_services, deployed_contents, - deployed_json, - deployed_json_errors, deployed_hash, deployed_message, ) = if deployed { ( Some(latest_services.clone()), Some(file_contents.clone()), - Some(json.clone()), - Some(json_errors.clone()), commit_hash.clone(), commit_message.clone(), ) @@ -137,8 +129,6 @@ impl Resolve for State { ( stack.info.deployed_services, stack.info.deployed_contents, - stack.info.deployed_json, - stack.info.deployed_json_errors, stack.info.deployed_hash, stack.info.deployed_message, ) @@ -151,11 +141,7 @@ impl Resolve for State { deployed_contents, deployed_hash, deployed_message, - deployed_json, - deployed_json_errors, latest_services, - latest_json: json, - latest_json_errors: json_errors, remote_contents: stack .config .file_contents diff --git a/bin/core/src/api/write/stack.rs b/bin/core/src/api/write/stack.rs index 8a97082fa..8288da9ce 100644 --- a/bin/core/src/api/write/stack.rs +++ b/bin/core/src/api/write/stack.rs @@ -6,7 +6,7 @@ use monitor_client::{ config::core::CoreConfig, monitor_timestamp, permission::PermissionLevel, - stack::{ComposeContents, PartialStackConfig, Stack, StackInfo}, + stack::{PartialStackConfig, Stack, StackInfo}, update::Update, user::User, NoData, Operation, @@ -25,7 +25,7 @@ use crate::{ config::core_config, helpers::{ stack::{ - json::get_config_jsons, remote::get_remote_compose_contents, + remote::get_remote_compose_contents, services::extract_services_into_res, }, update::{add_update, make_update}, @@ -176,7 +176,11 @@ impl Resolve for State { } impl Resolve for State { - #[instrument(name = "RefreshStackCache", level = "debug", skip(self, user))] + #[instrument( + name = "RefreshStackCache", + level = "debug", + skip(self, user) + )] async fn resolve( &self, RefreshStackCache { stack }: RefreshStackCache, @@ -202,8 +206,6 @@ impl Resolve for State { let ( latest_services, - latest_json, - latest_json_errors, remote_contents, remote_errors, latest_hash, @@ -237,13 +239,8 @@ impl Resolve for State { } } - let (jsons, json_errors) = - get_config_jsons(&remote_contents).await; - ( services, - jsons, - json_errors, Some(remote_contents), Some(remote_errors), latest_hash, @@ -263,19 +260,7 @@ impl Resolve for State { ); services.extend(stack.info.latest_services); }; - let (json, json_errors) = - get_config_jsons(&[ComposeContents { - path: stack - .config - .file_paths - .first() - .map(String::as_str) - .unwrap_or("compose.yaml") - .to_string(), - contents: stack.config.file_contents, - }]) - .await; - (services, json, json_errors, None, None, None, None) + (services, None, None, None, None) }; let info = StackInfo { @@ -285,11 +270,7 @@ impl Resolve for State { deployed_contents: stack.info.deployed_contents, deployed_hash: stack.info.deployed_hash, deployed_message: stack.info.deployed_message, - deployed_json: stack.info.deployed_json, - deployed_json_errors: stack.info.deployed_json_errors, latest_services, - latest_json, - latest_json_errors, remote_contents, remote_errors, latest_hash, diff --git a/bin/core/src/helpers/stack/json.rs b/bin/core/src/helpers/stack/json.rs deleted file mode 100644 index e755209be..000000000 --- a/bin/core/src/helpers/stack/json.rs +++ /dev/null @@ -1,80 +0,0 @@ -use anyhow::Context; -use formatting::format_serror; -use monitor_client::entities::stack::ComposeContents; -use run_command::async_run_command; -use tokio::fs; - -use crate::{config::core_config, helpers::random_string}; - -// Returns (Jsons, Errors) -pub async fn get_config_jsons( - contents: &[ComposeContents], -) -> (Vec, Vec) { - let mut oks = Vec::new(); - let mut errs = Vec::new(); - for contents in contents { - match get_config_json(&contents.contents).await { - (Some(json), _) => oks.push(ComposeContents { - path: contents.path.to_string(), - contents: json, - }), - (_, Some(err)) => errs.push(ComposeContents { - path: contents.path.to_string(), - contents: err, - }), - _ => unreachable!(), - } - } - (oks, errs) -} - -pub async fn get_config_json( - compose_contents: &str, -) -> (Option, Option) { - match get_config_json_inner(compose_contents).await { - Ok(res) => (Some(res), None), - Err(e) => ( - None, - Some(format_serror( - &e.context("failed to get config json").into(), - )), - ), - } -} - -async fn get_config_json_inner( - compose_contents: &str, -) -> anyhow::Result { - // create a new folder to prevent collisions - let dir = core_config().repo_directory.join(random_string(10)); - - fs::create_dir_all(&dir) - .await - .context("failed to create compose file directory")?; - let file = dir.join("compose.yaml"); - - fs::write(&file, compose_contents).await.with_context(|| { - format!("failed to write compose contents to file file: {file:?}") - })?; - - let res = async_run_command(&format!( - "cd {} && docker-compose config --format json", - dir.display() - )) - .await; - - // Don't fail the function call here, just log on this maintenance related information. - fs::remove_dir_all(&dir) - .await - .with_context(|| { - format!("failed to clean up compose directory: {dir:?}") - }) - .inspect_err(|e| error!("{e:#}")) - .ok(); - - if res.success() { - Ok(res.stdout) - } else { - Err(anyhow::Error::msg(res.stderr)) - } -} diff --git a/bin/core/src/helpers/stack/mod.rs b/bin/core/src/helpers/stack/mod.rs index cf322b768..a9c7fad45 100644 --- a/bin/core/src/helpers/stack/mod.rs +++ b/bin/core/src/helpers/stack/mod.rs @@ -22,7 +22,6 @@ use crate::{ use super::query::get_server_with_status; pub mod execute; -pub mod json; pub mod remote; pub mod services; diff --git a/client/core/rs/src/entities/stack.rs b/client/core/rs/src/entities/stack.rs index e7220267d..25545a14a 100644 --- a/client/core/rs/src/entities/stack.rs +++ b/client/core/rs/src/entities/stack.rs @@ -138,24 +138,12 @@ pub struct StackInfo { pub deployed_hash: Option, /// Deployed commit message, or null. Only for repo based stacks pub deployed_message: Option, - /// Cached json representation of the deployed compose file contents - /// Obtained by calling `docker compose config`. Will be of the deployed config if it exists. - pub deployed_json: Option>, - /// If there was an error in calling `docker compose config`, the message will be here with the associated file path. - pub deployed_json_errors: Option>, /// The deployed compose file contents. This is updated whenever Monitor successfully deploys the stack. pub deployed_contents: Option>, /// The deployed service names. /// This is updated whenever it is empty, or deployed contents is updated. pub deployed_services: Option>, - /// Cached json representation of the compose file contents. - /// Obtained by calling `docker compose config`. Will be of the latest config, not the deployed config. - #[serde(default)] - pub latest_json: Vec, - /// If there was an error in calling `docker compose config` on the latest contents, the message will be here - #[serde(default)] - pub latest_json_errors: Vec, /// The latest service names. /// This is updated whenever the stack cache refreshes, using the latest file contents (either db defined or remote). #[serde(default)] diff --git a/client/core/ts/src/types.ts b/client/core/ts/src/types.ts index 252ef1cd6..b4841bd30 100644 --- a/client/core/ts/src/types.ts +++ b/client/core/ts/src/types.ts @@ -1566,13 +1566,6 @@ export interface StackInfo { deployed_hash?: string; /** Deployed commit message, or null. Only for repo based stacks */ deployed_message?: string; - /** - * Cached json representation of the deployed compose file contents - * Obtained by calling `docker compose config`. Will be of the deployed config if it exists. - */ - deployed_json?: ComposeContents[]; - /** If there was an error in calling `docker compose config`, the message will be here with the associated file path. */ - deployed_json_errors?: ComposeContents[]; /** The deployed compose file contents. This is updated whenever Monitor successfully deploys the stack. */ deployed_contents?: ComposeContents[]; /** @@ -1580,13 +1573,6 @@ export interface StackInfo { * This is updated whenever it is empty, or deployed contents is updated. */ deployed_services?: StackServiceNames[]; - /** - * Cached json representation of the compose file contents. - * Obtained by calling `docker compose config`. Will be of the latest config, not the deployed config. - */ - latest_json?: ComposeContents[]; - /** If there was an error in calling `docker compose config` on the latest contents, the message will be here */ - latest_json_errors?: ComposeContents[]; /** * The latest service names. * This is updated whenever the stack cache refreshes, using the latest file contents (either db defined or remote). diff --git a/frontend/src/components/resources/stack/info.tsx b/frontend/src/components/resources/stack/info.tsx index 73ff2473b..d0f7c8bc3 100644 --- a/frontend/src/components/resources/stack/info.tsx +++ b/frontend/src/components/resources/stack/info.tsx @@ -25,7 +25,6 @@ export const StackInfo = ({ {stack?.info?.deployed_contents?.map((content) => (
                 path: {content.path}
-                
                 
{content.contents}
))} @@ -72,20 +71,6 @@ export const StackInfo = ({ )} - {stack?.info?.latest_json_errors && - stack?.info?.latest_json_errors.length > 0 && ( - - - parsing errors:{" "} - {stack?.info?.latest_json_errors?.map((content) => ( -
-                  path: {content.path}
-                  
{content.contents}
-
- ))} -
-
- )} ); };