feat: LokiDeploy 初始提交 - 轻量级 K8s Loki 部署平台

Go(Gin) + React(Vite + shadcn/ui + Tailwind) 前后端分离,全中文 UI

- 集群管理:Kubeconfig / Token 双接入,kubectl + helm 部署
- 主机管理:SSH 密钥 / 密码双认证,CPU/内存/磁盘使用率监控,SSH 错误中文友好提示
- 存储配置、部署管理、系统设置
- Docker 镜像内置 kubectl + helm,开箱即用
- run.sh 一键启停(start/stop/restart/status)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Logan.LiandClaude committed 2026-06-29 17:03:57 +08:00
commit 2a93de600d
134 files changed
+19595

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
import { request } from './client';
import type { User } from '@/types';
export const authApi = {
login: (username: string, password: string) =>
request<{ token: string; user: User }>('/auth/login', {
method: 'POST',
body: JSON.stringify({ username, password }),
}),
register: (username: string, password: string, nickname: string, role?: string) =>
request<User>('/auth/register', {
method: 'POST',
body: JSON.stringify({ username, password, nickname, role: role || 'user' }),
}),
getCurrentUser: () => request<User>('/auth/user'),
changePassword: (oldPassword: string, newPassword: string) =>
request<{ message: string }>('/auth/password', {
method: 'POST',
body: JSON.stringify({ oldPassword, newPassword }),
}),
};
+49
View File
@@ -0,0 +1,49 @@
import type { ApiResponse } from '@/types';
const API_BASE = import.meta.env.VITE_API_URL || '';
function getToken(): string | null {
return localStorage.getItem('token');
}
export async function request<T>(url: string, options: RequestInit = {}): Promise<T> {
const token = getToken();
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...((options.headers as Record<string, string>) || {}),
};
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
const fullUrl = `${API_BASE}/api/v1${url}`;
try {
const response = await fetch(fullUrl, { ...options, headers });
if (response.status === 401) {
localStorage.removeItem('token');
localStorage.removeItem('user');
window.location.href = '/login';
throw new Error('Unauthorized');
}
const contentType = response.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
const text = await response.text();
throw new Error(`Server returned non-JSON (${response.status}): ${text.substring(0, 200)}`);
}
const data = await response.json() as ApiResponse<T>;
if (data.code !== 0) {
throw new Error(data.message || 'Request failed');
}
return data.data;
} catch (err) {
if (err instanceof TypeError && err.message.includes('fetch')) {
throw new Error('Cannot connect to backend server. Please ensure the API server is running.');
}
throw err;
}
}
+23
View File
@@ -0,0 +1,23 @@
import { request } from './client';
import type { PageData, Cluster, ClusterInfo } from '@/types';
export const clusterApi = {
list: (page = 1, pageSize = 10) =>
request<PageData<Cluster>>(`/clusters?page=${page}&pageSize=${pageSize}`),
get: (id: number) => request<Cluster>(`/clusters/${id}`),
create: (data: {
name: string; description?: string; configType?: string;
apiServer?: string; kubeconfig?: string; token?: string; context?: string;
}) => request<Cluster>('/clusters', { method: 'POST', body: JSON.stringify(data) }),
update: (id: number, data: Record<string, unknown>) =>
request<{ message: string }>(`/clusters/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
remove: (id: number) => request<{ message: string }>(`/clusters/${id}`, { method: 'DELETE' }),
validate: (id: number) => request<{ message: string }>(`/clusters/${id}/validate`, { method: 'POST' }),
getInfo: (id: number) => request<ClusterInfo>(`/clusters/${id}/info`),
};
+28
View File
@@ -0,0 +1,28 @@
import { request } from './client';
import type { PageData, LokiDeployment, DeploymentLog, DashboardStats, CreateDeploymentRequest } from '@/types';
export const deploymentApi = {
list: (page = 1, pageSize = 10) =>
request<PageData<LokiDeployment>>(`/deployments?page=${page}&pageSize=${pageSize}`),
get: (id: number) => request<LokiDeployment>(`/deployments/${id}`),
create: (data: CreateDeploymentRequest) =>
request<LokiDeployment>('/deployments', { method: 'POST', body: JSON.stringify(data) }),
update: (id: number, data: Record<string, unknown>) =>
request<{ message: string }>(`/deployments/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
remove: (id: number) => request<{ message: string }>(`/deployments/${id}`, { method: 'DELETE' }),
deploy: (id: number) => request<{ message: string }>(`/deployments/${id}/deploy`, { method: 'POST' }),
stop: (id: number) => request<{ message: string }>(`/deployments/${id}/stop`, { method: 'POST' }),
restart: (id: number) => request<{ message: string }>(`/deployments/${id}/restart`, { method: 'POST' }),
logs: (id: number, page = 1, pageSize = 50) =>
request<PageData<DeploymentLog>>(`/deployments/${id}/logs?page=${page}&pageSize=${pageSize}`),
stats: () => request<DashboardStats>('/deployments/stats'),
};
+29
View File
@@ -0,0 +1,29 @@
import { request } from './client';
import type { PageData, Host, HostInfo } from '@/types';
export const hostApi = {
list: (page = 1, pageSize = 10) =>
request<PageData<Host>>(`/hosts?page=${page}&pageSize=${pageSize}`),
get: (id: number) => request<Host>(`/hosts/${id}`),
create: (data: {
name: string; hostIP: string; port?: number; user: string;
authType: 'password' | 'key'; password?: string; privateKey?: string;
keyPhrase?: string; os?: string; arch?: string; labels?: string;
}) => request<Host>('/hosts', { method: 'POST', body: JSON.stringify(data) }),
update: (id: number, data: Record<string, unknown>) =>
request<{ message: string }>(`/hosts/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
remove: (id: number) => request<{ message: string }>(`/hosts/${id}`, { method: 'DELETE' }),
validate: (id: number) => request<{ message: string }>(`/hosts/${id}/validate`, { method: 'POST' }),
getInfo: (id: number) => request<HostInfo>(`/hosts/${id}/info`),
execute: (id: number, command: string) =>
request<{ stdout: string; stderr: string }>(`/hosts/${id}/execute`, {
method: 'POST', body: JSON.stringify({ command }),
}),
};
+6
View File
@@ -0,0 +1,6 @@
export { request } from './client';
export { authApi } from './auth';
export { clusterApi } from './cluster';
export { hostApi } from './host';
export { storageApi } from './storage';
export { deploymentApi } from './deployment';
+23
View File
@@ -0,0 +1,23 @@
import { request } from './client';
import type { PageData, StorageConfig } from '@/types';
export const storageApi = {
list: (page = 1, pageSize = 10) =>
request<PageData<StorageConfig>>(`/storages?page=${page}&pageSize=${pageSize}`),
get: (id: number) => request<StorageConfig>(`/storages/${id}`),
create: (data: {
name: string; storageType: 's3' | 'oss' | 'minio' | 'rustfs';
endpoint?: string; bucket: string; region?: string;
accessKey?: string; secretKey?: string; pathPrefix?: string;
insecure?: boolean; isDefault?: boolean;
}) => request<StorageConfig>('/storages', { method: 'POST', body: JSON.stringify(data) }),
update: (id: number, data: Record<string, unknown>) =>
request<{ message: string }>(`/storages/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
remove: (id: number) => request<{ message: string }>(`/storages/${id}`, { method: 'DELETE' }),
getDefault: () => request<StorageConfig>('/storages/default'),
};