From f5c5f734e1fea968294cfe02f93e60cabebbf5ee Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Wed, 1 Mar 2023 21:18:40 +0000 Subject: [PATCH] clean deployment / build config before update --- core/src/actions/build.rs | 12 ++++++++ core/src/actions/deployment.rs | 29 ++++++++++++++++++- core/src/helpers.rs | 12 ++++++++ .../deployment/tabs/config/Config.tsx | 3 -- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/core/src/actions/build.rs b/core/src/actions/build.rs index ed5cd7cdc..3c2281337 100644 --- a/core/src/actions/build.rs +++ b/core/src/actions/build.rs @@ -15,6 +15,7 @@ use crate::{ cloud::aws::{ self, create_ec2_client, create_instance_with_ami, terminate_ec2_instance, Ec2Instance, }, + helpers::empty_or_only_spaces, state::State, }; @@ -187,6 +188,17 @@ impl State { new_build.created_at = current_build.created_at.clone(); new_build.updated_at = start_ts.clone(); + // filter out any build args that contain empty strings + // these could only happen by accident + new_build.docker_build_args = new_build.docker_build_args.map(|mut args| { + args.build_args = args + .build_args + .into_iter() + .filter(|a| !empty_or_only_spaces(&a.variable) && !empty_or_only_spaces(&a.value)) + .collect(); + args + }); + self.db .builds .update_one(&new_build.id, mungos::Update::Regular(new_build.clone())) diff --git a/core/src/actions/deployment.rs b/core/src/actions/deployment.rs index 67ffbb733..ea2ad0720 100644 --- a/core/src/actions/deployment.rs +++ b/core/src/actions/deployment.rs @@ -9,7 +9,7 @@ use types::{ use crate::{ auth::RequestUser, - helpers::{any_option_diff_is_some, get_image_name, option_diff_is_some}, + helpers::{any_option_diff_is_some, empty_or_only_spaces, get_image_name, option_diff_is_some}, state::State, }; @@ -197,6 +197,33 @@ impl State { new_deployment.created_at = current_deployment.created_at.clone(); new_deployment.updated_at = start_ts.clone(); + // filter out any volumes, ports, env vars, extra args which are or contain empty strings + // these could only happen by accident + new_deployment.docker_run_args.volumes = new_deployment + .docker_run_args + .volumes + .into_iter() + .filter(|v| !empty_or_only_spaces(&v.local) && !empty_or_only_spaces(&v.container)) + .collect(); + new_deployment.docker_run_args.ports = new_deployment + .docker_run_args + .ports + .into_iter() + .filter(|p| !empty_or_only_spaces(&p.local) && !empty_or_only_spaces(&p.container)) + .collect(); + new_deployment.docker_run_args.environment = new_deployment + .docker_run_args + .environment + .into_iter() + .filter(|e| !empty_or_only_spaces(&e.variable) && !empty_or_only_spaces(&e.value)) + .collect(); + new_deployment.docker_run_args.extra_args = new_deployment + .docker_run_args + .extra_args + .into_iter() + .filter(|a| a.len() != 0) + .collect(); + self.db .deployments .update_one( diff --git a/core/src/helpers.rs b/core/src/helpers.rs index dfdb1cdbb..fad1189cc 100644 --- a/core/src/helpers.rs +++ b/core/src/helpers.rs @@ -54,3 +54,15 @@ pub fn get_image_name(build: &Build) -> String { }, } } + +pub fn empty_or_only_spaces(word: &str) -> bool { + if word.len() == 0 { + return true; + } + for char in word.chars() { + if char != ' ' { + return false; + } + } + return true; +} diff --git a/frontend/src/components/deployment/tabs/config/Config.tsx b/frontend/src/components/deployment/tabs/config/Config.tsx index 188dc056d..a2d10605e 100644 --- a/frontend/src/components/deployment/tabs/config/Config.tsx +++ b/frontend/src/components/deployment/tabs/config/Config.tsx @@ -17,8 +17,6 @@ import { Tab } from "../../../shared/tabs/Tabs"; import RepoMount from "./mount-repo/RepoMount"; import { OnClone, OnPull } from "./mount-repo/OnGit"; import Loading from "../../../shared/loading/Loading"; -import { pushNotification, MONITOR_BASE_URL } from "../../../.."; -import { combineClasses, copyToClipboard, getId } from "../../../../util/helpers"; import { useAppDimensions } from "../../../../state/DimensionProvider"; import SimpleTabs from "../../../shared/tabs/SimpleTabs"; import ExtraArgs from "./container/ExtraArgs"; @@ -27,7 +25,6 @@ import WebhookUrl from "./container/WebhookUrl"; const Config: Component<{}> = () => { const { deployment, reset, save, userCanUpdate } = useConfig(); const { isMobile } = useAppDimensions(); - const listenerUrl = () => `${MONITOR_BASE_URL}/api/listener/deployment/${getId(deployment)}`; return (