From 235bb8eeb1ab74a31e60790185ba7a4a1c85f74b Mon Sep 17 00:00:00 2001 From: cassius23 Date: Fri, 9 Jan 2026 13:04:39 +0100 Subject: [PATCH] Add remove_volumes flag to Stack config Revert unwanted change --- bin/core/src/stack/execute.rs | 7 ++++++- bin/periphery/src/api/compose.rs | 11 ++++++++--- bin/periphery/src/compose/mod.rs | 6 +++++- client/core/rs/src/entities/stack.rs | 6 ++++++ client/core/ts/src/types.ts | 4 ++++ .../src/components/resources/stack/config.tsx | 18 ++++++++++++++++++ 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/bin/core/src/stack/execute.rs b/bin/core/src/stack/execute.rs index 202992d63..ee0900368 100644 --- a/bin/core/src/stack/execute.rs +++ b/bin/core/src/stack/execute.rs @@ -194,11 +194,16 @@ impl ExecuteCompose for DestroyStack { } else { "" }; + let maybe_volumes = if stack.config.remove_volumes { + " --volumes" + } else { + "" + }; periphery .request(ComposeExecution { project: stack.project_name(false), command: format!( - "down{maybe_timeout}{maybe_remove_orphans}{service_args}" + "down{maybe_timeout}{maybe_remove_orphans}{maybe_volumes}{service_args}" ), }) .await diff --git a/bin/periphery/src/api/compose.rs b/bin/periphery/src/api/compose.rs index 95c262a27..3f846bc58 100644 --- a/bin/periphery/src/api/compose.rs +++ b/bin/periphery/src/api/compose.rs @@ -634,9 +634,14 @@ impl Resolve for ComposeUp { { // Take down the existing containers. // This one tries to use the previously deployed service name, to ensure the right stack is taken down. - crate::compose::down(&last_project_name, &services, &mut res) - .await - .context("failed to destroy existing containers")?; + crate::compose::down( + &last_project_name, + &services, + stack.config.remove_volumes, + &mut res, + ) + .await + .context("failed to destroy existing containers")?; } // Run compose up diff --git a/bin/periphery/src/compose/mod.rs b/bin/periphery/src/compose/mod.rs index 856fc8bc2..78d380fe0 100644 --- a/bin/periphery/src/compose/mod.rs +++ b/bin/periphery/src/compose/mod.rs @@ -56,6 +56,7 @@ pub fn env_file_args( pub async fn down( project: &str, services: &[String], + remove_volumes: bool, res: &mut ComposeUpResponse, ) -> anyhow::Result<()> { let docker_compose = docker_compose(); @@ -64,10 +65,13 @@ pub async fn down( } else { format!(" {}", services.join(" ")) }; + let maybe_volumes = if remove_volumes { " --volumes" } else { "" }; let log = run_komodo_command( "Compose Down", None, - format!("{docker_compose} -p {project} down{service_args}"), + format!( + "{docker_compose} -p {project} down{maybe_volumes}{service_args}" + ), ) .await; let success = log.success; diff --git a/client/core/rs/src/entities/stack.rs b/client/core/rs/src/entities/stack.rs index 16b742f77..caa85ce10 100644 --- a/client/core/rs/src/entities/stack.rs +++ b/client/core/rs/src/entities/stack.rs @@ -503,6 +503,11 @@ pub struct StackConfig { #[builder(default)] pub build_extra_args: Vec, + /// Whether to add `--volumes` flag to `docker compose down` to remove named and anonymous volumes. + #[serde(default)] + #[builder(default)] + pub remove_volumes: bool, + /// Ignore certain services declared in the compose file when checking /// the stack status. For example, an init service might be exited, but the /// stack should be healthy. This init service should be in `ignore_services` @@ -605,6 +610,7 @@ impl Default for StackConfig { run_build: Default::default(), destroy_before_deploy: Default::default(), build_extra_args: Default::default(), + remove_volumes: Default::default(), skip_secret_interp: Default::default(), linked_repo: Default::default(), git_provider: default_git_provider(), diff --git a/client/core/ts/src/types.ts b/client/core/ts/src/types.ts index 248fbed4c..a0477f5f9 100644 --- a/client/core/ts/src/types.ts +++ b/client/core/ts/src/types.ts @@ -2257,6 +2257,10 @@ export interface StackConfig { * Only used if `run_build: true` */ build_extra_args?: string[]; + /** + * Whether to append `--volumes` when doing `docker compose down`. + */ + remove_volumes?: boolean; /** * Ignore certain services declared in the compose file when checking * the stack status. For example, an init service might be exited, but the diff --git a/frontend/src/components/resources/stack/config.tsx b/frontend/src/components/resources/stack/config.tsx index 2af22c910..2c386d421 100644 --- a/frontend/src/components/resources/stack/config.tsx +++ b/frontend/src/components/resources/stack/config.tsx @@ -409,6 +409,24 @@ export const StackConfig = ({ ), }, }, + { + label: "Remove Volumes", + labelHidden: true, + components: { + remove_volumes: (value, set) => { + return ( + set({ remove_volumes })} + disabled={disabled} + /> + ); + }, + }, + }, + { label: "Ignore Services", labelHidden: true,