import { Database, FileArchive, Plus, RotateCcw, Server, Settings, TerminalSquare, Trash2 } from 'lucide-react'; import { useEffect, useMemo, useState } from 'react'; import { Badge, Button, Card, CardHeader, Modal } from '../../components/ui'; import { useToast } from '../../components/toast'; import { PageTitle } from '../../layout/AppLayout'; import { cn } from '../../lib/utils'; import type { RuntimeResource } from '../../types/runtime'; import { LoadingModal, useMinimumLoading } from '../operations/operation-utils'; import { listLauncherBuildJobs, listLauncherVersions, loadLauncherComponentLogs, loadLauncherRuntimeResources, loadRuntimeWorkloadEnv, restartLauncherComponent, saveRuntimeWorkloadEnv, type LauncherBuildJob, type LauncherVersion } from './launcher-api'; const LAUNCHER_NAMESPACE = 'studio-system'; type LauncherComponentDefinition = { key: string; name: string; description: string; type: 'client' | 'backend' | 'database'; kind?: string; workloadName?: string; serviceName?: string; }; const launcherComponents: LauncherComponentDefinition[] = [ { key: 'launcher-client', name: '런처 클라이언트', description: '사용자 PC에 설치되는 Electron .deb 패키지입니다.', type: 'client' }, { key: 'launcher-be', name: '런처 백엔드', description: '로그인, 앱 목록, 업데이트, handoff API를 제공하는 서버입니다.', type: 'backend', kind: 'Deployment', workloadName: 'studio-launcher-be', serviceName: 'studio-launcher-be' }, { key: 'launcher-db', name: '런처 DB', description: '런처 앱, 버전, 사용자 앱 권한 데이터를 저장합니다.', type: 'database', kind: 'StatefulSet', workloadName: 'studio-launcher-db', serviceName: 'studio-launcher-db' } ]; function statusTone(status?: string): 'green' | 'amber' | 'red' | 'neutral' { if (['Running', 'Bound', 'ClusterIP', 'LoadBalancer'].includes(status ?? '')) return 'green'; if (['Pending', 'ContainerCreating'].includes(status ?? '')) return 'amber'; if (['Error', 'CrashLoopBackOff', 'ImagePullBackOff', 'Failed'].includes(status ?? '')) return 'red'; return 'neutral'; } function buildStatusText(status?: string) { if (status === 'SUCCEEDED') return '성공'; if (status === 'FAILED') return '실패'; if (status === 'RUNNING') return '진행 중'; if (status === 'PENDING') return '대기'; if (status === 'CANCELED') return '취소'; return status ?? '빌드 이력 없음'; } function buildStatusTone(status?: string): 'green' | 'amber' | 'red' | 'blue' | 'neutral' { if (status === 'SUCCEEDED') return 'green'; if (status === 'FAILED' || status === 'CANCELED') return 'red'; if (status === 'RUNNING') return 'blue'; if (status === 'PENDING') return 'amber'; return 'neutral'; } function componentIcon(type: LauncherComponentDefinition['type']) { if (type === 'client') return FileArchive; if (type === 'database') return Database; return Server; } function apiKind(kind?: string) { return (kind ?? '').toLowerCase(); } function stripAnsi(value: string) { return value.replace(/(?:\x1B|\u241B)\[[0-?]*[ -/]*[@-~]/g, ''); } function findResource(resources: RuntimeResource[], kind?: string, name?: string) { if (!kind || !name) return undefined; return resources.find((resource) => resource.kind === kind && resource.name === name); } function serviceResource(resources: RuntimeResource[], name?: string) { if (!name) return undefined; return resources.find((resource) => resource.kind === 'Service' && resource.name === name); } function relatedResources(resources: RuntimeResource[], component: LauncherComponentDefinition) { if (component.type === 'client') return []; const names = new Set([component.workloadName, component.serviceName].filter(Boolean)); return resources.filter((resource) => { if (names.has(resource.name)) return true; return component.workloadName ? resource.name.includes(component.workloadName) : false; }); } function launcherArtifactLabel(version?: LauncherVersion) { if (!version) return '등록된 릴리즈 없음'; if (version.artifact) return version.artifact; if (!version.downloadUrl) return '배포 파일 미등록'; const segments = version.downloadUrl.split('/').filter(Boolean); return segments[segments.length - 1] ?? '배포 파일 미등록'; } function launcherVersionMeta(version?: LauncherVersion) { if (!version) return '버전 관리에서 릴리즈를 등록하세요'; const minimum = version.minimumVersion ? `최소 지원 ${version.minimumVersion}` : '최소 지원 미설정'; return `${minimum} · ${version.isActive ? '활성' : '비활성'}`; } export function LauncherComponentsPage() { const { toast } = useToast(); const [versions, setVersions] = useState([]); const [buildJobs, setBuildJobs] = useState([]); const [resources, setResources] = useState([]); const [loading, setLoading] = useState(true); const [actionKey, setActionKey] = useState(''); const [logTarget, setLogTarget] = useState(null); const [logs, setLogs] = useState(''); const [logLoading, setLogLoading] = useState(false); const [envTarget, setEnvTarget] = useState(null); const [envVariables, setEnvVariables] = useState>([]); const [envLoading, setEnvLoading] = useState(false); const [envSaving, setEnvSaving] = useState(false); const loadingVisible = useMinimumLoading(loading || logLoading); const activeVersion = useMemo(() => versions.find((version) => version.isActive) ?? versions[0], [versions]); const latestBuild = useMemo(() => buildJobs[0], [buildJobs]); const refresh = () => { setLoading(true); Promise.all([ listLauncherVersions().catch(() => []), listLauncherBuildJobs().catch(() => []), loadLauncherRuntimeResources(LAUNCHER_NAMESPACE) ]) .then(([nextVersions, nextBuildJobs, runtime]) => { setVersions(nextVersions); setBuildJobs(nextBuildJobs); setResources(runtime.resources ?? []); }) .catch((error: Error) => { toast({ type: 'error', title: '런처 구성요소 조회 실패', message: error.message }); }) .finally(() => setLoading(false)); }; useEffect(() => { refresh(); }, []); const openLogs = (component: LauncherComponentDefinition) => { if (!component.kind || !component.workloadName) return; setLogTarget(component); setLogs(''); setLogLoading(true); loadLauncherComponentLogs(LAUNCHER_NAMESPACE, apiKind(component.kind), component.workloadName) .then((result) => setLogs(stripAnsi(result.logs || '로그가 없습니다.'))) .catch((error: Error) => setLogs(`[warn] 로그 조회 실패\n${error.message}`)) .finally(() => setLogLoading(false)); }; const restart = (component: LauncherComponentDefinition) => { if (!component.kind || !component.workloadName) return; setActionKey(component.key); restartLauncherComponent(LAUNCHER_NAMESPACE, apiKind(component.kind), component.workloadName) .then(() => { toast({ type: 'success', message: `${component.name} 재시작을 요청했습니다.` }); refresh(); }) .catch((error: Error) => { toast({ type: 'error', title: '재시작 실패', message: error.message }); }) .finally(() => setActionKey('')); }; const openEnv = (component: LauncherComponentDefinition) => { if (!component.kind || !component.workloadName) return; setEnvTarget(component); setEnvVariables([]); setEnvLoading(true); loadRuntimeWorkloadEnv(LAUNCHER_NAMESPACE, apiKind(component.kind), component.workloadName) .then((result) => { setEnvVariables(result.variables ?? []); }) .catch((error: Error) => { toast({ type: 'error', title: '설정값 조회 실패', message: error.message }); }) .finally(() => setEnvLoading(false)); }; const updateEnvVariable = (index: number, patch: Partial<{ key: string; value: string; isSecret: boolean }>) => { setEnvVariables((prev) => prev.map((variable, variableIndex) => ( variableIndex === index ? { ...variable, ...patch } : variable ))); }; const removeEnvVariable = (index: number) => { setEnvVariables((prev) => prev.filter((_, variableIndex) => variableIndex !== index)); }; const saveEnv = () => { if (!envTarget?.kind || !envTarget.workloadName) return; setEnvSaving(true); saveRuntimeWorkloadEnv( LAUNCHER_NAMESPACE, apiKind(envTarget.kind), envTarget.workloadName, envVariables .filter((variable) => variable.editable) .map((variable) => ({ key: variable.key.trim(), value: variable.value, isSecret: variable.isSecret })) .filter((variable) => variable.key) ) .then((result) => { setEnvVariables(result.variables ?? []); toast({ type: 'success', title: '설정값 저장', message: `${envTarget.name} 설정값을 반영했습니다.` }); refresh(); }) .catch((error: Error) => { toast({ type: 'error', title: '설정값 저장 실패', message: error.message }); }) .finally(() => setEnvSaving(false)); }; return ( <> 새로고침 } />

런처 최신 버전

{activeVersion?.version ?? '-'}

{launcherArtifactLabel(activeVersion)}

{launcherVersionMeta(activeVersion)}

최근 클라이언트 빌드

{latestBuild?.version ?? '-'}

{buildStatusText(latestBuild?.status)}

Namespace

{LAUNCHER_NAMESPACE}

{resources.length}개 관련 리소스 조회

{launcherComponents.map((component) => { const Icon = componentIcon(component.type); const workload = findResource(resources, component.kind, component.workloadName); const service = serviceResource(resources, component.serviceName); const details = relatedResources(resources, component); const isClient = component.type === 'client'; const status = isClient ? (activeVersion ? '배포 등록' : '미등록') : workload?.status ?? 'NotFound'; return ( {status}} />

{component.key}

{isClient ? 'Client Package' : `${component.kind}/${component.workloadName}`}

{isClient ? ( <>

Artifact

{activeVersion?.artifact ?? '-'}

Repository

{activeVersion?.repository ?? '-'}

) : ( <>

Ready

{workload?.ready ?? '-'}

Service

{service ? `${service.status} · ${service.detail}` : '-'}

Image

{workload?.detail ?? '-'}

)}
{!isClient ? (
{component.type === 'backend' ? ( ) : null}
) : null}
{isClient ? ( ) : null} {!isClient && details.length === 0 ? ( ) : null} {!isClient && details.map((resource) => ( ))}
Kind Name Status Ready Age Detail
Release {activeVersion?.version ?? '-'} {activeVersion?.isActive ? 'Active' : '-'} - {activeVersion?.createdAt ? new Date(activeVersion.createdAt).toLocaleString() : '-'} {activeVersion?.downloadUrl ?? '-'}
관련 리소스가 없습니다.
{resource.kind} {resource.name} {resource.status} {resource.ready} {resource.age} {resource.detail || '-'}
); })}
setLogTarget(null)} className="!max-w-5xl" >
          {logs || (logLoading ? '로그를 불러오는 중...' : '로그가 없습니다.')}
        
setEnvTarget(null)} className="!max-w-4xl" footer={ <> } >

Secret을 체크하면 Kubernetes Secret에 저장하고 secretKeyRef로 연결합니다. 체크하지 않은 값은 Deployment 환경변수로 저장합니다.

{envLoading ? ( ) : null} {!envLoading && envVariables.length === 0 ? ( ) : null} {!envLoading && envVariables.map((variable, index) => ( ))}
Key Value Secret Source
설정값을 불러오는 중입니다.
등록된 설정값이 없습니다.
updateEnvVariable(index, { key: event.target.value })} /> updateEnvVariable(index, { value: event.target.value })} /> {variable.source}
); }