Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: show correct host IP in service port tooltips (#3299)
Kyle Mendell4e0bea758bce
diff --git a/frontend/src/lib/components/badges/port-badge.svelte b/frontend/src/lib/components/badges/port-badge.svelteindex 4b95f5f71..5e4825c02 100644--- a/frontend/src/lib/components/badges/port-badge.svelte+++ b/frontend/src/lib/components/badges/port-badge.svelte@@ -1,5 +1,6 @@<script lang="ts">import type { ContainerPorts } from '$lib/types/docker';+ import type { ServicePort } from '$lib/types/swarm';import { m } from '$lib/paraglide/messages';import * as ArcaneTooltip from '$lib/components/arcane-tooltip';import { badgeVariants } from '$lib/components/ui/badge';@@ -9,13 +10,13 @@import { mergeProps } from 'bits-ui';let {- ports = [] as ContainerPorts[],+ ports = [] as PortBadgePort[],collapsible = true,maxVisible = 3,hideExposed = false,wrap = true} = $props<{- ports?: ContainerPorts[];+ ports?: PortBadgePort[];collapsible?: boolean;maxVisible?: number;hideExposed?: boolean;@@ -26,6 +27,7 @@let expanded = $state(false);const baseServerUrl = $derived($settingsStore?.baseServerUrl ?? 'http://localhost');+ type PortBadgePort = ContainerPorts | ServicePort;type NormalizedPort = {hostPort: string | null;@@ -35,36 +37,39 @@isPublished: boolean;};- function getPublicPort(p: ContainerPorts): string | null {- const pub =- (p as any).publicPort?.toString?.() ?? (p as any).hostPort?.toString?.() ?? (p as any).published?.toString?.() ?? null;+ function isContainerPort(p: PortBadgePort): p is ContainerPorts {+ return 'privatePort' in p;+ }++ function getPublicPort(p: PortBadgePort): string | null {+ const pub = isContainerPort(p) ? p.publicPort?.toString() : p.published?.toString();return pub && pub !== '0' ? pub : null;}- function getPrivatePort(p: ContainerPorts): string {- return ((p as any).privatePort ?? (p as any).target ?? '?').toString();+ function getPrivatePort(p: PortBadgePort): string {+ return (isContainerPort(p) ? p.privatePort : p.target).toString();}- function getProto(p: ContainerPorts): string | undefined {- return (p as any).type ?? (p as any).protocol ?? undefined;+ function getProto(p: PortBadgePort): string | undefined {+ return isContainerPort(p) ? p.type : p.protocol;}- function normalize(p: ContainerPorts): NormalizedPort {+ function normalize(p: PortBadgePort): NormalizedPort {const hostPort = getPublicPort(p);return {hostPort,containerPort: getPrivatePort(p),proto: getProto(p),- ip: (p as any).ip ?? null,+ ip: (isContainerPort(p) ? p.ip : p.host_ip)?.trim() || null,isPublished: hostPort !== null};}- function uniquePorts(list: ContainerPorts[]): NormalizedPort[] {+ function uniquePorts(list: PortBadgePort[]): NormalizedPort[] {const map = new Map<string, NormalizedPort>();for (const p of list) {const n = normalize(p);- const key = `${n.hostPort ?? ''}:${n.containerPort}/${n.proto ?? ''}`;+ const key = `${n.ip ?? ''}:${n.hostPort ?? ''}:${n.containerPort}/${n.proto ?? ''}`;if (!map.has(key)) map.set(key, n);}return Array.from(map.values()).sort((a, b) => {@@ -116,7 +121,7 @@</ArcaneTooltip.Trigger><ArcaneTooltip.Content><p class="text-xs">- Published: {p.ip ?? '0.0.0.0'}:{p.hostPort} → {p.containerPort}{p.proto ? `/${p.proto}` : ''}+ {m.ports_published_label()}: {p.ip ?? '0.0.0.0'}:{p.hostPort} → {p.containerPort}{p.proto ? `/${p.proto}` : ''}</p></ArcaneTooltip.Content></ArcaneTooltip.Root>@@ -133,7 +138,7 @@</ArcaneTooltip.Trigger><ArcaneTooltip.Content><p class="text-xs">- Exposed: {p.containerPort}{p.proto ? `/${p.proto}` : ''} (not published to host)+ {m.ports_exposed_label()}: {p.containerPort}{p.proto ? `/${p.proto}` : ''} ({m.ports_no_host_binding()})</p></ArcaneTooltip.Content></ArcaneTooltip.Root>diff --git a/frontend/src/lib/types/swarm.ts b/frontend/src/lib/types/swarm.tsindex 29b63b4f4..c7cddabdd 100644--- a/frontend/src/lib/types/swarm.ts+++ b/frontend/src/lib/types/swarm.ts@@ -514,6 +514,7 @@ export interface SwarmSecretUpdateRequest {export interface ServicePort {mode?: string;+ host_ip?: string;target: number;published?: string;protocol?: string;diff --git a/frontend/src/routes/(app)/projects/components/ProjectContainersTable.svelte b/frontend/src/routes/(app)/projects/components/ProjectContainersTable.svelteindex aba9d2a7a..55c38d524 100644--- a/frontend/src/routes/(app)/projects/components/ProjectContainersTable.svelte+++ b/frontend/src/routes/(app)/projects/components/ProjectContainersTable.svelte@@ -344,7 +344,7 @@{#snippet PortsCell({ item }: { item: ServiceWithId })}{#if item.serviceConfig?.ports && item.serviceConfig.ports.length > 0}- <PortBadge ports={item.serviceConfig.ports as any} wrap={false} />+ <PortBadge ports={item.serviceConfig.ports} wrap={false} />{:else if item.ports && item.ports.length > 0}{@const parsedPorts = item.ports.map((p) => {const [numsPart, proto] = p.split('/');diff --git a/tests/spec/project.spec.ts b/tests/spec/project.spec.tsindex dcb943501..c2d0ffb8c 100644--- a/tests/spec/project.spec.ts+++ b/tests/spec/project.spec.ts@@ -161,7 +161,11 @@ async function expectProjectCreateResponse(responsePromise: Promise<Response>) {);}-async function createProjectViaUI(page: Page, projectName: string) {+async function createProjectViaUI(+ page: Page,+ projectName: string,+ composeContent = TEST_COMPOSE_YAML+) {const containerName = `test-nginx-container-${Date.now()}`;const envFile = TEST_ENV_FILE.replace(/CONTAINER_NAME=.*/m, `CONTAINER_NAME=${containerName}`);@@ -178,13 +182,13 @@ async function createProjectViaUI(page: Page, projectName: string) {await expect(composeEditor).toBeVisible();await expect(envEditor).toBeVisible();- await setCodeMirrorValue(page, composeEditor, TEST_COMPOSE_YAML);+ await setCodeMirrorValue(page, composeEditor, composeContent);await setCodeMirrorValue(page, envEditor, envFile);await expect.poll(async () => (await getCodeMirrorValue(composeEditor)).trimEnd(), {message: 'Expected compose editor to contain the exact test compose fixture before creation'})- .toBe(TEST_COMPOSE_YAML.trimEnd());+ .toBe(composeContent.trimEnd());const createButton = page.locator('button[data-action="create"]');await expect(createButton).toBeEnabled();@@ -1226,6 +1230,37 @@ test.describe('Project Detail Page', () => {}});+ test('should display the configured service port host IP', async ({ page }) => {+ test.slow();++ const projectName = `test-project-port-host-${Date.now()}`;+ const composeContent = [+ 'services:',+ ' web:',+ ' image: public.ecr.aws/nginx/nginx:stable-alpine',+ ' ports:',+ ' - "127.0.0.1:8081:80"',+ ''+ ].join('\n');+ let projectId = '';++ try {+ projectId = await createProjectViaUI(page, projectName, composeContent);+ await page.getByRole('tab', { name: 'Services 1', exact: true }).click();++ await page.getByText('8081:80', { exact: true }).hover();+ await expect(+ page.getByText('Published: 127.0.0.1:8081 → 80/tcp', { exact: true })+ ).toBeVisible();+ } finally {+ if (projectId) {+ await destroyProjectByIdViaAPI(page, projectId);+ } else {+ await destroyProjectByNameViaUI(page, projectName);+ }+ }+ });+test('should display configuration editors', async ({ page }) => {test.skip(!realProjects.length, 'No projects available for configuration test');