Skip to content

Modern Docker Management, Designed for Everyone

feat: image inspection page

Kyle Mendellc3f5665bf5c6
diff --git a/src/lib/components/badges/unused-text-badge.svelte b/src/lib/components/badges/unused-text-badge.svelte
index beb210fc7..409f2d36b 100644
--- a/src/lib/components/badges/unused-text-badge.svelte
+++ b/src/lib/components/badges/unused-text-badge.svelte
@@ -4,13 +4,22 @@
interface Props {
name: string;
inUse: boolean | undefined;
+ link?: string;
}
- let { name, inUse }: Props = $props();
+ let { name, inUse, link }: Props = $props();
</script>
<div class="flex items-center gap-2">
- <span class="truncate">{name}</span>
+ {#if link}
+ <span class="">
+ <a href={link}>
+ {name}
+ </a>
+ </span>
+ {:else}
+ <span class="truncate">{name}</span>
+ {/if}
{#if !inUse}
<StatusBadge text="Unused" variant="amber" />
{/if}
diff --git a/src/lib/services/docker/image-service.ts b/src/lib/services/docker/image-service.ts
index 2343bc7fd..3a2189125 100644
--- a/src/lib/services/docker/image-service.ts
+++ b/src/lib/services/docker/image-service.ts
@@ -1,6 +1,8 @@
import { getDockerClient, dockerHost } from './core';
import type { ServiceImage } from '$lib/types/docker/image.type';
import type Docker from 'dockerode';
+// Import custom errors
+import { NotFoundError, ConflictError, DockerApiError } from '$lib/types/errors';
/**
* The function `listImages` retrieves a list of Docker images and parses their information into a
@@ -51,6 +53,29 @@ export async function listImages(): Promise<ServiceImage[]> {
}
}
+/**
+ * Retrieves detailed information about a specific Docker image by its ID.
+ * @param {string} imageId - The ID or name of the image to inspect.
+ * @returns {Promise<Docker.ImageInspectInfo>} A promise that resolves with the detailed image information.
+ * @throws {NotFoundError} If the image with the specified ID does not exist.
+ * @throws {DockerApiError} For other errors during the Docker API interaction.
+ */
+export async function getImage(imageId: string): Promise<Docker.ImageInspectInfo> {
+ try {
+ const docker = getDockerClient();
+ const image = docker.getImage(imageId);
+ const inspectInfo = await image.inspect();
+ console.log(`Docker Service: Inspected image "${imageId}" successfully.`);
+ return inspectInfo;
+ } catch (error: any) {
+ console.error(`Docker Service: Error inspecting image "${imageId}":`, error);
+ if (error.statusCode === 404) {
+ throw new NotFoundError(`Image "${imageId}" not found.`);
+ }
+ throw new DockerApiError(`Failed to inspect image "${imageId}": ${error.message || 'Unknown Docker error'}`, error.statusCode);
+ }
+}
+
/**
* This TypeScript function removes a Docker image by its ID, with an option to force removal if the
* image is in use.
diff --git a/src/routes/containers/ContainerActions.svelte b/src/routes/containers/ContainerActions.svelte
index b73266fe5..aa4094f29 100644
--- a/src/routes/containers/ContainerActions.svelte
+++ b/src/routes/containers/ContainerActions.svelte
@@ -3,7 +3,7 @@
import { Button } from '$lib/components/ui/button/index.js';
import * as DropdownMenu from '$lib/components/ui/dropdown-menu/index.js';
import { goto, invalidateAll } from '$app/navigation';
- import { Eye, Play, RotateCcw, StopCircle, Trash2, Loader2 } from '@lucide/svelte';
+ import { ScanSearch, Play, RotateCcw, StopCircle, Trash2, Loader2 } from '@lucide/svelte';
import { toast } from 'svelte-sonner';
import ConfirmDialog from '$lib/components/confirm-dialog.svelte';
@@ -95,7 +95,7 @@
<DropdownMenu.Content>
<DropdownMenu.Group>
<DropdownMenu.Item onclick={viewContainer} disabled={isAnyLoading}>
- <Eye class="w-4 h-4" />
+ <ScanSearch class="w-4 h-4" />
View
</DropdownMenu.Item>
diff --git a/src/routes/containers/[id]/+page.svelte b/src/routes/containers/[id]/+page.svelte
index fd6af8e25..44a0cad46 100644
--- a/src/routes/containers/[id]/+page.svelte
+++ b/src/routes/containers/[id]/+page.svelte
@@ -15,7 +15,6 @@
let { data, form }: { data: PageData; form: ActionData } = $props();
let { container, logs, stats } = $derived(data);
- console.log('Container:', container);
let starting = $state(false);
let stopping = $state(false);
diff --git a/src/routes/images/ImageActions.svelte b/src/routes/images/ImageActions.svelte
index 988fc36c3..6954acc42 100644
--- a/src/routes/images/ImageActions.svelte
+++ b/src/routes/images/ImageActions.svelte
@@ -2,7 +2,7 @@
import { Button } from '$lib/components/ui/button/index.js';
import * as Dialog from '$lib/components/ui/dialog/index.js';
import * as DropdownMenu from '$lib/components/ui/dropdown-menu/index.js';
- import { Trash2, Download, Ellipsis, Loader2 } from '@lucide/svelte';
+ import { Trash2, Download, Ellipsis, Loader2, ScanSearch } from '@lucide/svelte';
import { toast } from 'svelte-sonner';
let { id, repoTag, inUse = true }: { id: string; repoTag?: string; inUse: boolean } = $props();
@@ -79,6 +79,9 @@
isPulling = false;
}
}
+ function handleView(id: string) {
+ window.location.href = `/images/${id}`;
+ }
</script>
<DropdownMenu.Root>
@@ -92,17 +95,21 @@
</DropdownMenu.Trigger>
<DropdownMenu.Content>
<DropdownMenu.Group>
+ <DropdownMenu.Item onclick={() => handleView(id)}>
+ <ScanSearch class="h-4 w-4" />
+ Inspect
+ </DropdownMenu.Item>
<DropdownMenu.Item onclick={pullImage} disabled={isPulling || !repoTag}>
{#if isPulling}
<Loader2 class="h-4 w-4 animate-spin" />
Pulling...
{:else}
- <Download class="mr-2 h-4 w-4" />
+ <Download class="h-4 w-4" />
Pull
{/if}
</DropdownMenu.Item>
<DropdownMenu.Item class="text-red-500 focus:!text-red-700" onclick={() => (isConfirmDialogOpen = true)}>
- <Trash2 class="mr-2 h-4 w-4" />
+ <Trash2 class="h-4 w-4" />
Remove
</DropdownMenu.Item>
</DropdownMenu.Group>
diff --git a/src/routes/images/[imageId]/+page.server.ts b/src/routes/images/[imageId]/+page.server.ts
new file mode 100644
index 000000000..907da135a
--- /dev/null
+++ b/src/routes/images/[imageId]/+page.server.ts
@@ -0,0 +1,50 @@
+import type { PageServerLoad, Actions } from './$types';
+import { getImage, removeImage } from '$lib/services/docker/image-service'; // Import getImage and removeImage
+import { error, fail, redirect } from '@sveltejs/kit';
+import { NotFoundError, ConflictError, DockerApiError } from '$lib/types/errors';
+
+export const load: PageServerLoad = async ({ params }) => {
+ const imageId = params.imageId; // Use imageId to match the route parameter
+
+ try {
+ const image = await getImage(imageId);
+
+ // Optionally, you could fetch related containers here if needed
+ // const containersUsingImage = await getContainersUsingImage(imageId);
+
+ return {
+ image // Return the detailed image info
+ };
+ } catch (err: any) {
+ console.error(`Failed to load image ${imageId}:`, err);
+ if (err instanceof NotFoundError) {
+ // Use instanceof for custom errors
+ error(404, { message: err.message });
+ } else {
+ error(err.status || 500, {
+ message: err.message || `Failed to load image details for "${imageId}".`
+ });
+ }
+ }
+};
+
+// Add action for removing the image from its details page
+export const actions: Actions = {
+ remove: async ({ params, url }) => {
+ const imageId = params.imageId;
+ const force = url.searchParams.get('force') === 'true'; // Check for force parameter
+ try {
+ await removeImage(imageId, force);
+ // Redirect back to the main images list after successful removal
+ redirect(303, '/images');
+ } catch (err: any) {
+ // Handle specific errors from removeImage
+ // Note: image-service removeImage needs updating to throw custom errors
+ if (err instanceof NotFoundError || err instanceof ConflictError || err instanceof DockerApiError) {
+ return fail(err.status || 409, { error: err.message });
+ }
+ // Fallback for unexpected errors or generic errors from service
+ return fail(500, { error: err.message || 'An unexpected error occurred during removal.' });
+ }
+ }
+};
diff --git a/src/routes/images/[imageId]/+page.svelte b/src/routes/images/[imageId]/+page.svelte
new file mode 100644
index 000000000..94ddfed65
--- /dev/null
+++ b/src/routes/images/[imageId]/+page.svelte
@@ -0,0 +1,245 @@
+<script lang="ts">
+ import type { PageData, ActionData } from './$types';
+ import * as Card from '$lib/components/ui/card/index.js';
+ import { Button } from '$lib/components/ui/button/index.js';
+ import { ArrowLeft, AlertCircle, RefreshCw, HardDrive, Clock, Tag, Layers, Hash, Trash2, Loader2, Cpu } from '@lucide/svelte';
+ import * as Breadcrumb from '$lib/components/ui/breadcrumb/index.js';
+ import { enhance } from '$app/forms';
+ import { invalidateAll } from '$app/navigation';
+ import * as Alert from '$lib/components/ui/alert/index.js';
+ import { Separator } from '$lib/components/ui/separator/index.js';
+ import { Badge } from '$lib/components/ui/badge/index.js';
+ import { formatDate, formatBytes } from '$lib/utils';
+ import ConfirmDialog from '$lib/components/confirm-dialog.svelte';
+
+ let { data, form }: { data: PageData; form: ActionData } = $props();
+ let { image } = $derived(data);
+
+ let isRefreshing = $state(false);
+ let isRemoving = $state(false);
+ let showRemoveConfirm = $state(false);
+ let forceRemove = $state(false); // State for the force remove checkbox
+
+ // Helper to format the image ID
+ const shortId = $derived(image?.Id.split(':')[1].substring(0, 12) || 'N/A');
+ const createdDate = $derived(image?.Created ? formatDate(image.Created) : 'N/A');
+ const imageSize = $derived(formatBytes(image?.Size || 0));
+
+ // Determine if the image is potentially in use (basic check, more robust check might be needed)
+ // A more reliable check would involve fetching containers using this image ID in the load function
+ const potentiallyInUse = $derived(false); // Placeholder - Needs data from load function
+
+ async function refreshData() {
+ isRefreshing = true;
+ await invalidateAll();
+ setTimeout(() => {
+ isRefreshing = false;
+ }, 500);
+ }
+
+ function triggerRemove() {
+ forceRemove = false; // Reset force state when opening dialog
+ showRemoveConfirm = true;
+ }
+
+ // This function is called by the ConfirmDialog
+ function handleRemoveConfirm(forceConfirm: boolean) {
+ forceRemove = forceConfirm; // Set the force state based on checkbox
+ // Find the form and submit it
+ const removeForm = document.getElementById('remove-image-form') as HTMLFormElement;
+ if (removeForm) {
+ // Optionally add force parameter to form action or hidden input if needed by server action
+ // Since we read from URL in server action, just submit
+ removeForm.submit();
+ }
+ }
+</script>
+
+<!-- Confirmation Dialog for Remove -->
+<ConfirmDialog bind:open={showRemoveConfirm} title="Confirm Image Removal" description={`Are you sure you want to remove image ${shortId}? This action cannot be undone.`} confirmLabel="Remove" variant="destructive" onConfirm={handleRemoveConfirm} itemType={'image'} isRunning={potentiallyInUse} />
+
+<div class="space-y-6 pb-8">
+ <!-- Breadcrumb Navigation -->
+ <div class="flex flex-col sm:flex-row justify-between sm:items-center gap-4">
+ <div>
+ <Breadcrumb.Root>
+ <Breadcrumb.List>
+ <Breadcrumb.Item>
+ <Breadcrumb.Link href="/images">Images</Breadcrumb.Link>
+ </Breadcrumb.Item>
+ <Breadcrumb.Separator />
+ <Breadcrumb.Item>
+ <Breadcrumb.Page>{shortId}</Breadcrumb.Page>
+ </Breadcrumb.Item>
+ </Breadcrumb.List>
+ </Breadcrumb.Root>
+ <div class="mt-2 flex items-center gap-2">
+ <h1 class="text-2xl font-bold tracking-tight break-all">
+ {image?.RepoTags?.[0] || shortId}
+ </h1>
+ <!-- Add badges for tags if needed -->
+ </div>
+ </div>
+
+ <div class="flex gap-2 flex-wrap">
+ <Button variant="outline" size="sm" onclick={refreshData} disabled={isRefreshing}>
+ <RefreshCw class={`h-4 w-4 mr-2 ${isRefreshing ? 'animate-spin' : ''}`} /> Refresh
+ </Button>
+ <!-- Remove Button triggers dialog -->
+ <Button variant="destructive" size="sm" onclick={triggerRemove} disabled={isRemoving}>
+ {#if isRemoving}
+ <Loader2 class="h-4 w-4 mr-2 animate-spin" />
+ {:else}
+ <Trash2 class="h-4 w-4 mr-2" />
+ {/if} Remove
+ </Button>
+ <!-- Hidden form for removal action -->
+ <form
+ id="remove-image-form"
+ method="POST"
+ action="?/remove{forceRemove ? '&force=true' : ''}"
+ use:enhance={() => {
+ isRemoving = true;
+ return async ({ update }) => {
+ await update({ reset: false });
+ // isRemoving will be reset by effect or on navigation
+ };
+ }}
+ class="hidden"
+ >
+ <input type="hidden" name="imageId" value={image?.Id} />
+ <button type="submit">Submit</button>
+ </form>
+ </div>
+ </div>
+
+ <!-- Error Alert -->
+ {#if form?.error}
+ <Alert.Root variant="destructive">
+ <AlertCircle class="h-4 w-4 mr-2" />
+ <Alert.Title>Action Failed</Alert.Title>
+ <Alert.Description>{form.error}</Alert.Description>
+ </Alert.Root>
+ {/if}
+
+ {#if image}
+ <!-- Image Details Section -->
+ <div class="space-y-6">
+ <Card.Root class="border shadow-sm">
+ <Card.Header>
+ <Card.Title>Image Details</Card.Title>
+ </Card.Header>
+ <Card.Content>
+ <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
+ <!-- ID -->
+ <div class="flex items-start gap-3">
+ <div class="bg-gray-500/10 p-2 rounded-full h-10 w-10 flex items-center justify-center flex-shrink-0">
+ <Hash class="h-5 w-5 text-gray-500" />
+ </div>
+ <div class="min-w-0 flex-1">
+ <p class="text-sm font-medium text-muted-foreground">ID</p>
+ <p class="text-base font-semibold mt-1 truncate" title={image.Id}>{shortId}</p>
+ </div>
+ </div>
+
+ <!-- Size -->
+ <div class="flex items-start gap-3">
+ <div class="bg-blue-500/10 p-2 rounded-full h-10 w-10 flex items-center justify-center flex-shrink-0">
+ <HardDrive class="h-5 w-5 text-blue-500" />
+ </div>
+ <div class="min-w-0 flex-1">
+ <p class="text-sm font-medium text-muted-foreground">Size</p>
+ <p class="text-base font-semibold mt-1">{imageSize}</p>
+ </div>
+ </div>
+
+ <!-- Created -->
+ <div class="flex items-start gap-3">
+ <div class="bg-green-500/10 p-2 rounded-full h-10 w-10 flex items-center justify-center flex-shrink-0">
+ <Clock class="h-5 w-5 text-green-500" />
+ </div>
+ <div class="min-w-0 flex-1">
+ <p class="text-sm font-medium text-muted-foreground">Created</p>
+ <p class="text-base font-semibold mt-1">{createdDate}</p>
+ </div>
+ </div>
+
+ <!-- Architecture -->
+ <div class="flex items-start gap-3">
+ <div class="bg-orange-500/10 p-2 rounded-full h-10 w-10 flex items-center justify-center flex-shrink-0">
+ <Cpu class="h-5 w-5 text-orange-500" />
+ </div>
+ <div class="min-w-0 flex-1">
+ <p class="text-sm font-medium text-muted-foreground">Architecture</p>
+ <p class="text-base font-semibold mt-1">{image.Architecture || 'N/A'}</p>
+ </div>
+ </div>
+
+ <!-- OS -->
+ <div class="flex items-start gap-3">
+ <div class="bg-indigo-500/10 p-2 rounded-full h-10 w-10 flex items-center justify-center flex-shrink-0">
+ <Layers class="h-5 w-5 text-indigo-500" />
+ </div>
+ <div class="min-w-0 flex-1">
+ <p class="text-sm font-medium text-muted-foreground">OS</p>
+ <p class="text-base font-semibold mt-1">{image.Os || 'N/A'}</p>
+ </div>
+ </div>
+ </div>
+ </Card.Content>
+ </Card.Root>
+
+ <!-- Tags Card -->
+ {#if image.RepoTags && image.RepoTags.length > 0}
+ <Card.Root class="border shadow-sm">
+ <Card.Header>
+ <Card.Title class="flex items-center gap-2"><Tag class="h-5 w-5 text-muted-foreground" /> Tags</Card.Title>
+ </Card.Header>
+ <Card.Content>
+ <div class="flex flex-wrap gap-2">
+ {#each image.RepoTags as tag}
+ <Badge variant="secondary">{tag}</Badge>
+ {/each}
+ </div>
+ </Card.Content>
+ </Card.Root>
+ {/if}
+
+ <!-- Labels Card -->
+ {#if image.Config?.Labels && Object.keys(image.Config.Labels).length > 0}
+ <Card.Root class="border shadow-sm">
+ <Card.Header>
+ <Card.Title>Labels</Card.Title>
+ </Card.Header>
+ <Card.Content class="space-y-2">
+ {#each Object.entries(image.Config.Labels) as [key, value]}
+ <div class="text-sm flex flex-col sm:flex-row sm:items-center">
+ <span class="font-medium text-muted-foreground w-full sm:w-1/4 break-all">{key}:</span>
+ <span class="font-mono text-xs sm:text-sm break-all w-full sm:w-3/4">{value}</span>
+ </div>
+ {#if !Object.is(Object.keys(image.Config.Labels).length - 1, Object.keys(image.Config.Labels).indexOf(key))}
+ <Separator class="my-2" />
+ {/if}
+ {/each}
+ </Card.Content>
+ </Card.Root>
+ {/if}
+
+ <!-- Layers/History (Optional - can be large) -->
+ <!-- {#if image.RootFS?.Layers}
+ <Card.Root>
+ <Card.Header><Card.Title>Layers</Card.Title></Card.Header>
+ <Card.Content>...</Card.Content>
+ </Card.Root>
+ {/if} -->
+ </div>
+ {:else}
+ <!-- Image Not Found Section -->
+ <div class="text-center py-12">
+ <p class="text-lg font-medium text-muted-foreground">Image not found.</p>
+ <Button href="/images" variant="outline" size="sm" class="mt-4">
+ <ArrowLeft class="h-4 w-4 mr-2" /> Back to Images
+ </Button>
+ </div>
+ {/if}
+</div>
diff --git a/src/routes/images/columns.ts b/src/routes/images/columns.ts
index d0791f40c..f0c4b0008 100644
--- a/src/routes/images/columns.ts
+++ b/src/routes/images/columns.ts
@@ -13,11 +13,10 @@ export const columns: ColumnDef<EnhancedImage>[] = [
accessorKey: 'repo',
header: 'Name',
cell: ({ row }) => {
- const inUse = row.original.inUse;
-
return renderComponent(UnusedTextBadge, {
name: row.original.repo,
- inUse: row.original.inUse
+ inUse: row.original.inUse,
+ link: `/images/${row.original.id}`
});
}
},