Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/core/src/stack/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions bin/periphery/src/api/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,14 @@ impl Resolve<super::Args> 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
Expand Down
6 changes: 5 additions & 1 deletion bin/periphery/src/compose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions client/core/rs/src/entities/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,11 @@ pub struct StackConfig {
#[builder(default)]
pub build_extra_args: Vec<String>,

/// 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`
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions client/core/ts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/components/resources/stack/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,24 @@ export const StackConfig = ({
),
},
},
{
label: "Remove Volumes",
labelHidden: true,
components: {
remove_volumes: (value, set) => {
return (
<ConfigSwitch
label="Remove Volumes"
description="Add '--volumes' to docker compose down to remove named and anonymous volumes."
value={value}
onChange={(remove_volumes) => set({ remove_volumes })}
disabled={disabled}
/>
);
},
},
},

{
label: "Ignore Services",
labelHidden: true,
Expand Down