Skip to content

Commit

Permalink
feat:db add database type for migration and external network access (#…
Browse files Browse the repository at this point in the history
…4317)

* feat:db add database type for migration and external network access

Signed-off-by: jingyang <3161362058@qq.com>

* fix ci

Signed-off-by: jingyang <3161362058@qq.com>

---------

Signed-off-by: jingyang <3161362058@qq.com>
  • Loading branch information
zjy365 committed Nov 20, 2023
1 parent 881e165 commit f9f2d61
Show file tree
Hide file tree
Showing 77 changed files with 4,678 additions and 367 deletions.
324 changes: 323 additions & 1 deletion frontend/pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion frontend/providers/applaunchpad/src/pages/_app.tsx
Expand Up @@ -138,7 +138,6 @@ const App = ({ Component, pageProps }: AppProps) => {
const event = async (e: MessageEvent) => {
const envs = await getPlatformEnv();
const whitelist = [`https://${envs?.domain}`];
console.log(e, whitelist, 'post message');
if (!whitelist.includes(e.origin)) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/providers/applaunchpad/src/pages/api/delApp.ts
Expand Up @@ -80,7 +80,7 @@ export async function DeleteAppByName({ name, req }: DeleteAppParams & { req: Ne
delDependent.forEach((item) => {
console.log(item, 'delApp err');
if (item.status === 'rejected' && +item?.reason?.body?.code !== 404) {
throw new Error('删除 App 异常');
throw new Error(item?.reason?.body?.reason || item?.reason?.body?.message || '删除 App 异常');
}
});

Expand All @@ -94,7 +94,7 @@ export async function DeleteAppByName({ name, req }: DeleteAppParams & { req: Ne
delApp.forEach((item) => {
console.log(item, 'delApp err');
if (item.status === 'rejected' && +item?.reason?.body?.code !== 404) {
throw new Error(item?.reason?.body);
throw new Error(item?.reason?.body?.reason || item?.reason?.body?.message || '删除 App 异常');
}
});
}
1 change: 0 additions & 1 deletion frontend/providers/cronjob/src/pages/_app.tsx
Expand Up @@ -130,7 +130,6 @@ function App({ Component, pageProps }: AppProps) {
const event = async (e: MessageEvent) => {
const envs = await getPlatformEnv();
const whitelist = [`https://${envs?.domain}`];
console.log(e, whitelist, 'post message');
if (!whitelist.includes(e.origin)) {
return;
}
Expand Down
6 changes: 5 additions & 1 deletion frontend/providers/dbprovider/.env.template
Expand Up @@ -2,4 +2,8 @@ NEXT_PUBLIC_MOCK_USER=
SEALOS_DOMAIN="cloud.sealos.io"
FASTGPT_KEY=
STORAGE_CLASSNAME=choosable
MONITOR_URL=""
MONITOR_URL=""

MINIO_URL=""
MINIO_ACCESS_KEY=""
MINIO_SECRET_KEY=""
18 changes: 9 additions & 9 deletions frontend/providers/dbprovider/next.config.js
@@ -1,8 +1,8 @@
/** @type {import('next').NextConfig} */
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const { i18n } = require('./next-i18next.config');
const analyzer = process.env === 'production' ? [new BundleAnalyzerPlugin()] : [];
const path = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const { i18n } = require('./next-i18next.config')
const analyzer = process.env === 'production' ? [new BundleAnalyzerPlugin()] : []
const path = require('path')
const nextConfig = {
i18n,
output: 'standalone',
Expand All @@ -15,14 +15,14 @@ const nextConfig = {
issuer: /\.[jt]sx?$/,
use: ['@svgr/webpack']
}
]);
config.plugins = [...config.plugins, ...analyzer];
return config;
])
config.plugins = [...config.plugins, ...analyzer]
return config
},
experimental: {
// this includes files from the monorepo base two directories up
outputFileTracingRoot: path.join(__dirname, '../../')
}
};
}

module.exports = nextConfig;
module.exports = nextConfig
3 changes: 3 additions & 0 deletions frontend/providers/dbprovider/package.json
Expand Up @@ -34,6 +34,8 @@
"js-yaml": "^4.1.0",
"jszip": "^3.10.1",
"lodash": "^4.17.21",
"minio": "^7.1.3",
"multer": "1.4.5-lts.1",
"nanoid": "^4.0.2",
"next": "13.1.6",
"next-i18next": "^13.3.0",
Expand All @@ -56,6 +58,7 @@
"@types/js-cookie": "^3.0.4",
"@types/js-yaml": "^4.0.6",
"@types/lodash": "^4.14.199",
"@types/multer": "^1.4.10",
"@types/node": "18.13.0",
"@types/nprogress": "^0.2.1",
"@types/react": "18.2.37",
Expand Down
62 changes: 58 additions & 4 deletions frontend/providers/dbprovider/public/locales/en/common.json
Expand Up @@ -34,6 +34,7 @@
"Start Error": "Start Success",
"Submit Error": "Submit Error",
"Export": "Export",
"Deploy": "Deploy",
"Edit Environment Variables": "Edit Environment Variables",
"DataBase Deployment": "DataBase Deployment",
"Creating": "Creating",
Expand Down Expand Up @@ -66,7 +67,7 @@
"Backup List": "Backup List",
"DataBase Info": "DataBase Info",
"DataBase Type": "DataBase Type",
"DataBase Version": "DataBase Version",
"Version": "Version",
"Config Info": "Config",
"Limit CPU": "Limit CPU",
"Limit Memory": "Limit Memory",
Expand All @@ -89,7 +90,7 @@
"Remark": "Remark",
"Confirm Create Backup": "Confirm Create Backup?",
"Confirm delete the backup": "Confirm delete the backup",
"Basic Info": "Basic",
"Basic": "Basic",
"Restore Backup Tip": "Restoring the backup will create a new database, and you will need to provide the name of the new data, which cannot be the same as the current database.",
"Total Price": "Total",
"Redis HA": "HA",
Expand Down Expand Up @@ -129,5 +130,58 @@
"The container exposed port cannot be empty": "The container exposed port cannot be empty",
"The minimum exposed port is 1": "The minimum exposed port is 1",
"The maximum number of exposed ports is 65535": "The maximum number of exposed ports is 65535"
}
}
},
"common": {
"Total": "Total",
"Used": "Used",
"Surplus": "Surplus"
},
"Data Migration Config": "Data Migration Config",
"Migrate Now": "Migrate Now",
"Migration Preparation": "Migration Preparation",
"Continuous Migration": "Continuous Migration",
"Migrate": "Migrate",
"Advanced Configuration": "Advanced Configuration",
"Option": "Option",
"Internet Migration": "Internet Migration",
"Dump Import": "Dump Import",
"Source Database": "Source Database",
"Database Host": "Database Host",
"DB Name": "DataBase Name",
"DB Table": "DataBase Table",
"Username": "Username",
"Password": "Password",
"Port": "Port",
"Confirm delete the migrate": "Are you sure you want to delete the migration record?",
"Are you sure to perform database migration": "Are you sure to perform database migration?",
"Migration task created successfully": "Migration task created successfully",
"Upload dump file": "Upload Dump File",
"Target Database": "Target Database",
"Select a maximum of 10 files": "Select a maximum of 10 files",
"Redis does not support backup at this time": "Redis does not support backup at this time",
"Upload successful": "Upload Successful",
"Database Name Empty": "Database Name Empty",
"Parameter Error": "Parameter Error",
"Lost File": "Lost File",
"File upload failed": "File upload failed",
"Migrating": "Migrating",
"Migration prompt information": "Do not perform operations during migration to avoid migration failure due to XXX. If the amount of data is large, the migration may take a long time, please be patient.",
"Migration Successful": "Migration Successful",
"External Network": "External Network",
"Enable external network access": "Enable external network access",
"Billing Standards": "Billing Standards",
"Hour": "Hour",
"Turn On": "Turn On",
"Success": "Success",
"Service Deletion Failed": "Service Deletion Failed",
"Intranet Address": "Intranet Address",
"Successfully closed external network access": "Successfully closed external network access",
"External Address": "External Address",
"Enter Save": "Enter Save && All means exporting the entire library",
"Collection Name": "Collection Name",
"Database Host Empty": "Database Host Empty",
"Database Port Empty": "Database Port Empty",
"Database UserName Empty": "Database UserName Empty",
"Database Password Empty": "Database Password Empty",
"Migration Failed": "Migration Failed"
}
59 changes: 53 additions & 6 deletions frontend/providers/dbprovider/public/locales/zh/common.json
Expand Up @@ -72,13 +72,12 @@
"Backup List": "备份列表",
"DataBase Info": "数据库信息",
"Confirm Restart": "确认重启该应用?",
"DataBase Version": "数据库版本",
"DataBase Type": "数据库类型",
"Config Info": "配置信息",
"Limit CPU": "最大 CPU",
"Limit Memory": "最大内存",
"Connection Info": "连接信息",
"Direct Connection": "一键连接",
"Direct Connection": "连接",
"Delete Warning": "删除警告",
"Delete Hint": "如果确认要删除这个数据库吗?如果执行此操作,将删除该数据库的所有数据。",
"Please Enter": "请输入",
Expand All @@ -89,7 +88,6 @@
"Basic": "基础配置",
"Version": "版本",
"Deploy": "部署",
"Basic Info": "基本信息",
"Pod Name": "实例名",
"Restarts": "重启次数",
"Age": "运行时长",
Expand Down Expand Up @@ -132,7 +130,6 @@
"Friday": "周五",
"Saturday": "周六",
"Sunday": "周日",
"Start Hour": "小时",
"Start Minute": "分钟",
"Save": "保存",
"Hour": "小时",
Expand Down Expand Up @@ -176,5 +173,55 @@
"The container exposed port cannot be empty": "容器暴露端口不能为空",
"The minimum exposed port is 1": "暴露端口最小为 1",
"The maximum number of exposed ports is 65535": "暴露端口最大为65535"
}
}
},
"common": {
"Total": "总共",
"Used": "已用",
"Surplus": "剩余"
},
"Data Migration Config": "数据迁移配置",
"Migrate Now": "立即迁移",
"Migration Preparation": "迁移准备",
"Continuous Migration": "持续迁移",
"Migrate": "迁移",
"Advanced Configuration": "高级配置",
"Option": "选填",
"Internet Migration": "公网迁移",
"Dump Import": "Dump 导入",
"Source Database": "源数据库",
"Database Host": "数据库 Host",
"DB Name": "数据库名字",
"DB Table": "数据库表",
"Username": "用户名",
"Password": "密码",
"Port": "端口",
"Confirm delete the migrate": "确定删除迁移记录吗?",
"Are you sure to perform database migration": "确定执行数据库迁移吗?",
"Migration task created successfully": "迁移任务创建成功",
"Upload dump file": "上传 Dump 文件",
"Target Database": "目标数据库",
"Select a maximum of 10 files": "最多选择 10 个文件",
"Upload successful": "文件上传成功",
"Database Name Empty": "数据库名称不能为空",
"Parameter Error": "参数错误",
"Lost File": "缺少文件",
"File upload failed": "文件上传失败",
"Migrating": "正在迁移",
"Migration prompt information": "迁移时请勿执行操作,以免因XXX导致迁移失败。如数据量较大,迁移时间可能较长,请耐心等待",
"Migration Successful": "迁移成功",
"External Network": "外网访问",
"Enable external network access": "开启外网访问",
"Billing Standards": "计费标准",
"Turn On": "开启",
"Service Deletion Failed": "Service 删除失败",
"Intranet Address": "内网地址",
"Successfully closed external network access": "已关闭外网访问",
"External Address": "外网地址",
"Enter Save": "回车保存 && All 代表导出整个库",
"Collection Name": "集合名称",
"Database Host Empty": "缺少 DataBase Host",
"Database Port Empty": "缺少数据库端口",
"Database UserName Empty": "缺少数据库用户名",
"Database Password Empty": "缺少数据库密码",
"Migration Failed": "迁移失败"
}
1 change: 0 additions & 1 deletion frontend/providers/dbprovider/src/api/backup.ts
Expand Up @@ -9,7 +9,6 @@ export const getBackupPolicy = (data: { dbName: string; dbType: string }) =>
export const createBackup = (data: CreateBackupPros) => POST('/api/backup/create', data);
export const getBackupList = (dbName: string) =>
GET('/api/backup/getBackupList', { dbName }).then((res) => res.map(adaptBackup));

export const deleteBackup = (backupName: string) =>
DELETE(`/api/backup/delBackup?backupName=${backupName}`);
export const updateBackupPolicy = (data: UpdatePolicyProps) =>
Expand Down
6 changes: 6 additions & 0 deletions frontend/providers/dbprovider/src/api/db.ts
Expand Up @@ -4,6 +4,7 @@ import type { DBType, PodDetailType } from '@/types/db';
import { json2Restart } from '@/utils/json2Yaml';
import { json2StartOrStop } from '../utils/json2Yaml';
import type { SecretResponse } from '@/pages/api/getSecretByName';
import { V1Service } from '@kubernetes/client-node';

export const getMyDBList = () => GET('/api/getDBList').then((data) => data.map(adaptDBListItem));

Expand Down Expand Up @@ -55,3 +56,8 @@ export const startDBByName = (data: { dbName: string; dbType: DBType }) => {
});
return applyYamlList([yaml], 'update');
};

export const getDBServiceByName = (name: string) =>
GET<V1Service>(`/api/getServiceByName?name=${name}`);

export const delDBServiceByName = (name: string) => DELETE('/api/delServiceByName', { name });
38 changes: 38 additions & 0 deletions frontend/providers/dbprovider/src/api/migrate.ts
@@ -0,0 +1,38 @@
import { DELETE, GET, POST } from '@/services/request';
import { InternetMigrationCR } from '@/types/migrate';
import { adaptMigrateList } from '@/utils/adapt';
import { V1Pod } from '@kubernetes/client-node';

export const getMigrateList = (migrateName: string) =>
GET<InternetMigrationCR[]>('/api/migrate/list', { migrateName }).then((res) =>
res.map(adaptMigrateList).sort((a, b) => {
const startTimeA = new Date(a.startTime).getTime();
const startTimeB = new Date(b.startTime).getTime();
return startTimeB - startTimeA;
})
);

export const deleteMigrateByName = (migrateName: string) =>
DELETE<InternetMigrationCR[]>('/api/migrate/delete', { migrateName });

export const getMigratePodList = (
migrateName: string,
migrateType: 'network' | 'file' = 'network'
) =>
GET<V1Pod[]>('/api/migrate/getPodList', { migrateName, migrateType }).then((res) => {
return res.sort((a, b) => {
const startTimeA = new Date(a.metadata?.creationTimestamp || '').getTime();
const startTimeB = new Date(b.metadata?.creationTimestamp || '').getTime();
return startTimeA - startTimeB;
});
});

export const getLogByNameAndContainerName = (data: {
containerName: string;
podName: string;
stream: boolean;
logSize?: number;
}) => POST<string>('/api/migrate/getLogByName', data);

export const getPodStatusByName = (podName: string) =>
GET(`/api/pod/getPodStatus?podName=${podName}`);
12 changes: 11 additions & 1 deletion frontend/providers/dbprovider/src/api/platform.ts
@@ -1,8 +1,10 @@
import { Response as EnvResponse } from '@/pages/api/getEnv';
import type { Response as DBVersionMapType } from '@/pages/api/platform/getVersion';
import type { Response as resourcePriceResponse } from '@/pages/api/platform/resourcePrice';
import { GET } from '@/services/request';
import { GET, POST } from '@/services/request';

import type { UserQuotaItemType } from '@/types/user';
import axios from 'axios';

export const getResourcePrice = () => GET<resourcePriceResponse>('/api/platform/resourcePrice');

Expand All @@ -15,3 +17,11 @@ export const getUserQuota = () =>
balance: number;
quota: UserQuotaItemType[];
}>('/api/platform/getQuota');

export const uploadFile = (data: FormData) => {
return POST<string[]>('/api/minio/upload', data, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
};

0 comments on commit f9f2d61

Please sign in to comment.