1.0.9
This commit is contained in:
1 parent
62636426bf
commit
c185d00dc3
60 files changed
+2830
-918
No files matched your search
@@ -1,3 +1,7 @@
|
||||
<svelte:head>
|
||||
<title>Stacks - Dockhand</title>
|
||||
</svelte:head>
|
||||
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
@@ -52,6 +56,11 @@
|
||||
// Derived: current environment details for reactive port URL generation
|
||||
const currentEnvDetails = $derived($environments.find(e => e.id === $currentEnvironment?.id) ?? null);
|
||||
|
||||
// Polling intervals - module scope for cleanup in onDestroy
|
||||
let stacksInterval: ReturnType<typeof setInterval> | null = null;
|
||||
let statsInterval: ReturnType<typeof setInterval> | null = null;
|
||||
let unsubscribeDockerEvent: (() => void) | null = null;
|
||||
|
||||
// Helper: extract host from URL (e.g., tcp://192.168.1.4:2376 -> 192.168.1.4)
|
||||
function extractHostFromUrl(urlString: string): string | null {
|
||||
if (!urlString) return null;
|
||||
@@ -1037,38 +1046,51 @@
|
||||
document.addEventListener('resume', handleVisibilityChange);
|
||||
|
||||
// Subscribe to container events (stacks are identified by container labels)
|
||||
const unsubscribe = onDockerEvent((event) => {
|
||||
unsubscribeDockerEvent = onDockerEvent((event) => {
|
||||
if (envId && isContainerListChange(event)) {
|
||||
fetchStacks();
|
||||
fetchStats();
|
||||
}
|
||||
});
|
||||
|
||||
// Refresh stacks every 30 seconds
|
||||
const stacksInterval = setInterval(() => {
|
||||
// Refresh stacks every 30 seconds (use module-scope vars for cleanup)
|
||||
stacksInterval = setInterval(() => {
|
||||
if (envId) fetchStacks();
|
||||
}, 30000);
|
||||
|
||||
// Refresh stats every 5 seconds (faster for resource monitoring)
|
||||
const statsInterval = setInterval(() => {
|
||||
statsInterval = setInterval(() => {
|
||||
if (envId) fetchStats();
|
||||
}, 5000);
|
||||
|
||||
return () => {
|
||||
clearInterval(stacksInterval);
|
||||
clearInterval(statsInterval);
|
||||
unsubscribe();
|
||||
};
|
||||
// Note: In Svelte 5, cleanup must be in onDestroy, not returned from onMount
|
||||
});
|
||||
|
||||
// Cleanup on component destroy
|
||||
onDestroy(() => {
|
||||
// Clear polling intervals
|
||||
if (stacksInterval) {
|
||||
clearInterval(stacksInterval);
|
||||
stacksInterval = null;
|
||||
}
|
||||
if (statsInterval) {
|
||||
clearInterval(statsInterval);
|
||||
statsInterval = null;
|
||||
}
|
||||
|
||||
// Unsubscribe from Docker events
|
||||
if (unsubscribeDockerEvent) {
|
||||
unsubscribeDockerEvent();
|
||||
unsubscribeDockerEvent = null;
|
||||
}
|
||||
|
||||
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
||||
document.removeEventListener('resume', handleVisibilityChange);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="flex-1 min-h-0 flex flex-col gap-3 overflow-hidden">
|
||||
<div class="shrink-0 flex flex-wrap justify-between items-center gap-3">
|
||||
<div class="shrink-0 flex flex-wrap justify-between items-center gap-3 min-h-8">
|
||||
<PageHeader icon={Layers} title="Compose stacks" count={stacks.length}>
|
||||
{#if stacks.length > 0}
|
||||
<button
|
||||
@@ -1127,13 +1149,14 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Selection bar -->
|
||||
{#if selectedStacks.size > 0}
|
||||
<div class="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<!-- Selection bar - always reserve space to prevent layout shift -->
|
||||
<div class="h-4 shrink-0">
|
||||
{#if selectedStacks.size > 0}
|
||||
<div class="flex items-center gap-1 text-xs text-muted-foreground h-full">
|
||||
<span>{selectedInFilter.length} selected</span>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border border-border shadow-sm hover:border-foreground/30 hover:shadow transition-all"
|
||||
class="inline-flex items-center gap-1 px-1.5 py-0 rounded border border-border hover:border-foreground/30 hover:shadow transition-all"
|
||||
onclick={selectNone}
|
||||
>
|
||||
Clear
|
||||
@@ -1151,7 +1174,7 @@
|
||||
onOpenChange={(open) => confirmBulkStart = open}
|
||||
>
|
||||
{#snippet children({ open })}
|
||||
<span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border border-border shadow-sm hover:text-green-600 hover:border-green-500/40 hover:shadow transition-all cursor-pointer">
|
||||
<span class="inline-flex items-center gap-1 px-1.5 py-0 rounded border border-border hover:text-green-600 hover:border-green-500/40 hover:shadow transition-all cursor-pointer">
|
||||
<Play class="w-3 h-3" />
|
||||
Start
|
||||
</span>
|
||||
@@ -1171,7 +1194,7 @@
|
||||
onOpenChange={(open) => confirmBulkRestart = open}
|
||||
>
|
||||
{#snippet children({ open })}
|
||||
<span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border border-border shadow-sm hover:text-amber-600 hover:border-amber-500/40 hover:shadow transition-all cursor-pointer">
|
||||
<span class="inline-flex items-center gap-1 px-1.5 py-0 rounded border border-border hover:text-amber-600 hover:border-amber-500/40 hover:shadow transition-all cursor-pointer">
|
||||
<RotateCcw class="w-3 h-3" />
|
||||
Restart
|
||||
</span>
|
||||
@@ -1190,7 +1213,7 @@
|
||||
onOpenChange={(open) => confirmBulkStop = open}
|
||||
>
|
||||
{#snippet children({ open })}
|
||||
<span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border border-border shadow-sm hover:text-red-600 hover:border-red-500/40 hover:shadow transition-all cursor-pointer">
|
||||
<span class="inline-flex items-center gap-1 px-1.5 py-0 rounded border border-border hover:text-red-600 hover:border-red-500/40 hover:shadow transition-all cursor-pointer">
|
||||
<Square class="w-3 h-3" />
|
||||
Stop
|
||||
</span>
|
||||
@@ -1209,7 +1232,7 @@
|
||||
onOpenChange={(open) => confirmBulkDown = open}
|
||||
>
|
||||
{#snippet children({ open })}
|
||||
<span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border border-border shadow-sm hover:text-orange-600 hover:border-orange-500/40 hover:shadow transition-all cursor-pointer">
|
||||
<span class="inline-flex items-center gap-1 px-1.5 py-0 rounded border border-border hover:text-orange-600 hover:border-orange-500/40 hover:shadow transition-all cursor-pointer">
|
||||
<ArrowBigDown class="w-3 h-3" />
|
||||
Down
|
||||
</span>
|
||||
@@ -1228,15 +1251,16 @@
|
||||
onOpenChange={(open) => confirmBulkRemove = open}
|
||||
>
|
||||
{#snippet children({ open })}
|
||||
<span class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border border-border shadow-sm hover:text-destructive hover:border-destructive/40 hover:shadow transition-all cursor-pointer">
|
||||
<span class="inline-flex items-center gap-1 px-1.5 py-0 rounded border border-border hover:text-destructive hover:border-destructive/40 hover:shadow transition-all cursor-pointer">
|
||||
<Trash2 class="w-3 h-3" />
|
||||
Remove
|
||||
</span>
|
||||
{/snippet}
|
||||
</ConfirmPopover>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if !loading && ($environments.length === 0 || !$currentEnvironment)}
|
||||
<NoEnvironment />
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
// Form state - stack deployment config
|
||||
let formStackName = $state('');
|
||||
let formStackNameUserModified = $state(false);
|
||||
let formComposePath = $state('docker-compose.yml');
|
||||
let formComposePath = $state('compose.yaml');
|
||||
let formAutoUpdate = $state(false);
|
||||
let formAutoUpdateCron = $state('0 3 * * *');
|
||||
let formWebhookEnabled = $state(false);
|
||||
@@ -290,7 +290,7 @@
|
||||
formNewRepoCredentialId = null;
|
||||
formStackName = '';
|
||||
formStackNameUserModified = false;
|
||||
formComposePath = 'docker-compose.yml';
|
||||
formComposePath = 'compose.yaml';
|
||||
formEnvFilePath = null;
|
||||
formAutoUpdate = false;
|
||||
formAutoUpdateCron = '0 3 * * *';
|
||||
@@ -344,7 +344,7 @@
|
||||
try {
|
||||
let body: any = {
|
||||
stackName: formStackName,
|
||||
composePath: formComposePath || 'docker-compose.yml',
|
||||
composePath: formComposePath || 'compose.yaml',
|
||||
envFilePath: formEnvFilePath,
|
||||
environmentId: environmentId,
|
||||
autoUpdate: formAutoUpdate,
|
||||
@@ -661,7 +661,7 @@
|
||||
|
||||
<div class="space-y-2">
|
||||
<Label for="compose-path">Compose file path</Label>
|
||||
<Input id="compose-path" bind:value={formComposePath} placeholder="docker-compose.yml" />
|
||||
<Input id="compose-path" bind:value={formComposePath} placeholder="compose.yaml" />
|
||||
<p class="text-xs text-muted-foreground">Path to the compose file within the repository</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -65,6 +65,9 @@
|
||||
// Error dialog state
|
||||
let operationError = $state<{ title: string; message: string; details?: string } | null>(null);
|
||||
|
||||
// Stack exists warning dialog state
|
||||
let showExistsWarning = $state(false);
|
||||
|
||||
|
||||
// ─── Path State (Simplified) ─────────────────────────────────────────────────
|
||||
// Working paths: what we're currently editing (always strings, never null)
|
||||
@@ -197,7 +200,7 @@
|
||||
|
||||
// Get the current compose filename
|
||||
const currentComposePath = workingComposePath;
|
||||
const composeFilename = currentComposePath ? currentComposePath.split('/').pop() : 'docker-compose.yml';
|
||||
const composeFilename = currentComposePath ? currentComposePath.split('/').pop() : 'compose.yaml';
|
||||
|
||||
// Build new paths: create a subfolder with the stack name inside selected directory
|
||||
const displayName = mode === 'edit' ? stackName : newStackName;
|
||||
@@ -371,7 +374,7 @@
|
||||
const stackName = newStackName.trim();
|
||||
if (stackName) {
|
||||
// If we have a stack name, include the subfolder
|
||||
finalPath = `${baseDir}/${stackName}/docker-compose.yml`;
|
||||
finalPath = `${baseDir}/${stackName}/compose.yaml`;
|
||||
} else {
|
||||
// No stack name yet - just show the selected directory
|
||||
finalPath = `${baseDir}/`;
|
||||
@@ -811,6 +814,26 @@ services:
|
||||
|
||||
if (hasErrors) return;
|
||||
|
||||
const envId = $currentEnvironment?.id ?? null;
|
||||
|
||||
// Check if stack already exists
|
||||
try {
|
||||
const stacksResponse = await fetch(appendEnvParam('/api/stacks', envId));
|
||||
if (stacksResponse.ok) {
|
||||
const stacks = await stacksResponse.json();
|
||||
const existingStack = stacks.find((s: { name: string }) =>
|
||||
s.name.toLowerCase() === newStackName.trim().toLowerCase()
|
||||
);
|
||||
if (existingStack) {
|
||||
showExistsWarning = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Failed to check for existing stacks:', e);
|
||||
// Continue with creation if check fails
|
||||
}
|
||||
|
||||
saving = true;
|
||||
error = null;
|
||||
|
||||
@@ -818,8 +841,6 @@ services:
|
||||
const prepared = envVarsPanelRef?.prepareForSave() || { rawContent: '', variables: [] };
|
||||
|
||||
try {
|
||||
const envId = $currentEnvironment?.id ?? null;
|
||||
|
||||
// Build request body
|
||||
const requestBody: Record<string, unknown> = {
|
||||
name: newStackName.trim(),
|
||||
@@ -1365,7 +1386,7 @@ services:
|
||||
<PathBarItem
|
||||
label="Compose file"
|
||||
path={workingComposePath || null}
|
||||
placeholder="/path/to/docker-compose.yml"
|
||||
placeholder="/path/to/compose.yaml"
|
||||
copied={composePathCopied}
|
||||
onCopy={() => copyToClipboard(workingComposePath, (v) => composePathCopied = v)}
|
||||
onBrowse={openComposeBrowser}
|
||||
@@ -1457,7 +1478,7 @@ services:
|
||||
existingSecretKeys={mode === 'edit' ? existingSecretKeys : new Set()}
|
||||
onchange={() => { markDirty(); debouncedValidate(); }}
|
||||
theme={editorTheme}
|
||||
infoText="These variables will be written to a .env file in the stack directory."
|
||||
infoText="These variables will be written to a .env file in the stack directory and passed to the compose command."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1671,6 +1692,26 @@ services:
|
||||
</Dialog.Content>
|
||||
</Dialog.Root>
|
||||
|
||||
<!-- Stack already exists warning dialog -->
|
||||
<Dialog.Root bind:open={showExistsWarning}>
|
||||
<Dialog.Content class="max-w-sm">
|
||||
<Dialog.Header>
|
||||
<Dialog.Title class="flex items-center gap-2">
|
||||
<TriangleAlert class="w-5 h-5 text-amber-500" />
|
||||
Stack already exists
|
||||
</Dialog.Title>
|
||||
<Dialog.Description>
|
||||
A stack named "{newStackName}" already exists. Please choose a different name.
|
||||
</Dialog.Description>
|
||||
</Dialog.Header>
|
||||
<div class="flex justify-end mt-4">
|
||||
<Button size="sm" onclick={() => showExistsWarning = false}>
|
||||
OK
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog.Root>
|
||||
|
||||
<!-- Error dialog for failed operations -->
|
||||
{#if operationError}
|
||||
{@const errorDialogOpen = true}
|
||||
|
||||
Reference in new issue
Block a user