Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 1.x docker #56

Merged
merged 20 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode
# node_modules/
# config/manifest.json
run
logs
cache
.history
# public
resources
# app/view
# .yarnrc
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:14.17.4-slim

RUN mkdir -p /app/doraemon

# RUN set -x && \
# echo "deb http://mirrors.aliyun.com/debian/ buster main non-free contrib" > /etc/apt/sources.list && \
# echo "deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib" >> /etc/apt/sources.list && \
# apt-get update && apt-get install -y --no-install-recommends \
# inetutils-ping \
# iproute2 \
# vim \
# ssh \
# curl \
# netcat-openbsd \
# libltdl7 \
# telnet \
# net-tools \
# && \
# apt-get clean && \
# rm -rf /var/lib/apt/lists/*

COPY . /app/doraemon

WORKDIR /app/doraemon

CMD ["yarn", "server:docker"]

EXPOSE 7002
46 changes: 42 additions & 4 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 哆啦 A 梦 (Doraemon) Here, you can find everything you need
# 哆啦 A 梦 (Doraemon) Here, you can find everything you need

[English](./README.md) | 简体中文

Expand All @@ -14,7 +14,7 @@

## 环境支持

- node >= 8.0.0
- node >= 16.0.0

## 快速开始

Expand All @@ -29,6 +29,7 @@ cd doraemon
```

#### 安装依赖

我们推荐使用 yarn 进行依赖安装。

```bash
Expand All @@ -54,15 +55,52 @@ yarn dev
#### 发布模式启动应用

```bash
yarn start
yarn start

yarn start:test // 测试环境发布
```

## 使用 Docker 部署(仅支持 Linux)

#### 构建镜像(如果镜像已在 Docker Hub 中,可跳过此步)
1. 修改 `./dockerScripts/const.sh` 文件配置的镜像信息(`image_mysql`, `image_web`, `version` 等)

2. 执行 build 命令

```bash
$ yarn build:docker
```

3. 待构建完成并推到仓库后,登入部署服务器,拉取镜像并启动容器

#### 启动镜像

1. 登入部署服务器,进到 `dockerScripts` 文件夹下,修改 `const.sh` 文件中 `v_path` (数据卷的存储路径)

2. 启动容器
回到根目录下,执行启动命令,拉取最新镜像,并启动

```bash
$ yarn start:docker
```

如果是第一次启动,尚未初始化库表结构,请执行 `-volume` 命令(历史数据需手动迁移)

```bash
$ yarn start:docker -volume
```

3. 上述操作会删除原有容器和镜像,拉取最新镜像,如果只是重启停止的容器,仅需要 start 即可

```bash
$ docker start <containerId>
```

访问: http://127.0.0.1:7002

## 使用指南

查看完整的 Doraemon 功能使用指南,请访问 [在线文档](https://dtstack.github.io/doraemon/docsify/#/)
查看完整的 Doraemon 功能使用指南,请访问 [在线文档](https://dtstack.github.io/doraemon/docsify/#/)

## 如何贡献

Expand Down
49 changes: 44 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 哆啦 A 梦 (Doraemon) Here, you can find everything you need
# 哆啦 A 梦 (Doraemon) Here, you can find everything you need

English | [简体中文](./README-zh_CN.md)
English | [简体中文](./README-zh_CN.md)

A management tool to help you organize your daily development, configuration, proxy services, host resources, etc.

Expand All @@ -20,14 +20,14 @@ A management tool to help you organize your daily development, configuration, pr

### Install


```bash
git clone git@github.com:DTStack/doraemon.git

cd doraemon
```

#### Installation dependencies

We recommend using yarn for dependency installation.

```bash
Expand All @@ -53,11 +53,50 @@ visit: http://127.0.0.1:7001
#### Publish mode to start

```bash
yarn start
yarn start

yarn start:test // test environment publishing
```

## Deploy with Docker(Only support Linux)

#### Images build(If the image is already in the Docker Hub, skip this step)

1. Modify the configure of the image information in the `./dockerScripts/const.sh`(such as `image_mysql`, `image_web`, `version` and so on)

2. Image build

```bash
$ yarn build:docker
```

3. After the build is complete and pushed to the repository, log in to the deployment server, pull the image and start the container

#### Container run

1. Log in to the deployment server, `cd ./dockerScripts`, change `v_path`(the path to the data volume) in the `const.sh` file

2. container run
Return to the root directory and run the startup command, pull the latest image and run

```bash
$ yarn start:docker
```

If this is the first startup and the library table structure has not been initialized, run the `-volume` command (historical data needs to be manually migrated)

```bash
$ yarn start:docker -volume
```

3. The preceding operations will delete the original container and image, and pull the latest image. If you want to restart the stopped container, you only need to start

```bash
$ docker start <containerId>
```

visit: http://127.0.0.1:7002

## Documentation

Visit [Doraemon Docs](https://dtstack.github.io/doraemon/docsify/#/) for the full Doraemon documentation.
Expand All @@ -72,4 +111,4 @@ Detailed changes for each release are documented in the [ChangeLog.md](./CHANGEL

## License

[MIT](LICENSE)
[MIT](LICENSE)
5 changes: 3 additions & 2 deletions app/controller/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ class CommonController extends Controller {
}
async getLocalIp() {
const { app, ctx } = this;
const localIp = ctx.header['x-real-ip']||ctx.ip;
const localIp = ctx.header['x-real-ip'] || ctx.ip;
ctx.body = app.utils.response(true, {
localIp,
host: ctx.host,
protocol: ctx.protocol
protocol: ctx.protocol,
ips: ctx.ips
});
}
}
Expand Down
8 changes: 7 additions & 1 deletion config/config.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const config = require('../env.json');
const mysqlConfig = (config && config.mysql && config.mysql.prod) || {};
const mysqlConfig = (config
&& config.mysql
&& (
process.env.DEPLOY_ENV === 'docker'
? config.mysql.docker
: config.mysql.prod
)) || {};
const { database, host, port, username, password } = mysqlConfig;

/**
Expand Down
2 changes: 1 addition & 1 deletion config/config.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const config = require('../env.json');
const mysqlConfig = (config && config.mysql && config.mysql.prod) || {};
const mysqlConfig = (config && config.mysql && config.mysql.test) || {};
const { database, host, port, username, password } = mysqlConfig;

/**
Expand Down
5 changes: 5 additions & 0 deletions dockerScripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
yarn
yarn build
cd ./dockerScripts
sh ./make.sh
10 changes: 10 additions & 0 deletions dockerScripts/const.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
export image_mysql=172.16.84.121/dtstack-dev/doraemon_mysql
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ip 写到文档里,不要写到代码里


export image_web=172.16.84.121/dtstack-dev/doraemon_web

export version=0.0.2

export mysql_pwd=123456

export v_path=/home/app/doraemon_docker/data
59 changes: 59 additions & 0 deletions dockerScripts/docker_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
source ./const.sh

# 导入 sql 文件
soucreSql() {
containerId=$(docker ps -a | grep $image_mysql | awk '{print $1}')
mysql_path=/app/doraemon/doraemon.sql
docker exec -i $containerId mysql -uroot -p$mysql_pwd <<EOF
source $mysql_path;
ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY '$mysql_pwd';
FLUSH PRIVILEGES;
EOF
}

# 启动容器
reRunContainer() {
imageName=$1:$version

# 停止容器并删除
containerId=$(docker ps -a | grep $imageName | awk '{print $1}')
if [[ $containerId ]]; then
docker stop $containerId
docker rm $containerId
fi

# 删除老镜像
imageId=$(docker images | grep $1 | awk '{print $3}')
if [[ $imageId ]]; then
docker rmi $imageId
fi

# 拉取镜像
docker image pull $imageName

# 启动
if [[ $imageName =~ $image_web ]]; then
docker run -d --net=host $imageName
else
docker run -d \
--name="doraemon_mysql" \
-v $v_path:/var/lib/mysql \
-e MYSQL_ROOT_HOST=% \
-e MYSQL_ROOT_PASSWORD=$mysql_pwd \
-p 3302:3306 \
$imageName

sleep 11
if [[ $2 == '-volume' ]]; then
mkdir -p $v_path
soucreSql
fi
fi
}

if [[ $1 == 'web' ]]; then
reRunContainer $image_web
elif [[ $1 == 'mysql' ]]; then
reRunContainer $image_mysql $2
fi
3 changes: 3 additions & 0 deletions dockerScripts/make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
sh make_mysql.sh
sh make_web.sh
8 changes: 8 additions & 0 deletions dockerScripts/make_mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
source ./const.sh

imageName=$image_mysql:$version

docker build -t $imageName ../sql

docker push $imageName
8 changes: 8 additions & 0 deletions dockerScripts/make_web.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
source ./const.sh

imageName=$image_web:$version

docker build -t $imageName ../

docker push $imageName
4 changes: 4 additions & 0 deletions dockerScripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
cd ./dockerScripts
sh ./docker_start.sh mysql $1
sh ./docker_start.sh web
1 change: 1 addition & 0 deletions docs/docsify/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

+ [快速开始](zh-cn/start/快速开始)
+ [开发者使用](zh-cn/start/开发者使用)
+ [Docker 部署](zh-cn/start/Docker部署)
* 配置
+ [配置项](zh-cn/configuration/envConfig)
+ [MySQL](zh-cn/configuration/mysql)
Expand Down
1 change: 1 addition & 0 deletions docs/docsify/zh-cn/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

+ [快速开始](zh-cn/start/快速开始)
+ [开发者使用](zh-cn/start/开发者使用)
+ [Docker 部署](zh-cn/start/Docker部署)
* 配置
+ [配置项](zh-cn/configuration/envConfig)
+ [MySQL](zh-cn/configuration/mysql)
Expand Down
8 changes: 6 additions & 2 deletions docs/docsify/zh-cn/configuration/envConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,22 @@ dingBot 的通知模板的跳转路径,默认跳转到帮助文档,可自行
- 类型:Object
- 默认值:无

数据库连接配置,目前仅提供 config.prod.js 生产下的数据库连接配置
数据库连接配置,提供不同环境下的数据库连接配置
- test => config.test.js
- prod/docker => config.prod.js (其中,mysql.docker 配置仅在 Docker 部署的情况下生效)

```json
{
"mysql": {
"test": {},
"prod": {
"database": "doraemon",
"host": "127.0.0.1",
"port": 3306,
"username": "root",
"password": "******"
}
},
"docker": {}
}
}
```
Loading