Skip to content

Commit

Permalink
fix: fix docker-build.js bugs;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Jul 30, 2021
1 parent edf1a7a commit ca12167
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 96 deletions.
72 changes: 7 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,80 +53,22 @@
> 有以下两种方式: `基于 Docker Compose 快速部署``手动安装部署`
## 基于 Docker Compose 快速部署

```
git clone https://github.com/Maslow/less-framework.git
cd less-framework
docker-compose up
```

> 另,[less-admin](https://github.com/Maslow/less-admin) 是 less-framework 配套的后台管理,可管理访问规则、云函数等功能
## 手动安装部署

### 安装依赖

```sh
# 下载代码
git clone https://github.com/Maslow/less-framework.git
cd less-framework

# 安装依赖(建议使用 node 14+ 或 npm 7.5+,速度更快)
npm install

# 编译
npm run build
```

> 开发环境可自动编译
```sh
npm run watch
```

### 启动 MongoDb

```sh
docker run -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=less -e MONGO_INITDB_ROOT_PASSWORD=less --name mongo -d mongo
```

### 配置数据库 (MongoDb)

> A.【推荐】将 .env.development 拷贝并重命名为 .env,编辑里面的环境变量
```
cp .env.development .env
```

> B.【不推荐】或直接修改 `/src/config.ts` 相应配置
### 初始化应用的基础数据

> 初始化管理员、角色、权限、访问规则
```sh
npm run init
```

### 运行
# 因 mongo 启动较慢,所以先启动 mongo 服务
docker-compose up -d mongo

```sh
#运行
npm start
# 主动等待数秒后,启动所有服务
docker-compose up
```

> 也可使用 pm2 来运行应用
```sh
# 首次使用 pm2 运行前,需将创建配置文件 ecosystem.config.js
cp ecosystem.config.js.tpl ecosystem.config.js

pm2 run
```
> 另,[less-admin](https://github.com/Maslow/less-admin) 是 less-framework 配套的后台管理,可管理访问规则、云函数等功能

## TODO

- 添加运行截图到 README.md
- 完成自动打包 docker 镜像并发布脚本,实现 docker-compose 一键启动
- 使用 lerna fixed version
- 使用 lerna fixed version
- 将 less-admin 更名为 devops-admin 并加入到此项目中来
78 changes: 78 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
version: '3.8'
services:
mongo:
image: bitnami/mongodb:latest
environment:
- ALLOW_EMPTY_PASSWORD=yes
- MONGODB_REPLICA_SET_MODE=primary
- MONGODB_INITIAL_PRIMARY_HOST=mongo
- MONGODB_REPLICA_SET_NAME=rs0
volumes:
- db-data:/data/db
ports:
- "27018:27017"

devops_server:
image: lessx/laf-devops-server:latest
user: node
environment:
SYS_DB: laf-sys
SYS_DB_URI: mongodb://mongo:27017
SYS_DB_POOL_LIMIT: 10
SYS_SERVER_SECRET_SALT: Rewrite_Your_Own_Secret_Salt_abcdefg1234567
SYS_ADMIN: laf-sys
SYS_ADMIN_PASSWORD: laf-sys
LOG_LEVEL: debug
PORT: 9000
APP_DB: laf-app
APP_DB_URI: mongodb://mongo:27017
APP_DB_POOL_LIMIT: 100
APP_SERVER_SECRET_SALT: Rewrite_Your_Own_Secret_Salt_abcdefg1234567
volumes:
- ./packages/devops-server:/app
ports:
- "9000:9000"
read_only: true
depends_on:
- mongo
cap_drop:
- ALL
tmpfs:
- /tmp
restart: always

app_server:
image: lessx/laf-app-server:latest
user: node
environment:
DB: laf-app
DB_URI: mongodb://mongo:27017
DB_POOL_LIMIT: 100
SERVER_SECRET_SALT: Rewrite_Your_Own_Secret_Salt_abcdefg1234567
SUPER_ADMIN: laf-app
SUPER_ADMIN_PASSWORD: laf-app
LOG_LEVEL: debug
PORT: 8000
# command: npm run init-start
volumes:
- ./packages/app-server:/app
- app-data:/app/data
ports:
- "8000:8000"
read_only: true
depends_on:
- devops_server
- mongo
cap_drop:
- ALL
tmpfs:
- /tmp
restart: always

# networks:
# laf:

volumes:
app-data:
db-data:

64 changes: 38 additions & 26 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,67 @@
version: '3.8'
services:
server:
mongodb:
image: mongo:latest
user: mongodb
environment:
MONGO_INITDB_ROOT_USERNAME: laf
MONGO_INITDB_ROOT_PASSWORD: laf
volumes:
- db-data:/data/db
networks:
- laf

image: laf-devops-server:latest
mongo:
image: bitnami/mongodb:latest
environment:
- ALLOW_EMPTY_PASSWORD=yes
- MONGODB_REPLICA_SET_MODE=primary
- MONGODB_INITIAL_PRIMARY_HOST=mongo
- MONGODB_REPLICA_SET_NAME=rs0
volumes:
- db-data:/data/db
networks:
- laf

devops_server:
image: lessx/laf-devops-server:latest
user: node
environment:
SERVER_SALT: Rewrite_Your_Own_Secret_Salt_abcdefg1234567
DB: laf-sys-db
DB_URI: mongodb://laf:laf@mongodb:27017
DB_POOL_LIMIT: 10
SUPER_ADMIN: laf-sys
SUPER_ADMIN_PASSWORD: laf-sys
SYS_DB: laf-sys
SYS_DB_URI: mongodb://mongo:27017
SYS_DB_POOL_LIMIT: 10
SYS_SERVER_SECRET_SALT: Rewrite_Your_Own_Secret_Salt_abcdefg1234567
SYS_ADMIN: laf-sys
SYS_ADMIN_PASSWORD: laf-sys
LOG_LEVEL: debug
command: npm run init-start
PORT: 9000
APP_DB: laf-app
APP_DB_URI: mongodb://mongo:27017
APP_DB_POOL_LIMIT: 100
APP_SERVER_SECRET_SALT: Rewrite_Your_Own_Secret_Salt_abcdefg1234567
ports:
- "9000:9000"
read_only: true
depends_on:
- mongo
cap_drop:
- ALL
tmpfs:
- /tmp
restart: always
networks:
- laf

image: laf-app-server:latest

app_server:
image: lessx/laf-app-server:latest
user: node
environment:
SERVER_SALT: Rewrite_Your_Own_Secret_Salt_abcdefg1234567
DB: laf-app-db
DB_URI: mongodb://laf:laf@mongodb:27017
DB: laf-app
DB_URI: mongodb://mongo:27017
DB_POOL_LIMIT: 100
SERVER_SECRET_SALT: Rewrite_Your_Own_Secret_Salt_abcdefg1234567
SUPER_ADMIN: laf-app
SUPER_ADMIN_PASSWORD: laf-app
LOG_LEVEL: debug
PORT: 8000
command: npm run init-start
volumes:
- app-data:/app/data
ports:
- "8000:8000"
read_only: true
depends_on:
- devops_server
- mongo
cap_drop:
- ALL
tmpfs:
Expand All @@ -58,7 +70,7 @@ services:
networks:
- laf

admin:
devops_admin:
image: lessx/less-admin:latest
ports:
- 8080:80
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"watch": "lerna run watch",
"init": "lerna run init",
"prepublishOnly": "npm run build",
"init-start": "npm run init && npm run start"
"init-start": "npm run init && npm run start",
"docker-build": "node ./scripts/docker-build.js",
"docker-push": "node ./scripts/docker-push.js"
},
"keywords": [
"BaaS",
Expand Down
2 changes: 1 addition & 1 deletion scripts/docker-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function main() {

const appDockerfile = path.resolve(__dirname, '../packages/app-server')
const appVersion = getAppServerVersion()
buildImage(devopsDockerfile, `${images.app}:${appVersion}`, `${images.app}:latest`)
buildImage(appDockerfile, `${images.app}:${appVersion}`, `${images.app}:latest`)
}

main()
6 changes: 3 additions & 3 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const assert = require('assert')
const child_process = require('child_process')

const images = {
devops: 'laf-devops-server',
app: 'laf-app-server'
devops: 'lessx/laf-devops-server',
app: 'lessx/laf-app-server'
}

function getDevopsServerVersion() {
Expand Down Expand Up @@ -48,7 +48,7 @@ function getAppServerVersion() {
* @param {string} filepath path of Dockerfile
*/
function pushImage(tag) {
const sub = child_process.spawn('docker', ['push', tag)
const sub = child_process.spawn('docker', ['push', tag])

sub.stdout.on('data', (data) => {
console.log(`${tag} stdout: ${data}`);
Expand Down

0 comments on commit ca12167

Please sign in to comment.