Skip to content

Commit

Permalink
chore: 前后端一体化部署
Browse files Browse the repository at this point in the history
前后端代码共用一套镜像文件, 并配置docker-compose 一键部署命令
  • Loading branch information
moonrailgun committed Sep 3, 2022
1 parent 2e179c4 commit 23e690c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Nightly版 体验地址: [https://nightly.paw.msgbyte.com/](https://nightly.paw.
- 可以严谨,也可以乐趣。通过插件的组合可以创造用于不同场景的 Tailchat。可以是面向娱乐,也可以是面向企业
- 后端微服务架构,已经为大规模部署做好了准备。不用担心用户量大了以后怎么办


<!--
## Build
#### 编译 web 前端代码
Expand All @@ -48,4 +48,4 @@ SERVICE_URL=http://127.0.0.1:11000 pnpm build
cd app
pnpm install
pnpm start
```
``` -->
7 changes: 2 additions & 5 deletions client/shared/manager/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { buildRegFnWithEvent } from './buildReg';

/**
* 获取服务器地址相关逻辑
* @default http://127.0.0.1:11000
* @default "/" (前后端一体)
*/
export const [getServiceUrl, setServiceUrl, onServiceUrlChange] =
buildRegFnWithEvent<() => string>(
'serverUrl',
() => 'http://127.0.0.1:11000'
);
buildRegFnWithEvent<() => string>('serverUrl', () => '/');
2 changes: 1 addition & 1 deletion client/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "cross-env NODE_ENV=production rimraf ./dist && pnpm plugins:all && pnpm build:webpack",
"build:webpack": "cross-env TS_NODE_PROJECT='tsconfig.node.json' webpack --config ./build/webpack.config.ts",
"build:stats": "pnpm build:webpack --profile --json=compilation-stats.json",
"dev": "cross-env TS_NODE_PROJECT='tsconfig.node.json' NODE_ENV=development webpack serve --config ./build/webpack.config.ts",
"dev": "cross-env TS_NODE_PROJECT='tsconfig.node.json' NODE_ENV=development SERVICE_URL=http://127.0.0.1:11000 webpack serve --config ./build/webpack.config.ts",
"serve": "npx http-server ./dist",
"test": "jest",
"analysis": "cross-env ANALYSIS=true pnpm build:webpack",
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
version: "3.3"

services:
# 应用网关
web:
build:
context: .
image: tailchat
restart: unless-stopped
env_file: docker-compose.env
labels:
- "traefik.enable=true"
- "traefik.http.routers.web.rule=Method(`GET`) || (Path(`/`) || PathPrefix(`/main`) || PathPrefix(`/entry`))"
- "traefik.http.services.web.loadbalancer.server.port=11011"
command: npx http-server-spa ./client/web/dist index.html 11011
networks:
- internal

# 应用网关
service-gateway:
build:
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
"dev:web": "cd client/web && pnpm run dev",
"dev:server": "cd server && pnpm run dev",
"start:service": "cd server && pnpm run start:service",
"build": "concurrently npm:build:web npm:build:server",
"build": "concurrently npm:build:web npm:build:server && cp -r client/web/dist/* server/dist/public",
"build:web": "cd client/web && pnpm run build",
"build:server": "cd server && pnpm run build && echo \"Install server side plugin:\" && pnpm run plugin:install com.msgbyte.tasks com.msgbyte.linkmeta com.msgbyte.github com.msgbyte.simplenotify && mkdir -p ./dist/public && cp -r ./public/plugins ./dist/public && cp ./public/registry.json ./dist/public",
"postbuild": "cp -r client/web/dist/* server/dist/public",
"check:type": "concurrently npm:check:type:client npm:check:type:server",
"check:type:client": "cd client/web && tsc --noEmit",
"check:type:server": "cd server && tsc --noEmit",
Expand Down

0 comments on commit 23e690c

Please sign in to comment.