feat(stacks): optional STACKS_DIR layout with Hawser display paths (#1482)

When STACKS_DIR is set, local managed stacks are stored in a flat
$STACKS_DIR/<stackName>/ layout instead of $DATA_DIR/stacks/<env>/<stack>/.
Existing stacks are not moved automatically and continue to resolve from
their existing locations. Invalid or unwritable STACKS_DIR values produce a
warning and fall back to $DATA_DIR/stacks instead of aborting startup. With
this layout, local stack names must be unique across environments.

Hawser agents report their remote stacks directory on hello. That path is
persisted on the environment as hawser_stacks_dir so compose APIs and the UI
can show host paths rather than Dockhand staging paths. Staging paths are
remapped to and from the remote stack dir for compose files, backups, and
environment settings. Backup restore may write under either the default
staging root or the configured STACKS_DIR.

Co-authored-by: xd003 <xd003@users.noreply.github.com>
This commit is contained in:
Badal Singhandxd003 authored and GitHub committed 2026-08-31 18:54:27 +02:00
1 parent 53161a6718
commit 77686da02a
27 files changed
+9145 -190

No files matched your search

+34 -21
View File
@@ -42,6 +42,8 @@ export interface EdgeConnection {
dockerVersion: string;
hostname: string;
capabilities: string[];
/** Remote agent STACKS_DIR (from hello message) */
stacksDir?: string;
connectedAt: Date;
lastHeartbeat: number;
pendingRequests: Map<string, PendingRequest>;
@@ -496,6 +498,7 @@ export function handleEdgeConnection(
dockerVersion: hello.dockerVersion,
hostname: hello.hostname,
capabilities: hello.capabilities,
stacksDir: hello.stacksDir,
connectedAt: new Date(),
lastHeartbeat: Date.now(),
pendingRequests: new Map(),
@@ -522,32 +525,40 @@ export function handleEdgeConnection(
}
/**
* Update environment status in database
* Update environment status in database. Best-effort: called from connection
* setup, teardown and heartbeat-timeout paths where a DB failure must not
* take down the connection handling.
*/
async function updateEnvironmentStatus(
environmentId: number,
connection: EdgeConnection | null
): Promise<void> {
if (connection) {
await db
.update(environments)
.set({
hawserLastSeen: new Date().toISOString(),
hawserAgentId: connection.agentId,
hawserAgentName: connection.agentName,
hawserVersion: connection.agentVersion,
hawserCapabilities: JSON.stringify(connection.capabilities),
updatedAt: new Date().toISOString()
})
.where(eq(environments.id, environmentId));
} else {
await db
.update(environments)
.set({
hawserLastSeen: new Date().toISOString(),
updatedAt: new Date().toISOString()
})
.where(eq(environments.id, environmentId));
try {
if (connection) {
await db
.update(environments)
.set({
hawserLastSeen: new Date().toISOString(),
hawserAgentId: connection.agentId,
hawserAgentName: connection.agentName,
hawserVersion: connection.agentVersion,
hawserCapabilities: JSON.stringify(connection.capabilities),
hawserStacksDir: connection.stacksDir ?? null,
updatedAt: new Date().toISOString()
})
.where(eq(environments.id, environmentId));
} else {
await db
.update(environments)
.set({
hawserLastSeen: new Date().toISOString(),
updatedAt: new Date().toISOString()
})
.where(eq(environments.id, environmentId));
}
} catch (error) {
const msg = error instanceof Error ? error.message : String(error);
console.warn(`[Hawser] Failed to update environment status for env ${environmentId}: ${msg}`);
}
}
@@ -930,6 +941,8 @@ export interface HelloMessage {
dockerVersion: string;
hostname: string;
capabilities: string[];
/** Remote agent STACKS_DIR — host path where compose stacks are written */
stacksDir?: string;
}
export interface WelcomeMessage {