Skip to content

Commit

Permalink
chore: update launchpad config to use yaml. (labring#4706)
Browse files Browse the repository at this point in the history
* chore: update launchpad config to use yaml.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* chore: update launchpad config to use yaml.
Signed-off-by: yy <[email protected]>

* chore: update launchpad config to use yaml.
Signed-off-by: yy <[email protected]>

* chore: update launchpad config to use yaml.
Signed-off-by: yy <[email protected]>

* chore: update launchpad config to use yaml.
Signed-off-by: yy <[email protected]>

---------

Signed-off-by: yy <[email protected]>
  • Loading branch information
lingdie authored Apr 24, 2024
1 parent 1d0ad5c commit 3458948
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 108 deletions.
37 changes: 18 additions & 19 deletions frontend/providers/applaunchpad/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
module.exports = {
printWidth: 100,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: true,
quoteProps: 'as-needed',
jsxSingleQuote: false,
trailingComma: 'none',
bracketSpacing: true,
jsxBracketSameLine: false,
arrowParens: 'always',
rangeStart: 0,
rangeEnd: Infinity,
requirePragma: false,
insertPragma: false,
proseWrap: 'preserve',
htmlWhitespaceSensitivity: 'css',
endOfLine: 'lf'
printWidth: 100,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: true,
quoteProps: 'as-needed',
jsxSingleQuote: false,
trailingComma: 'none',
bracketSpacing: true,
jsxBracketSameLine: false,
arrowParens: 'always',
rangeStart: 0,
rangeEnd: Infinity,
requirePragma: false,
insertPragma: false,
proseWrap: 'preserve',
htmlWhitespaceSensitivity: 'css',
endOfLine: 'lf'
};

18 changes: 18 additions & 0 deletions frontend/providers/applaunchpad/data/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cloud:
domain: 127.0.0.1.nip.io
port: ""
common:
guideEnabled: "false"
apiEnabled: "false"
launchpad:
ingressTlsSecretName: wildcard-cert
eventAnalyze:
enabled: "false"
fastGPTKey: ""
components:
monitor:
url: http://launchpad-monitor.sealos.svc.cluster.local:8428
appResourceFormSliderConfig:
default:
cpu: [100, 200, 500, 1000, 2000, 3000, 4000, 8000]
memory: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]
6 changes: 0 additions & 6 deletions frontend/providers/applaunchpad/data/form_slider_config.json

This file was deleted.

46 changes: 21 additions & 25 deletions frontend/providers/applaunchpad/deploy/manifests/deploy.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ metadata:
namespace: applaunchpad-frontend
data:
config.yaml: |-
addr: :3000
form_slider_config.json: |-
{
"NoGpu": {
"cpu": [100, 200, 500, 1000, 2000, 3000, 4000, 8000],
"memory": [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]
}
}
cloud:
domain: {{ .cloudDomain }}
port: {{ if .cloudPort }}:{{ .cloudPort }}{{ end }}
common:
guideEnabled: "{{ .guideEnabled }}"
apiEnabled: "{{ .apiEnabled }}"
launchpad:
ingressTlsSecretName: {{ .ingressTlsSecretName }}
eventAnalyze:
enabled: "false"
fastGPTKey: ""
components:
monitor:
url: {{ .monitorUrl }}
appResourceFormSliderConfig:
default:
cpu: [100, 200, 500, 1000, 2000, 3000, 4000, 8000]
memory: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]
---
apiVersion: apps/v1
kind: Deployment
Expand All @@ -42,18 +52,7 @@ spec:
app: applaunchpad-frontend
spec:
containers:
- env:
- name: SEALOS_DOMAIN
value: {{ .cloudDomain }}
- name: MONITOR_URL
value: {{ .monitorUrl }}
- name: DOMAIN_PORT
value: "{{ if .cloudPort }}:{{ .cloudPort }}{{ end }}"
- name: INGRESS_SECRET
value: {{ .ingressSecret }}
- name: GUIDE_ENABLED
value: "false"
name: applaunchpad-frontend
- name: applaunchpad-frontend
securityContext:
runAsNonRoot: true
runAsUser: 1001
Expand All @@ -72,12 +71,9 @@ spec:
image: ghcr.io/labring/sealos-applaunchpad-frontend:latest
imagePullPolicy: Always
volumeMounts:
- name: applaunchpad-frontend-volume
mountPath: /config.yaml
subPath: config.yaml
- mountPath: /app/data/form_slider_config.json
- mountPath: /app/data/config.yaml
name: applaunchpad-frontend-volume
subPath: form_slider_config.json
subPath: config.yaml
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
Expand Down
2 changes: 1 addition & 1 deletion frontend/providers/applaunchpad/src/constants/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const ProtocolList = [
{ value: 'WS', label: 'wss://' }
];

export const noGpuSliderKey = 'NoGpu';
export const defaultSliderKey = 'default';
export const pauseKey = 'deploy.cloud.sealos.io/pause';
export const maxReplicasKey = 'deploy.cloud.sealos.io/maxReplicas';
export const minReplicasKey = 'deploy.cloud.sealos.io/minReplicas';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function streamFetch(res: NextApiResponse<ApiResp>, events: any) {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.FASTGPT_KEY}`
Authorization: `Bearer ${global.AppConfig.launchpad.eventAnalyze.fastGPTKey}`
},
body: JSON.stringify({
stream: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
try {
if (process.env.GUIDE_ENABLED !== 'true') return jsonRes(res, { data: null });
if (!global.AppConfig.common.guideEnabled) return jsonRes(res, { data: null });
const kubeconfig = await authSession(req.headers);
const domain = process.env.SEALOS_DOMAIN;
const domain = global.AppConfig.cloud.domain;
console.log(`https://${domain}/api/v1alpha/account/getAccount`);

const response = await fetch(`https://${domain}/api/v1alpha/account/getAccount`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
try {
if (process.env.GUIDE_ENABLED !== 'true') return jsonRes(res, { data: null });
if (global.AppConfig.common.guideEnabled) return jsonRes(res, { data: null });
const { k8sCore, namespace } = await getK8s({
kubeconfig: await authSession(req.headers)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export type UpdateUserGuideParams = {

export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
try {
if (process.env.GUIDE_ENABLED !== 'true') return jsonRes(res, { data: null });
if (global.AppConfig.common.guideEnabled) return jsonRes(res, { data: null });
const { activityType, phase, phasePage, shouldSendGift } = req.body as UpdateUserGuideParams;

if (!activityType || !phase || !phasePage)
return jsonRes(res, { code: 400, message: 'Bad Request: Invalid parameters' });
const kubeconfig = await authSession(req.headers);
const domain = process.env.SEALOS_DOMAIN;
const domain = global.AppConfig.cloud.domain;

const payload = {
activityType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type { NextApiRequest, NextApiResponse } from 'next';
export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
jsonRes<EnvResponse>(res, {
data: {
domain: process.env.SEALOS_DOMAIN || 'cloud.sealos.io',
guideEnabled: process.env.GUIDE_ENABLED === 'true'
domain: global.AppConfig.cloud.domain || 'cloud.sealos.io',
guideEnabled: global.AppConfig.common.guideEnabled
}
});
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/services/backend/response';
import type { FormSliderListType } from '@/types';
import type { AppConfigType, FormSliderListType } from '@/types';
import { readFileSync } from 'fs';
import { Coin, noGpuSliderKey } from '@/constants/app';
import { Coin } from '@/constants/app';
import * as yaml from 'js-yaml';

// todo make response type to be more specific and clear.
export type Response = {
SEALOS_DOMAIN: string;
DOMAIN_PORT: string;
Expand All @@ -13,39 +15,56 @@ export type Response = {
CURRENCY: Coin;
};

export const defaultVal = {
[noGpuSliderKey]: {
cpu: [100, 200, 500, 1000, 2000, 3000, 4000, 8000],
memory: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]
export const defaultAppConfig: AppConfigType = {
cloud: {
domain: 'cloud.sealos.io',
port: ''
},
common: {
guideEnabled: false,
apiEnabled: false
},
launchpad: {
ingressTlsSecretName: 'wildcard-cert',
eventAnalyze: {
enabled: false,
fastGPTKey: ''
},
components: {
monitor: {
url: 'http://launchpad-monitor.sealos.svc.cluster.local:8428'
}
},
appResourceFormSliderConfig: {
default: {
cpu: [100, 200, 500, 1000, 2000, 3000, 4000, 8000],
memory: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]
}
}
}
};

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
if (!global.FormSliderListConfig) {
if (!global.AppConfig) {
const filename =
process.env.NODE_ENV === 'development'
? 'data/form_slider_config.json.local'
: '/app/data/form_slider_config.json';

const res = JSON.parse(readFileSync(filename, 'utf-8'));
process.env.NODE_ENV === 'development' ? 'data/config.yaml.local' : '/app/data/config.yaml';
const res: any = yaml.load(readFileSync(filename, 'utf-8'));
console.log(res);

global.FormSliderListConfig = res;
global.AppConfig = res;
}
} catch (error) {
console.log('error: /api/platform/getInitData', error);

global.FormSliderListConfig = defaultVal;
global.AppConfig = defaultAppConfig;
}
jsonRes<Response>(res, {
data: {
SEALOS_DOMAIN: process.env.SEALOS_DOMAIN || 'cloud.sealos.io',
DOMAIN_PORT: process.env.DOMAIN_PORT || '',
INGRESS_SECRET: process.env.INGRESS_SECRET || 'wildcard-cert',
SHOW_EVENT_ANALYZE: !!process.env.FASTGPT_KEY,
FORM_SLIDER_LIST_CONFIG: global.FormSliderListConfig,
CURRENCY: (process.env['CURRENCY'] || Coin.shellCoin) as Coin
SEALOS_DOMAIN: global.AppConfig.cloud.domain,
DOMAIN_PORT: global.AppConfig.cloud.port?.toString() || '',
INGRESS_SECRET: global.AppConfig.launchpad.ingressTlsSecretName,
SHOW_EVENT_ANALYZE: global.AppConfig.launchpad.eventAnalyze.enabled,
FORM_SLIDER_LIST_CONFIG: global.AppConfig.launchpad.appResourceFormSliderConfig,
CURRENCY: Coin.shellCoin
}
});
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { obj2Query } from '@/api/tools';
import MyIcon from '@/components/Icon';
import { MyTooltip } from '@sealos/ui';
import { RangeInput } from '@sealos/ui';
import { MySelect } from '@sealos/ui';
import { MySlider } from '@sealos/ui';
import { ProtocolList, noGpuSliderKey } from '@/constants/app';
import { MyRangeSlider, MySelect, MySlider, MyTooltip, RangeInput, Tabs, Tip } from '@sealos/ui';
import { defaultSliderKey, ProtocolList } from '@/constants/app';
import { GpuAmountMarkList } from '@/constants/editApp';
import { useToast } from '@/hooks/useToast';
import { useGlobalStore } from '@/store/global';
Expand Down Expand Up @@ -33,14 +30,13 @@ import {
useDisclosure,
useTheme
} from '@chakra-ui/react';
import { MyRangeSlider, Tabs, Tip } from '@sealos/ui';
import { throttle } from 'lodash';
import { customAlphabet } from 'nanoid';
import { useTranslation } from 'next-i18next';
import dynamic from 'next/dynamic';
import { useRouter } from 'next/router';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { UseFormReturn, useFieldArray } from 'react-hook-form';
import { useFieldArray, UseFormReturn } from 'react-hook-form';
import type { ConfigMapType } from './ConfigmapModal';
import type { CustomAccessModalParams } from './CustomAccessModal';
import PriceBox from './PriceBox';
Expand Down Expand Up @@ -274,7 +270,7 @@ const Form = ({
// cpu, memory have different sliderValue
const countSliderList = useCallback(() => {
const gpuType = getValues('gpu.type');
const key = gpuType && formSliderListConfig[gpuType] ? gpuType : noGpuSliderKey;
const key = gpuType && formSliderListConfig[gpuType] ? gpuType : defaultSliderKey;

return {
cpu: sliderNumber2MarkList({
Expand Down
7 changes: 3 additions & 4 deletions frontend/providers/applaunchpad/src/pages/app/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { postDeployApp, putApp } from '@/api/app';
import { updateDesktopGuide } from '@/api/platform';
import { noGpuSliderKey } from '@/constants/app';
import { defaultSliderKey } from '@/constants/app';
import { defaultEditVal, editModeMap } from '@/constants/editApp';
import { useConfirm } from '@/hooks/useConfirm';
import useDriver from '@/hooks/useDriver';
import { useLoading } from '@/hooks/useLoading';
import { useToast } from '@/hooks/useToast';
import { useAppStore } from '@/store/app';
import { useGlobalStore } from '@/store/global';
import { useUserStore } from '@/store/user';
Expand Down Expand Up @@ -234,8 +233,8 @@ const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) =>
if (!appName) {
const defaultApp = {
...defaultEditVal,
cpu: formSliderListConfig[noGpuSliderKey].cpu[0],
memory: formSliderListConfig[noGpuSliderKey].memory[0]
cpu: formSliderListConfig[defaultSliderKey].cpu[0],
memory: formSliderListConfig[defaultSliderKey].memory[0]
};
setAlready(true);
setYamlList([
Expand Down
8 changes: 4 additions & 4 deletions frontend/providers/applaunchpad/src/services/monitorFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ export const monitorFetch = async (props: AxiosRequestConfig, kubeconfig: string
Authorization: encodeURIComponent(kubeconfig)
}
};
const doMain = process.env.MONITOR_URL || 'http://monitor-system.cloud.sealos.run';
const doMain =
global.AppConfig.launchpad.components.monitor.url ||
'http://launchpad-monitor.sealos.svc.cluster.local:8428';

try {
const response = await fetch(`${doMain}${url}?${queryString}`, requestOptions);

if (!response.ok) {
throw new Error(`Error monitorFetch ${response.status}`);
}

const jsonResponse = await response.json();
return jsonResponse;
return await response.json();
} catch (error) {
throw error;
}
Expand Down
12 changes: 6 additions & 6 deletions frontend/providers/applaunchpad/src/store/global.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import { FormSliderListType } from '@/types';
import { noGpuSliderKey } from '@/constants/app';
import {create} from 'zustand';
import {devtools} from 'zustand/middleware';
import {immer} from 'zustand/middleware/immer';
import {FormSliderListType} from '@/types';
import {defaultSliderKey} from '@/constants/app';

type State = {
screenWidth: number;
Expand Down Expand Up @@ -37,7 +37,7 @@ export const useGlobalStore = create<State>()(
});
},
formSliderListConfig: {
[noGpuSliderKey]: {
[defaultSliderKey]: {
cpu: [100, 200, 500, 1000, 2000, 3000, 4000, 8000],
memory: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]
}
Expand Down
Loading

0 comments on commit 3458948

Please sign in to comment.