mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-18 06:23:18 +00:00
feat: guide missing external network creation during deploy (#1645)
* feat: guide missing external network creation during deploy Detect missing external networks before Compose runs, prompt or auto-create safe bridge networks, and keep unsupported declarations blocked with trusted deploy provenance. * test: align deploy context and settings fixtures with missing-network gate Update caller spies, EffResource expectations, StacksSection save keys, and git-source spy cleanup so CI matches the new deployStack context and auto-create setting. * fix: drop unused renderError binding in missing-network resolver Satisfies no-unused-vars so backend ESLint CI passes; callers already key only on model presence. * fix: use HTTP-safe clipboard helper in missing-network dialog navigator.clipboard fails on plain HTTP LAN hosts; route copy actions through copyToClipboard so Docker and Compose copy buttons work on self-hosted instances. * fix: simplify missing-network dialog actions and copy label Drop the Compose snippet escape hatch, move secondary actions under More, and rename the terminal copy action to Copy create command so the footer is a clear Cancel / Create decision.
This commit is contained in:
@@ -33,9 +33,10 @@ export const CAPABILITIES = [
|
||||
'compose-storage',
|
||||
'cross-node-rbac',
|
||||
'stack-down-remove-volumes',
|
||||
'guided-external-network-preflight',
|
||||
] as const;
|
||||
|
||||
export type Capability = (typeof CAPABILITIES)[number];
|
||||
|
||||
/** Must stay in sync with backend CapabilityRegistry.STACK_DOWN_REMOVE_VOLUMES_CAPABILITY */
|
||||
export const STACK_DOWN_REMOVE_VOLUMES_CAPABILITY = 'stack-down-remove-volumes' as const satisfies Capability;
|
||||
export const GUIDED_EXTERNAL_NETWORK_PREFLIGHT_CAPABILITY = 'guided-external-network-preflight' as const satisfies Capability;
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
type NetworkingFinding, type NetworkingFindingKind, type NetworkingNetworkRow, type NetworkingOverviewEnvelope,
|
||||
type NetworkingRecommendedAction, type NodeNetworkingOverview,
|
||||
} from '@/types/networking';
|
||||
import { stringify as stringifyYaml } from 'yaml';
|
||||
|
||||
export type NetworkFilter = 'all' | 'managed' | 'external' | 'system' | 'shared' | 'exposed' | 'drift';
|
||||
|
||||
@@ -95,9 +96,40 @@ export function canUseNetworkName(name: string): boolean {
|
||||
return /^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(name);
|
||||
}
|
||||
|
||||
export function buildExternalNetworkSnippet(name: string): string | null {
|
||||
if (!canUseNetworkName(name)) return null;
|
||||
return `networks:\n ${name}:\n external: true`;
|
||||
/**
|
||||
* Build a single valid `networks:` Compose fragment for one or more
|
||||
* key → runtime-name mappings. Stable-sorts keys. Returns null if any
|
||||
* runtime name is unsafe.
|
||||
*/
|
||||
export function buildExternalNetworksSnippet(
|
||||
entries: ReadonlyArray<{ key: string; name: string }>,
|
||||
): string | null {
|
||||
if (entries.length === 0) return null;
|
||||
const networks: Record<string, { external: true; name?: string }> = {};
|
||||
const sorted = [...entries].sort((a, b) => a.key.localeCompare(b.key));
|
||||
for (const { key, name } of sorted) {
|
||||
if (!canUseNetworkName(name)) return null;
|
||||
networks[key] = key === name
|
||||
? { external: true }
|
||||
: { external: true, name };
|
||||
}
|
||||
// Prefer yaml when available; fallback keeps simple unquoted keys for tests.
|
||||
try {
|
||||
return stringifyYaml({ networks }).trimEnd();
|
||||
} catch {
|
||||
const lines = ['networks:'];
|
||||
for (const { key, name } of sorted) {
|
||||
lines.push(` ${key}:`);
|
||||
lines.push(' external: true');
|
||||
if (key !== name) lines.push(` name: ${name}`);
|
||||
}
|
||||
return lines.join('\n');
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated Prefer buildExternalNetworksSnippet with explicit key+name. */
|
||||
export function buildExternalNetworkSnippet(name: string, key: string = name): string | null {
|
||||
return buildExternalNetworksSnippet([{ key, name }]);
|
||||
}
|
||||
|
||||
/** Normalizes a network row from a schema-2 remote (no serviceNames) so the UI
|
||||
|
||||
Reference in New Issue
Block a user