diff --git a/.github/workflows/nancal.yml b/.github/workflows/nancal.yml new file mode 100644 index 000000000..690e641cc --- /dev/null +++ b/.github/workflows/nancal.yml @@ -0,0 +1,47 @@ +name: nancal site deploy + +on: + workflow_dispatch + # pull_request: + # branches: [ "main" ] + # push: + # branches: [ "main" ] + +jobs: + build-and-deploy: + runs-on: nancal + defaults: + run: + working-directory: /home/nancal/rd/project/deeptest + steps: + - name: checkout backend codes + run: git pull + + - name: checkout frontend codes + run: git pull + working-directory: /home/nancal/rd/project/deeptest-ui + + - name: make server + run: ENV=dp make compile_server_linux + + - name: make agent + run: ENV=dp make compile_agent_linux + + - name: make ui + run: make compile_ui_nancal + + - name: copy files + run: | + mkdir -p /home/nancal/rd/server + cp -f bin/linux/deeptest-server /home/nancal/rd/server/ + cp -f client/bin/linux/deeptest-agent /home/nancal/rd/server/ + + rm -rf /home/nancal/rd/server/deeptest-ui + cp -fr client/ui /home/nancal/rd/server/deeptest-ui + + - name: start service + run: | + ps -ef | grep 'deeptest-' | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 + cd /home/nancal/rd/server + RUNNER_TRACKING_ID="" && nohup ./deeptest-server > server.log 2>&1 & + RUNNER_TRACKING_ID="" && nohup ./deeptest-agent > agent.log 2>&1 & diff --git a/.gitignore b/.gitignore index 1676b29ea..a02d54324 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ client/icon/ly client/src/app/package-ly.json +client/node_modules client-ly/node_modules client-ly/out client-ly/.webpack diff --git a/Makefile b/Makefile index 74d235d91..938e09a51 100644 --- a/Makefile +++ b/Makefile @@ -48,25 +48,26 @@ GIT_HASH=`git show -s --format=%H` BUILD_CMD_UNIX=go build -ldflags "-X 'main.AppVersion=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GoVersion=${GO_VERSION}' -X 'main.GitHash=${GIT_HASH}'" BUILD_CMD_WIN=go build -ldflags "-s -w -X 'main.AppVersion=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GoVersion=${GO_VERSION}' -X 'main.GitHash=${GIT_HASH}'" -default: compile_ui_web win64 win32 linux mac +web: compile_ui_web win64-web win32-web linux-web mac-web -# 非客户端版本打包 -win64: prepare compile_agent_win64 compile_server_win64 zip_web_win64 -win32: prepare compile_agent_win32 compile_server_win32 zip_web_win32 -linux: prepare compile_agent_linux compile_server_linux zip_web_linux -mac: prepare compile_agent_mac compile_server_mac zip_web_mac +# 非客户端版本打包,需先运行 make compile_ui_web +win64-web: prepare compile_agent_win64 compile_server_win64 zip_win64_web +win32-web: prepare compile_agent_win32 compile_server_win32 zip_win32_web +linux-web: prepare compile_agent_linux compile_server_linux zip_linux_web +mac-web: prepare compile_agent_mac compile_server_mac zip_mac_web -# 客户端版本打包 -dp-win64: prepare build_gui_win64 compile_launcher_win64 compile_server_win64 copy_files_win64 zip_win64 zip_win64_upgrade -dp-win32: prepare build_gui_win32 compile_launcher_win32 compile_server_win32 copy_files_win32 zip_win32 zip_win32_upgrade -dp-linux: prepare build_gui_linux compile_server_linux copy_files_linux zip_linux zip_linux_upgrade -dp-mac: prepare build_gui_mac compile_server_mac copy_files_mac zip_mac zip_mac_upgrade +# 客户端版本打包,需先运行 make compile_ui_ +dp-win64-client: prepare build_gui_win64 compile_launcher_win64 compile_server_win64 copy_files_win64 zip_win64_client zip_win64_upgrade +dp-win32-client: prepare build_gui_win32 compile_launcher_win32 compile_server_win32 copy_files_win32 zip_win32_client zip_win32_upgrade +dp-linux-client: prepare build_gui_linux compile_server_linux copy_files_linux zip_linux_client zip_linux_upgrade +dp-mac-client: prepare build_gui_mac compile_server_mac copy_files_mac zip_mac_client zip_mac_upgrade +dp-mac-test-client: compile_ui_client_test build_gui_mac # 乐研 打包 -ly-win64: prepare compile_ly_ui_client build_gui_win64 compile_ly_launcher_win64 compile_server_win64 copy_files_win64 zip_win64 zip_win64_upgrade -ly-win32: prepare compile_ly_ui_client build_gui_win32 compile_ly_launcher_win32 compile_server_win32 copy_files_win32 zip_win32 zip_win32_upgrade -ly-linux: prepare compile_ly_ui_client build_gui_linux compile_server_linux copy_files_linux zip_linux zip_linux_upgrade -ly-mac: prepare compile_ly_ui_client build_gui_mac compile_server_mac copy_files_mac zip_mac zip_mac_upgrade +ly-win64-client: prepare compile_ly_ui_client build_gui_win64 compile_ly_launcher_win64 compile_server_win64 copy_files_win64 zip_win64_client zip_win64_upgrade +ly-win32-client: prepare compile_ly_ui_client build_gui_win32 compile_ly_launcher_win32 compile_server_win32 copy_files_win32 zip_win32_client zip_win32_upgrade +ly-linux-client: prepare compile_ly_ui_client build_gui_linux compile_server_linux copy_files_linux zip_linux_client zip_linux_upgrade +ly-mac-client: prepare compile_ly_ui_client build_gui_mac compile_server_mac copy_files_mac zip_mac_client zip_mac_upgrade prepare: init_client_project update_version @@ -83,15 +84,20 @@ gen_version_file: compile_ui: @cd ui && yarn build --dest ../client/ui && cd .. -compile_ui_web: - @cd ../leyanapi-frontend && yarn build:web --dest ../leyanapi-backend/client/ui && cd ../leyanapi-backend -compile_ui_demo: +compile_ui_demo: # DeepTest测试 @cd ../deeptest-ui && yarn build:demo --dest ../deeptest/client/ui && cd ../deeptest +compile_ui_nancal: # 内网测试 + @cd ../deeptest-ui && yarn build:nancal --dest ../deeptest/client/ui && cd ../deeptest compile_ui_client: - @cd ui && yarn build --dest ../client/ui && cd .. + @rm -rf client/ui && cd ../leyanapi-frontend && yarn build:client --dest ../leyanapi-backend/client/ui && cd .. +compile_ui_client_test: + @rm -rf client/ui && cd ../leyanapi-frontend && yarn build:clientTest --dest ../leyanapi-backend/client/ui && cd .. compile_ly_ui_client: @cd ../leyanapi-frontend && yarn build:client && cd ../leyanapi-backend +compile_ui_web: + @cd ../leyanapi-frontend && yarn build:web --dest ../leyanapi-backend/bin/deeptest-ui && cd ../leyanapi-backend + # launcher compile_launcher_win64: @echo 'start compile win64 launcher' @@ -241,15 +247,15 @@ copy_files_mac: @echo 'start copy files darwin' # zip web files -zip_web_win64: +zip_win64_web: @echo 'start zip win64' @find . -name .DS_Store -print0 | xargs -0 rm -f @mkdir -p ${QINIU_DIST_DIR}win64 && rm -rf ${QINIU_DIST_DIR}win64/${PROJECT}-web.zip @cp -rf config ${BIN_DIR}win64/ @cp -rf ${CLIENT_BIN_DIR}win32/deeptest-agent.exe ${BIN_DIR}win64/ - @rm -rf ${BIN_DIR}win64/deeptest-ui && mkdir ${BIN_DIR}win64/deeptest-ui - @cp -rf client/ui/* ${BIN_DIR}win64/deeptest-ui + @rm -rf ${BIN_DIR}win64/deeptest-ui + @cp -rf bin/deeptest-ui ${BIN_DIR}win64 @cd ${BIN_DIR}win64/ && \ zip -ry ${QINIU_DIST_DIR}win64/${PROJECT}-web.zip ./* && \ @@ -257,15 +263,15 @@ zip_web_win64: xargs echo > ${QINIU_DIST_DIR}win64/${PROJECT}-web.zip.md5 && \ cd ../..; \ -zip_web_win32: +zip_win32_web: @echo 'start zip win32' @find . -name .DS_Store -print0 | xargs -0 rm -f @mkdir -p ${QINIU_DIST_DIR}win32 && rm -rf ${QINIU_DIST_DIR}win32/${PROJECT}-web.zip @cp -rf config ${BIN_DIR}win32/ @cp -rf ${CLIENT_BIN_DIR}win32/deeptest-agent.exe ${BIN_DIR}win32/ - @rm -rf ${BIN_DIR}win32/deeptest-ui && mkdir ${BIN_DIR}win32/deeptest-ui - @cp -rf client/ui/* ${BIN_DIR}win32/deeptest-ui + @rm -rf ${BIN_DIR}win32/deeptest-ui + @cp -rf bin/deeptest-ui ${BIN_DIR}win32 @cd ${BIN_DIR}win32/ && \ zip -ry ${QINIU_DIST_DIR}win32/${PROJECT}-web.zip ./* && \ @@ -273,15 +279,15 @@ zip_web_win32: xargs echo > ${QINIU_DIST_DIR}win32/${PROJECT}-web.zip.md5 && \ cd ../..; \ -zip_web_linux: +zip_linux_web: @echo 'start zip linux' @find . -name .DS_Store -print0 | xargs -0 rm -f @mkdir -p ${QINIU_DIST_DIR}linux && rm -rf ${QINIU_DIST_DIR}linux/${PROJECT}-web.zip @cp -rf config ${BIN_DIR}linux/ @cp -rf ${CLIENT_BIN_DIR}linux/deeptest-agent ${BIN_DIR}linux/ - @rm -rf ${BIN_DIR}linux/deeptest-ui && mkdir ${BIN_DIR}linux/deeptest-ui - @cp -rf client/ui/* ${BIN_DIR}linux/deeptest-ui + @rm -rf ${BIN_DIR}linux/deeptest-ui + @cp -rf bin/deeptest-ui ${BIN_DIR}linux @cd ${BIN_DIR}linux/ && \ zip -ry ${QINIU_DIST_DIR}linux/${PROJECT}-web.zip ./* && \ @@ -289,61 +295,61 @@ zip_web_linux: xargs echo > ${QINIU_DIST_DIR}linux/${PROJECT}-web.zip.md5 && \ cd ../..; \ -zip_web_mac: +zip_mac_web: @echo 'start zip darwin' @find . -name .DS_Store -print0 | xargs -0 rm -f @mkdir -p ${QINIU_DIST_DIR}darwin && rm -rf ${QINIU_DIST_DIR}darwin/${PROJECT}-web.zip @cp -rf config ${BIN_DIR}darwin/ @cp -rf ${CLIENT_BIN_DIR}darwin/deeptest-agent ${BIN_DIR}darwin/ - @rm -rf ${BIN_DIR}darwin/deeptest-ui && mkdir ${BIN_DIR}darwin/deeptest-ui - @cp -rf client/ui/* ${BIN_DIR}darwin/deeptest-ui + @rm -rf ${BIN_DIR}darwin/deeptest-ui + @cp -rf bin/deeptest-ui ${BIN_DIR}darwin @cd ${BIN_DIR}darwin/ && \ - zip -ry ${QINIU_DIST_DIR}darwin/${PROJECT}-web.zip ./* && \ + zip -ry ${QINIU_DIST_DIR}darwin/${PROJECT}-web.zip ./* -x Leyan* && \ md5sum ${QINIU_DIST_DIR}darwin/${PROJECT}-web.zip | awk '{print $$1}' | \ xargs echo > ${QINIU_DIST_DIR}darwin/${PROJECT}-web.zip.md5 && \ cd ../..; \ # zip client files -zip_win64: +zip_win64_client: @echo 'start zip win64' @find . -name .DS_Store -print0 | xargs -0 rm -f - @mkdir -p ${QINIU_DIST_DIR}win64 && rm -rf ${QINIU_DIST_DIR}win64/${PROJECT}.zip + @mkdir -p ${QINIU_DIST_DIR}win64 && rm -rf ${QINIU_DIST_DIR}win64/${PROJECT}-client.zip @cd ${CLIENT_OUT_DIR_EXECUTABLE}win64 && \ - zip -ry ${QINIU_DIST_DIR}win64/${PROJECT}.zip ./* && \ - md5sum ${QINIU_DIST_DIR}win64/${PROJECT}.zip | awk '{print $$1}' | \ - xargs echo > ${QINIU_DIST_DIR}win64/${PROJECT}.zip.md5 && \ + zip -ry ${QINIU_DIST_DIR}win64/${PROJECT}-client.zip ./* -x Leyan* && \ + md5sum ${QINIU_DIST_DIR}win64/${PROJECT}-client.zip | awk '{print $$1}' | \ + xargs echo > ${QINIU_DIST_DIR}win64/${PROJECT}-client.zip.md5 && \ cd ../../..; \ -zip_win32: +zip_win32_client: @echo 'start zip win32' @find . -name .DS_Store -print0 | xargs -0 rm -f - @mkdir -p ${QINIU_DIST_DIR}win32 && rm -rf ${QINIU_DIST_DIR}win32/${PROJECT}.zip + @mkdir -p ${QINIU_DIST_DIR}win32 && rm -rf ${QINIU_DIST_DIR}win32/${PROJECT}-client.zip @cd ${CLIENT_OUT_DIR_EXECUTABLE}win32 && \ - zip -ry ${QINIU_DIST_DIR}win32/${PROJECT}.zip ./* && \ - md5sum ${QINIU_DIST_DIR}win32/${PROJECT}.zip | awk '{print $$1}' | \ - xargs echo > ${QINIU_DIST_DIR}win32/${PROJECT}.zip.md5 && \ + zip -ry ${QINIU_DIST_DIR}win32/${PROJECT}-client.zip ./* -x Leyan* && \ + md5sum ${QINIU_DIST_DIR}win32/${PROJECT}-client.zip | awk '{print $$1}' | \ + xargs echo > ${QINIU_DIST_DIR}win32/${PROJECT}-client.zip.md5 && \ cd ../../..; \ -zip_linux: +zip_linux_client: @echo 'start zip linux' @find . -name .DS_Store -print0 | xargs -0 rm -f - @mkdir -p ${QINIU_DIST_DIR}linux && rm -rf ${QINIU_DIST_DIR}linux/${PROJECT}.zip + @mkdir -p ${QINIU_DIST_DIR}linux && rm -rf ${QINIU_DIST_DIR}linux/${PROJECT}-client.zip @cd ${CLIENT_OUT_DIR_EXECUTABLE}linux && \ - zip -ry ${QINIU_DIST_DIR}linux/${PROJECT}.zip ./* && \ - md5sum ${QINIU_DIST_DIR}linux/${PROJECT}.zip | awk '{print $$1}' | \ - xargs echo > ${QINIU_DIST_DIR}linux/${PROJECT}.zip.md5 && \ + zip -ry ${QINIU_DIST_DIR}linux/${PROJECT}-client.zip ./* -x Leyan* && \ + md5sum ${QINIU_DIST_DIR}linux/${PROJECT}-client.zip | awk '{print $$1}' | \ + xargs echo > ${QINIU_DIST_DIR}linux/${PROJECT}-client.zip.md5 && \ cd ../../..; \ -zip_mac: +zip_mac_client: @echo 'start zip darwin' @find . -name .DS_Store -print0 | xargs -0 rm -f - @mkdir -p ${QINIU_DIST_DIR}darwin && rm -rf ${QINIU_DIST_DIR}darwin/${PROJECT}.zip + @mkdir -p ${QINIU_DIST_DIR}darwin && rm -rf ${QINIU_DIST_DIR}darwin/${PROJECT}-client.zip @cd ${CLIENT_OUT_DIR_EXECUTABLE}darwin && \ - zip -ry ${QINIU_DIST_DIR}darwin/${PROJECT}.zip ./* && \ - md5sum ${QINIU_DIST_DIR}darwin/${PROJECT}.zip | awk '{print $$1}' | \ - xargs echo > ${QINIU_DIST_DIR}darwin/${PROJECT}.zip.md5 && \ + zip -ry ${QINIU_DIST_DIR}darwin/${PROJECT}-client.zip ./* -x Leyan* && \ + md5sum ${QINIU_DIST_DIR}darwin/${PROJECT}-client.zip | awk '{print $$1}' | \ + xargs echo > ${QINIU_DIST_DIR}darwin/${PROJECT}-client.zip.md5 && \ cd ../../..; \ # zip upgrade package @@ -385,6 +391,17 @@ upload_to: @qshell qupload2 --src-dir=${QINIU_DIR} --bucket=download --thread-count=10 --log-file=qshell.log \ --skip-path-prefixes=ztf,zd,zv,zmanager,driver --rescan-local --overwrite --check-hash +zip_server: + @cp bin/win64/${PROJECT}-server.exe ${QINIU_DIST_DIR}win64/ + + @cp bin/win32/${PROJECT}-server.exe ${QINIU_DIST_DIR}win32/ + @cp bin/linux/${PROJECT}-server ${QINIU_DIST_DIR}linux/ + + # zip -r /Users/aaron/work/qiniu/deeptest/3.0/darwin/deeptest-server.zip config bin/deeptest-ui bin/darwin/deeptest-server + @zip -ry ${QINIU_DIST_DIR}darwin/${PROJECT}-server.zip \ + bin/darwin/${PROJECT}-server config client/ui && \ + md5sum ${QINIU_DIST_DIR}darwin/${PROJECT}-upgrade.zip | awk '{print $$1}' | \ + xargs echo > ${QINIU_DIST_DIR}darwin/${PROJECT}-upgrade.zip.md5 && \ DEMO_BIN=/home/lighthouse/rd/server/deeptest diff --git a/backend-config b/backend-config index e39b7c200..1ea412af6 160000 --- a/backend-config +++ b/backend-config @@ -1 +1 @@ -Subproject commit e39b7c20019b120e8ab36a1eb99d9f6a45c4b0e3 +Subproject commit 1ea412af61fb3364803bd56c6a381b818cba305a diff --git a/client/forge.config.js b/client/forge.config.js index 2760123ba..5d413b28d 100644 --- a/client/forge.config.js +++ b/client/forge.config.js @@ -17,7 +17,9 @@ module.exports = { { name: '@electron-forge/maker-squirrel', config: { - name: pkg?.name || 'deeptest' + name: pkg?.name || 'deeptest', + authors: 'AaronChen', + description: 'DeepTest Electron Client' } }, { diff --git a/client/package.json b/client/package.json index 33956e0f2..f49dec263 100644 --- a/client/package.json +++ b/client/package.json @@ -17,27 +17,26 @@ "lint": "echo \"No linting configured\"" }, "keywords": [], - "author": { - "name": "Aaron Chen", - "email": "chenqi@easycorp.ltd" - }, + "author": "Aaron Chen", "license": "GPL3", "config": { "forge": "./forge.config.js" }, "devDependencies": { - "@electron-forge/cli": "^6.4.1", - "@electron-forge/maker-deb": "^6.4.1", - "@electron-forge/maker-rpm": "^6.4.1", - "@electron-forge/maker-squirrel": "^6.4.1", - "@electron-forge/maker-zip": "^6.4.1", - "@electron-forge/plugin-auto-unpack-natives": "^6.4.1", - "@electron-forge/plugin-webpack": "^6.4.1", + "electron": "30.0.9", + "electron-packager": "17.1.2", + + "@electron-forge/cli": "7.4.0", + "@electron-forge/maker-deb": "7.4.0", + "@electron-forge/maker-rpm": "7.4.0", + "@electron-forge/maker-squirrel": "7.4.0", + "@electron-forge/maker-zip": "7.4.0", + "@electron-forge/plugin-auto-unpack-natives": "7.4.0", + "@electron-forge/plugin-webpack": "7.4.0", + "@timfish/forge-externals-plugin": "^0.2.0", "@vercel/webpack-asset-relocator-loader": "1.7.3", "css-loader": "^6.5.1", - "electron": "26.1.0", - "electron-packager": "15.4.0", "node-loader": "^2.0.0", "style-loader": "^3.3.1" }, diff --git a/client/src/app/app.js b/client/src/app/app.js index 09201fb32..c45aa201b 100644 --- a/client/src/app/app.js +++ b/client/src/app/app.js @@ -46,14 +46,18 @@ export class DeepTestApp { app.commandLine.appendSwitch('disable-site-isolation-trials') app.commandLine.appendSwitch('disable-features','BlockInsecurePrivateNetworkRequests') this._windows = new Map(); + // 需要启动本地 Agent 服务,之后再会启动 UI 服务 (async () => { port = await getUsefulPort(portAgent,56999); + + logInfo(`>> starting deeptest agent on port ${port}`); + startAgent(port).then((agentUrl)=> { - if (agentUrl) logInfo(`>> deeptest server started successfully on : ${agentUrl}`); + if (agentUrl) logInfo(`>> deeptest agent started successfully at ${agentUrl}`); this.bindElectronEvents(); }).catch((err) => { - logErr('>> agent started failed, err: ' + err); + logErr('>> deeptest agent started failed on port ${port}, err: ' + err); process.exit(1); }) })() @@ -95,13 +99,16 @@ export class DeepTestApp { mainWin.show() this._windows.set('main', mainWin); + // 最终都是返回 http地址,远端 或者 本地http服务 const uiPort = process.env.UI_SERVER_PORT || await getUsefulPort(portClient,55999); const url = await startUIService(uiPort); await mainWin.loadURL(url); // 通知渲染进程,agent服务端口 - mainWin.webContents.send(electronMsgUsePort, {uiPort,agentPort:port}); + const data = {uiPort, agentPort: port} + logInfo(`send event to webpage, uiPort=${data.uiPort}, agentPort=${data.agentPort}`) + mainWin.webContents.send(electronMsgUsePort, data); // 读取服务配置 const confPath = path.join(os.homedir(), App, 'conf.yaml'); @@ -196,6 +203,7 @@ export class DeepTestApp { // this.buildAppMenu(); this.openOrCreateWindow() this.setAboutPanel(); + // 使用默认的快捷键,和常用的快捷键有冲突 // globalShortcut.register('CommandOrControl+D', () => { // const mainWin = this._windows.get('main'); @@ -234,6 +242,7 @@ export class DeepTestApp { // createWindow(); // } }); + // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. diff --git a/client/src/app/core/ui.js b/client/src/app/core/ui.js index 7eb369ee4..e13176f1b 100644 --- a/client/src/app/core/ui.js +++ b/client/src/app/core/ui.js @@ -27,43 +27,45 @@ export function startUIService(portClient) { } // 从环境变量中获取 ui 服务地址 - let {UI_SERVER_URL: uiServerUrl} = process.env; + let {UI_SERVER_URL: uiServerUrlOrPath} = process.env; - if (!uiServerUrl && !DEBUG) { - uiServerUrl = path.resolve(process.resourcesPath, 'ui'); + if (!uiServerUrlOrPath && !DEBUG) { + uiServerUrlOrPath = path.resolve(process.resourcesPath, 'ui'); } - // uiServerUrl = path.resolve(process.resourcesPath, 'ui'); - uiServerUrl = uiServerUrl || path.resolve(process.resourcesPath, 'ui'); + // uiServerUrlOrPath = path.resolve(process.resourcesPath, 'ui'); + uiServerUrlOrPath = uiServerUrlOrPath || path.resolve(process.resourcesPath, 'ui'); - if (uiServerUrl) { + if (uiServerUrlOrPath) { // 有效的 http 地址 - if (/^https?:\/\//.test(uiServerUrl)) { - return Promise.resolve(uiServerUrl); + if (/^https?:\/\//.test(uiServerUrlOrPath)) { + return Promise.resolve(uiServerUrlOrPath); } // 返回本地的静态资源路径,启动 express 服务 return new Promise((resolve, reject) => { - if (!path.isAbsolute(uiServerUrl)) { - uiServerUrl = path.resolve(app.getAppPath(), uiServerUrl); + if (!path.isAbsolute(uiServerUrlOrPath)) { + uiServerUrlOrPath = path.resolve(app.getAppPath(), uiServerUrlOrPath); } const port = portClient; - logInfo(`>> starting ui serer at ${uiServerUrl} with port ${port}`); + logInfo(`>> starting deeptest webui from dir ${uiServerUrlOrPath} with port ${port}`); const uiServer = express(); uiServer.use(history()); - uiServer.use(express.static(uiServerUrl)); + uiServer.use(express.static(uiServerUrlOrPath)); + const server = uiServer.listen(port, serverError => { if (serverError) { - console.error('>>> start ui server failed with error', serverError); + console.error('>>> start deeptest webui failed with error', serverError); _uiService = null; reject(serverError); } else { - logInfo(`>> ui server started successfully on http://localhost:${port}.`); + logInfo(`>> deeptest webui started successfully on http://localhost:${port}.`); resolve(`http://localhost:${port}`); } }); + // express 服务关闭时,清空 _uiService server.on('close', () => { _uiService = null; diff --git a/client/src/app/utils/checkPort.js b/client/src/app/utils/checkPort.js index c9524222a..a46c793a4 100644 --- a/client/src/app/utils/checkPort.js +++ b/client/src/app/utils/checkPort.js @@ -23,7 +23,7 @@ export const getUsefulPort = async function (port, maxPort) { port: port, // minimum port maxPort: maxPort, // maximum port }); - logInfo(`>> getUsefulPort port ${port} is used ${newPort} : ${newPort !== port}`); + logInfo(`>> getUsefulPort: port = ${port}, newPort = ${newPort}`); return newPort; } diff --git a/go.mod b/go.mod index 31f3f20ec..04857d537 100644 --- a/go.mod +++ b/go.mod @@ -181,6 +181,7 @@ require ( github.com/pelletier/go-toml v1.9.3 // indirect github.com/pierrec/lz4/v4 v4.0.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/r3labs/sse/v2 v2.10.0 // indirect github.com/richardlehane/mscfb v1.0.4 // indirect github.com/richardlehane/msoleps v1.0.3 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect @@ -221,6 +222,7 @@ require ( google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect + gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect moul.io/http2curl v1.0.1-0.20190925090545-5cd742060b0e // indirect diff --git a/go.sum b/go.sum index 8d74f2e4e..8bc00bd03 100644 --- a/go.sum +++ b/go.sum @@ -740,6 +740,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0= +github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I= github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM= github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk= github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= @@ -1047,6 +1049,7 @@ golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -1425,6 +1428,8 @@ gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gG gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk= gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d h1:TxyelI5cVkbREznMhfzycHdkp5cLA7DpE+GKjSslYhM= gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw= +gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y= +gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/pkg/config/init.go b/internal/pkg/config/init.go index 3c682da16..b1bc72b59 100644 --- a/internal/pkg/config/init.go +++ b/internal/pkg/config/init.go @@ -13,6 +13,7 @@ import ( "github.com/go-redis/redis/v8" "github.com/snowlyg/helper/dir" "github.com/spf13/viper" + "log" "os" "path" "path/filepath" @@ -78,7 +79,7 @@ func Init() { // server config serverConfigPath := filepath.Join(consts.WorkDir, consts.ServerConfigFileName) if !dir.IsExist(serverConfigPath) { // create config if not exist - configRes := filepath.Join("res", consts.ServerConfigFileName) + configRes := path.Join("res", consts.ServerConfigFileName) yamlDefault, _ := deeptest.ReadResData(configRes) if err := VIPER.ReadConfig(bytes.NewBuffer(yamlDefault)); err != nil { @@ -114,10 +115,12 @@ func Init() { // create casbin rbac_model.conf if needed casbinPath := filepath.Join(consts.WorkDir, consts.CasbinFileName) if !dir.IsExist(casbinPath) { - casbinRes := filepath.Join("res", consts.CasbinFileName) + casbinRes := path.Join("res", consts.CasbinFileName) yamlDefault, err := deeptest.ReadResData(casbinRes) if err != nil { - panic(fmt.Errorf("failed to read casbin rbac_model.conf from res: %s", err.Error())) + panic(fmt.Errorf("failed to read casbin rbac_model.conf from res: %s\n", err.Error())) + } else { + log.Printf("success to read casbin rbac_model.conf from res path %s\n", casbinRes) } err = _fileUtils.WriteFile(casbinPath, string(yamlDefault)) diff --git a/internal/pkg/config/model.go b/internal/pkg/config/model.go index b0cfbb770..0ae4e2448 100644 --- a/internal/pkg/config/model.go +++ b/internal/pkg/config/model.go @@ -8,6 +8,7 @@ import ( type Config struct { MaxSize int64 `mapstructure:"max-size" json:"burst" yaml:"max-size"` System System `mapstructure:"system" json:"system" yaml:"system"` + Mail Mail `mapstructure:"mail" json:"mail" yaml:"mail"` Limit Limit `mapstructure:"limit" json:"limit" yaml:"limit"` Zap myZap.Zap `mapstructure:"zap" json:"zap" yaml:"zap"` Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"` @@ -17,12 +18,19 @@ type Config struct { ThirdParty ThirdParty `mapstructure:"third-party" json:"third-party" yaml:"third-party"` Mcs Mcs `mapstructure:"mcs" json:"mcs" yaml:"mcs"` Environment Environment `mapstructure:"environment" json:"environment" yaml:"environment"` - OpenApi OpenApi `mapstructure:"openapi" json:"openapi" yaml:"openapi"` Saas Saas `mapstructure:"saas" json:"saas" yaml:"saas"` + + OpenApi OpenApi `mapstructure:"openapi" json:"openapi" yaml:"openapi"` + ChatChatUrl string `mapstructure:"chatChatUrl" json:"chatChatUrl" yaml:"chatChatUrl"` + ChatChatControllerAddress string `mapstructure:"chatChatControllerAddress" json:"chatChatControllerAddress" yaml:"chatChatControllerAddress"` } type System struct { - Name string `mapstructure:"name" json:"name" yaml:"name"` + Name string `mapstructure:"name" json:"name" yaml:"name"` + + SupportMail string `mapstructure:"supportMail" json:"supportMail" yaml:"supportMail"` + Website string `mapstructure:"website" json:"website" yaml:"website"` + SysEnv string `mapstructure:"sysEnv" json:"sysEnv" yaml:"sysEnv"` // dev, leyan_test, deeptest_demo etc. Level string `mapstructure:"level" json:"level" yaml:"level"` // debug,release,test ServerAddress string `mapstructure:"serverAddress" json:"serverAddress" yaml:"serverAddress"` @@ -34,6 +42,13 @@ type System struct { TimeFormat string `mapstructure:"time-format" json:"timeFormat" yaml:"time-format"` } +type Mail struct { + SmtpAddress string `mapstructure:"smtpAddress" json:"smtpAddress" yaml:"smtpAddress"` + SmtpPort int `mapstructure:"smtpPort" json:"smtpPort" yaml:"smtpPort"` + Account string `mapstructure:"account" json:"account" yaml:"account"` + Password string `mapstructure:"password" json:"password" yaml:"password"` +} + type Limit struct { Disable bool `mapstructure:"disable" json:"disable" yaml:"disable"` Limit float64 `mapstructure:"limit" json:"limit" yaml:"limit"` diff --git a/internal/pkg/consts/consts.go b/internal/pkg/consts/consts.go index fd1054417..23ed45523 100644 --- a/internal/pkg/consts/consts.go +++ b/internal/pkg/consts/consts.go @@ -33,19 +33,11 @@ const ( ServerConfigFileName = "server.yaml" CasbinFileName = "rbac_model.conf" // casbin 规则文件名称 - SupportEmail = "chenqi@deeptest.com" - Sys = "DeepTest" - Url = "https://deeptest.com/" - UrlDev = "http://localhost:8000/" + WebsiteDev = "http://localhost:8000/" ExtractorErr = "extractor_err" ContentErr = "content_err" - EmailSmtpAddress = "smtp.exmail.qq.com" - EmailSmtpPort = 465 - EmailAccount = "chenqi@deeptest.com" - EmailPassword = "" - HttpRequestTimeout = 60 * time.Second DeepestKey = "com_deeptest_prop_for_selection" KEY_BASE_URL = "_base_url_" diff --git a/internal/server/modules/service/account.go b/internal/server/modules/service/account.go index 9efa74e48..6a16f1a88 100644 --- a/internal/server/modules/service/account.go +++ b/internal/server/modules/service/account.go @@ -16,6 +16,7 @@ import ( "go.uber.org/zap" "golang.org/x/crypto/bcrypt" "strconv" + "strings" "time" ) @@ -110,12 +111,15 @@ func (s *AccountService) Register(tenantId consts.TenantId, req v1.RegisterReq) s.UserRepo.Register(tenantId, &user) - //mp := map[string]string{ - // "name": user.Name, - // "sys": consts.Sys, - // "url": consts.Url, - //} - //_mailUtils.Send(user.Email, _i118Utils.Sprintf("register_success"), "register-success", mp) + if strings.ToLower(config.CONFIG.System.Name) == "deeptest" { + mp := map[string]string{ + "name": user.Name, + "sys": config.CONFIG.System.Name, + "url": config.CONFIG.System.Website, + "toEmail": user.Email, + } + _mailUtils.Send(user.Email, _i118Utils.Sprintf("register_success"), "register-success", mp) + } return } @@ -125,14 +129,15 @@ func (s *AccountService) ForgotPassword(tenantId consts.TenantId, usernameOrPass vcode, err := s.UserRepo.GenAndUpdateVcode(tenantId, user.ID) - url := consts.Url + url := config.CONFIG.System.Website if !consts.IsRelease { - url = consts.UrlDev + url = consts.WebsiteDev } settings := map[string]string{ - "name": user.Username, - "url": url, - "vcode": vcode, + "name": user.Username, + "url": url, + "vcode": vcode, + "toEmail": user.Email, } _mailUtils.Send(user.Email, _i118Utils.Sprintf("reset_password"), "reset-password", settings) diff --git a/internal/server/modules/service/user.go b/internal/server/modules/service/user.go index da1e6cf7c..f8cc3f5a9 100644 --- a/internal/server/modules/service/user.go +++ b/internal/server/modules/service/user.go @@ -2,6 +2,7 @@ package service import ( v1 "github.com/aaronchen2k/deeptest/cmd/server/v1/domain" + "github.com/aaronchen2k/deeptest/internal/pkg/config" "github.com/aaronchen2k/deeptest/internal/pkg/consts" "github.com/aaronchen2k/deeptest/internal/server/modules/model" "github.com/aaronchen2k/deeptest/internal/server/modules/repo" @@ -81,15 +82,15 @@ func (s *UserService) Invite(tenantId consts.TenantId, req v1.InviteUserReq) (us vcode, _ := s.UserRepo.GenAndUpdateVcode(tenantId, user.ID) - url := consts.Url + url := config.CONFIG.System.Website if !consts.IsRelease { - url = consts.UrlDev + url = consts.WebsiteDev } settings := map[string]string{ "name": user.Username, "url": url, "vcode": vcode, - "sys": consts.Sys, + "sys": config.CONFIG.System.Name, } _mailUtils.Send(user.Email, _i118Utils.Sprintf("invite_user"), "invite-user", settings) diff --git a/log/2024-01-23.log_lock b/log/2024-01-23.log_lock deleted file mode 100644 index e69de29bb..000000000 diff --git a/pkg/lib/mail/mail.go b/pkg/lib/mail/mail.go index de90f5f71..9f86cb0d8 100644 --- a/pkg/lib/mail/mail.go +++ b/pkg/lib/mail/mail.go @@ -5,7 +5,7 @@ import ( "bytes" "fmt" "github.com/aaronchen2k/deeptest" - "github.com/aaronchen2k/deeptest/internal/pkg/consts" + "github.com/aaronchen2k/deeptest/internal/pkg/config" "github.com/aaronchen2k/deeptest/pkg/lib/comm" "github.com/aaronchen2k/deeptest/pkg/lib/i118" "github.com/aaronchen2k/deeptest/pkg/lib/log" @@ -15,34 +15,29 @@ import ( "io" "os" "os/exec" - "path/filepath" + "path" "regexp" "strings" ) -// name -// inviter -// sys -// url -// vcode - func Send(to, subject, tmpl string, mp map[string]string) (err error) { d := gomail.NewDialer( - consts.EmailSmtpAddress, - consts.EmailSmtpPort, - consts.EmailAccount, - consts.EmailPassword) + config.CONFIG.Mail.SmtpAddress, + config.CONFIG.Mail.SmtpPort, + config.CONFIG.Mail.Account, + config.CONFIG.Mail.Password) + s, err := d.Dial() if err != nil { return } m := gomail.NewMessage() - m.SetHeader("From", consts.SupportEmail) + m.SetHeader("From", config.CONFIG.Mail.Account) m.SetAddressHeader("To", to, mp["name"]) m.SetHeader("Subject", subject) - tmplFile := filepath.Join("res", "tmpl", tmpl+".ftl") + tmplFile := path.Join("res", "tmpl", tmpl+".ftl") content, _ := deeptest.ReadResData(tmplFile) body := os.Expand(string(content), func(k string) string { return mp[k] }) diff --git a/res/agent.yaml b/res/agent.yaml index fc377c9ca..f58bf475e 100644 --- a/res/agent.yaml +++ b/res/agent.yaml @@ -1,6 +1,6 @@ limit: disable: true - limit: 10 + limit: 0 burst: 5 system: level: debug diff --git a/res/server.yaml b/res/server.yaml index a1258e3be..298fae969 100644 --- a/res/server.yaml +++ b/res/server.yaml @@ -1,3 +1,4 @@ + captcha: key-long: 6 img-width: 240 @@ -9,6 +10,13 @@ limit: disable: true limit: 0 burst: 5 + +mail: + smtpAddress: smtp.qq.com + smtpPort: 465 + account: + password: + max-size: 1024 maxsize: 1024 mcs: @@ -44,8 +52,12 @@ saas: appSecret: "" host: "" system: - name: "" + name: "DeepTest" sysEnv: "" + + supportMail: chenqi@deeptest.com + website: http://demo.deeptest.com/ + level: debug serverAddress: 0.0.0.0:8085 agentAddress: "" @@ -54,6 +66,7 @@ system: db-type: mysql cache-type: redis time-format: "2006-01-02 15:04:05" + thirdparty: username: "" password: "" @@ -73,3 +86,6 @@ zap: encode-level: "" stacktrace-key: stacktrace log-in-console: true + +chatChatUrl: http://127.0.0.1:7861/ +chatChatControllerAddress: http://127.0.0.1:20001/ diff --git a/res/tmpl/reset-password.ftl b/res/tmpl/reset-password.ftl index d2bc77f3a..4eba21aa3 100644 --- a/res/tmpl/reset-password.ftl +++ b/res/tmpl/reset-password.ftl @@ -15,7 +15,7 @@
- 请访问 ${url}#/user/resetPassword/${name}/${vcode}, 重置您的密码。 + 请访问 ${url}user/resetPassword/${name}/${vcode}, 重置您的密码。
\ No newline at end of file diff --git a/xdoc/notes.txt b/xdoc/notes.txt index 49a3da64a..4e0071eed 100644 --- a/xdoc/notes.txt +++ b/xdoc/notes.txt @@ -68,16 +68,6 @@ npm config set ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/ scp -r ~/work/qiniu/deeptest/* lighthouse@111.231.16.35:~/work/qiniu/deeptest nohup light-server -s ~/work/qiniu/deeptest > ~/light-server.log 2>&1 & -git push -f github master:main -git push -f github feature/chenqi99/var_in_params:feature/chenqi99/var_in_params - -ENV=dp rm -rf bin && make default - -ENV=dp make win64 -ENV=dp make win32 -ENV=dp make linux -ENV=dp make mac - 测试: 基本Websocket ws://111.231.16.35:9090/ws @@ -93,3 +83,22 @@ gRPC ${eval("'url is ' + escape('https://baidu.com')")} 加 ${x} ${_do_something('test ' + g_var1 + ' ' + escape('https://baidu.com'))} int2=='101' && function(x) {return x + 100} (6) == 106 + +# 版本库 +git push -f github dt:main +git push -f github feature/chenqi99/var_in_params:feature/chenqi99/var_in_params +git push -f github feature/chenqi99/openai:feature/chenqi99/openai + +git pull github feature/chenqi99/openai + +# 打包命令 +ENV=dp rm -rf bin && make default + +ENV=dp make compile_ui_client_test +ENV=dp make dp-win64 +ENV=dp make dp-win32 +ENV=dp make dp-linux +ENV=dp make dp-mac + +# 测试客户端 +ENV=dp make dp-mac-test \ No newline at end of file