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
12 changes: 12 additions & 0 deletions src-tauri/src/api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3306,6 +3306,17 @@ async fn api_compose_logs(
}
}

async fn api_compose_stop(
Json(body): Json<ComposeProjectBody>,
) -> (StatusCode, Json<ApiResponse<String>>) {
match run_blocking(move || run_cmd("docker", &["compose", "-p", &body.project_name, "stop"]))
.await
{
Ok(out) => ok(out),
Err(e) => err(e),
}
}

async fn api_compose_ps(
Query(q): Query<ComposePsQuery>,
) -> (StatusCode, Json<ApiResponse<String>>) {
Expand Down Expand Up @@ -3394,6 +3405,7 @@ pub fn build_router() -> Router {
.route("/api/compose/up", post(api_compose_up))
.route("/api/compose/down", post(api_compose_down))
.route("/api/compose/restart", post(api_compose_restart))
.route("/api/compose/stop", post(api_compose_stop))
.route("/api/compose/logs", get(api_compose_logs))
.route("/api/compose/ps", get(api_compose_ps))
// Kubernetes
Expand Down
15 changes: 15 additions & 0 deletions src-tauri/src/commands/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ pub async fn compose_logs(project_name: String, lines: u32) -> Result<String, St
Ok(combined)
}

/// Stop a Docker Compose project (stops containers without removing them)
#[tauri::command]
pub async fn compose_stop(project_name: String) -> Result<String, String> {
let output = docker_output(vec!["compose".into(), "-p".into(), project_name.clone(), "stop".into()]).await?;

if !output.status.success() {
return Err(format!(
"docker compose stop failed: {}",
String::from_utf8_lossy(&output.stderr)
));
}

Ok(format!("Compose project '{}' stopped", project_name))
}

/// List services in a compose project
#[tauri::command]
pub async fn compose_ps(project_name: String) -> Result<String, String> {
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub fn run() {
compose::compose_restart,
compose::compose_logs,
compose::compose_ps,
compose::compose_stop,
// Kubernetes commands
kubernetes::k8s_check,
kubernetes::k8s_namespaces,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ export const composeApi = {
call<string>("compose_down", { projectName }, "POST", "/api/compose/down", undefined, { projectName }),
restart: (projectName: string) =>
call<string>("compose_restart", { projectName }, "POST", "/api/compose/restart", undefined, { projectName }),
stop: (projectName: string) =>
call<string>("compose_stop", { projectName }, "POST", "/api/compose/stop", undefined, { projectName }),
logs: (projectName: string, lines = 200) =>
call<string>("compose_logs", { projectName, lines }, "GET", "/api/compose/logs", { projectName, lines: String(lines) }),
ps: (projectName: string) =>
Expand Down
11 changes: 8 additions & 3 deletions src/pages/Compose.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useEffect, useCallback } from "react";
import { composeApi, ComposeProject } from "../lib/api";
import { globalToast } from "../lib/globalToast";
import { WarningIcon, RestartIcon, StopIcon, CloseIcon } from "../components/Icons";
import { WarningIcon, RestartIcon, StopIcon, TrashIcon, CloseIcon } from "../components/Icons";

export default function Compose() {
const [projects, setProjects] = useState<ComposeProject[]>([]);
Expand Down Expand Up @@ -33,11 +33,14 @@ export default function Compose() {
return () => clearInterval(interval);
}, [fetchProjects]);

const handleAction = async (name: string, action: "down" | "restart") => {
const handleAction = async (name: string, action: "down" | "restart" | "stop") => {
setActionLoading(`${name}-${action}`);
try {
if (action === "down") {
await composeApi.down(name);
globalToast("success", `Project '${name}' stopped and removed`);
} else if (action === "stop") {
await composeApi.stop(name);
globalToast("success", `Project '${name}' stopped`);
} else {
await composeApi.restart(name);
Expand Down Expand Up @@ -142,10 +145,12 @@ export default function Compose() {
)}
</div>
<div style={{ display: "flex", gap: 6 }} onClick={e => e.stopPropagation()}>
<button className="btn btn-ghost" style={{ fontSize: "var(--text-xs)" }} disabled={!!isLoading}
onClick={() => handleAction(p.Name, "stop")}><StopIcon size={12} /> Stop</button>
<button className="btn btn-ghost" style={{ fontSize: "var(--text-xs)" }} disabled={!!isLoading}
onClick={() => handleAction(p.Name, "restart")}><RestartIcon size={12} /> Restart</button>
<button className="btn btn-ghost" style={{ fontSize: "var(--text-xs)", color: "var(--accent-red)" }}
disabled={!!isLoading} onClick={() => handleAction(p.Name, "down")}><StopIcon size={12} /> Down</button>
disabled={!!isLoading} onClick={() => handleAction(p.Name, "down")}><TrashIcon size={12} /> Down</button>
</div>
</div>
</div>
Expand Down