Skip to content

Commit

Permalink
feat:desktop add umami (#3676)
Browse files Browse the repository at this point in the history
Signed-off-by: jingyang <3161362058@qq.com>
  • Loading branch information
zjy365 committed Aug 16, 2023
1 parent 2bbd1dd commit 3be0e8f
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 15 deletions.
2 changes: 1 addition & 1 deletion frontend/desktop/.gitignore
Expand Up @@ -27,7 +27,7 @@ yarn-error.log*

# local env files
.env*.local

data/config.local.json
# vercel
.vercel

Expand Down
3 changes: 3 additions & 0 deletions frontend/desktop/data/config.json
@@ -0,0 +1,3 @@
{
"scripts": []
}
7 changes: 7 additions & 0 deletions frontend/desktop/deploy/manifests/deploy.yaml.tmpl
Expand Up @@ -37,6 +37,10 @@ metadata:
data:
config.yaml: |-
addr: :3000
config.json: |-
{
"scripts": []
}
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -165,6 +169,9 @@ spec:
- name: desktop-frontend-volume
mountPath: /config.yaml
subPath: config.yaml
- mountPath: /app/data/config.json
name: desktop-frontend-volume
subPath: config.json
resources:
limits:
cpu: 1000m
Expand Down
28 changes: 28 additions & 0 deletions frontend/desktop/src/pages/api/system/getSystemConfig.ts
@@ -0,0 +1,28 @@
import { jsonRes } from '@/services/backend/response';
import { SystemConfigType } from '@/types/system';
import { readFileSync } from 'fs';
import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const config = await getSystemConfig();
jsonRes(res, {
data: config,
code: 200
});
}

const defaultConfig: SystemConfigType = {
scripts: []
};

export async function getSystemConfig(): Promise<SystemConfigType> {
try {
const filename =
process.env.NODE_ENV === 'development' ? 'data/config.local.json' : '/app/data/config.json';
const res = JSON.parse(readFileSync(filename, 'utf-8'));
return res;
} catch (error) {
console.log('get system config error, set default');
return defaultConfig;
}
}
10 changes: 10 additions & 0 deletions frontend/desktop/src/pages/index.tsx
Expand Up @@ -6,11 +6,14 @@ import { enableRecharge } from '@/services/enable';
import request from '@/services/request';
import useAppStore from '@/stores/app';
import useSessionStore from '@/stores/session';
import { ApiResp } from '@/types';
import { SystemConfigType } from '@/types/system';
import { parseOpenappQuery } from '@/utils/format';
import { useColorMode } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useRouter } from 'next/router';
import Script from 'next/script';
import { createContext, useEffect, useState } from 'react';
const destination = '/signin';
interface IMoreAppsContext {
Expand All @@ -35,6 +38,10 @@ export default function Home({
const setAutoLaunch = useAppStore((state) => state.setAutoLaunch);
const cancelAutoLaunch = useAppStore((state) => state.cancelAutoLaunch);

const { data: systemConfig, refetch } = useQuery(['getSystemConfig'], () =>
request<any, ApiResp<SystemConfigType>>('/api/system/getSystemConfig')
);

useEffect(() => {
colorMode === 'dark' ? toggleColorMode() : null;
}, [colorMode, toggleColorMode]);
Expand Down Expand Up @@ -79,6 +86,9 @@ export default function Home({

return (
<Layout>
{systemConfig?.data?.scripts?.map((item, i) => {
return <Script key={i} {...item} />;
})}
<MoreAppsContext.Provider value={{ showMoreApps, setShowMoreApps }}>
<RechargeEnabledContext.Provider value={rechargeEnabled}>
<DesktopContent />
Expand Down
8 changes: 8 additions & 0 deletions frontend/desktop/src/types/system.ts
@@ -0,0 +1,8 @@
export type SystemConfigType = {
scripts: ScriptConfig[];
};

export type ScriptConfig = {
src: string;
'data-website-id'?: string;
};
2 changes: 2 additions & 0 deletions frontend/providers/dbprovider/deploy/Kubefile
Expand Up @@ -8,5 +8,7 @@ COPY manifests manifests
ENV cloudDomain="127.0.0.1.nip.io"
ENV cloudPort=""
ENV certSecretName="wildcard-cert"
ENV monitorUrl=""


CMD ["kubectl apply -f manifests"]
Expand Up @@ -42,6 +42,8 @@ spec:
value: {{ .cloudDomain }}
- name: SEALOS_PORT
value: "{{ if .cloudPort }}:{{ .cloudPort }}{{ end }}"
- name: MONITOR_URL
value: {{ .monitorUrl }}
securityContext:
runAsNonRoot: true
runAsUser: 1001
Expand Down
Expand Up @@ -69,7 +69,7 @@ const AppDetail = ({
flex={'0 0 400px'}
mr={4}
overflowY={'auto'}
zIndex={1}
zIndex={9}
transition={'0.4s'}
bg={'white'}
border={theme.borders.sm}
Expand Down
2 changes: 0 additions & 2 deletions frontend/providers/template/deploy/manifests/deploy.yaml.tmpl
Expand Up @@ -58,8 +58,6 @@ spec:
value: {{ .certSecretName }}
- name: TEMPLATE_REPO_URL
value: {{ .templateRepoUrl }}
- name: TEMPLATE_REPO_PATH
value: {{ .templateRepoPath }}
image: ghcr.io/labring/sealos-template-frontend:latest
imagePullPolicy: Always
volumeMounts:
Expand Down
18 changes: 7 additions & 11 deletions frontend/providers/template/src/pages/deploy/index.tsx
Expand Up @@ -8,11 +8,10 @@ import { GET } from '@/services/request';
import { useCachedStore } from '@/store/cached';
import { useGlobalStore } from '@/store/global';
import type { QueryType, YamlItemType } from '@/types';
import { TemplateSource, TemplateType, YamlType } from '@/types/app';
import { TemplateSource, TemplateType } from '@/types/app';
import { serviceSideProps } from '@/utils/i18n';
import { generateYamlList, parseTemplateString } from '@/utils/json-yaml';
import { processEnvValue } from '@/utils/tools';
import { getUserKubeConfig } from '@/utils/user';
import { Box, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Flex } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query';
import JSYAML from 'js-yaml';
Expand Down Expand Up @@ -108,9 +107,9 @@ const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) =>
}, 200);

const getCachedValue = () => {
if (!cached) return {};
if (!cached) return null;
const cachedValue = JSON.parse(cached);
return cachedValue?.cachedKey === templateName ? cachedValue : {};
return cachedValue?.cachedKey === templateName ? cachedValue : null;
};

// form
Expand Down Expand Up @@ -209,26 +208,23 @@ const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) =>
try {
const yamlString = res.yamlList?.map((item) => JSYAML.dump(item)).join('---\n');
const output = mapValues(res?.source.defaults, (value) => value.value);

const generateStr = parseTemplateString(yamlString, /\$\{\{\s*(.*?)\s*\}\}/g, {
...res?.source,
defaults: output,
inputs: getFormDefaultValues(res)
inputs: getCachedValue() ? JSON.parse(cached) : getFormDefaultValues(res)
});

setCorrectYaml(generateStr);
setYamlList(generateYamlList(generateStr, detailName));
} catch (err) {
console.log(err, 'getTemplateData');
}
};

useEffect(() => {
const cached = getCachedValue();
formOnchangeDebounce(cached);
}, [templateSource]);

useEffect(() => {
setInsideCloud(!(window.top === window));
// get template data

(async () => {
try {
await getTemplateData();
Expand Down

0 comments on commit 3be0e8f

Please sign in to comment.