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: add docker-compose.yml #14

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iloveyou11
Copy link

@iloveyou11 iloveyou11 commented Apr 28, 2021

  1. npm config set registry https://registry.npm.taobao.org && npm install --prod
  2. 新增docker-compose.yml文件
  3. 运行docker-compose up -d(启动docker中的node、mysql、redis,并将端口映射到本机)
  4. 运行npm run dev,访问http://127.0.0.1:8443 即可

这样电脑可以不用安装node、mysql、redis等环境,直接运行本项目。

environment:
- MYSQL_ROOT_PASSWORD=root
volumes: # 将容器的目录映射到宿主机上目录中
- "./db:/docker-entrypoint-initdb.d/" # 启动时自动执行db下的sql文件

This comment was marked as outdated.

Copy link
Member

Choose a reason for hiding this comment

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

这里会提示 ERROR 1046 (3D000) at line 3: No database selected

Copy link
Author

Choose a reason for hiding this comment

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

建议整合db下的init.sql文件为以下内容,因为这里"./db:/docker-entrypoint-initdb.d/"是指定在启动mysql时自动执行db下的sql文件,我看你初始数据库的操作在init_unittest_db.sh文件中

Copy link
Author

Choose a reason for hiding this comment

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

-- 创建数据库
DROP DATABASE IF EXISTS xprofiler_console_unittest;
CREATE DATABASE xprofiler_console_unittest;
DROP DATABASE IF EXISTS xprofiler_logs_unittest;
CREATE DATABASE xprofiler_logs_unittest;

-- 切换到数据库
use xprofiler_console_unittest;

-- 在数据库中建表
DROP TABLE IF EXISTS user;
CREATE TABLE user(
id INT UNSIGNED AUTO_INCREMENT COMMENT 'unique auto increment id',
name VARCHAR(100) NOT NULL COMMENT 'user name',
nick VARCHAR(100) NOT NULL COMMENT 'user nick name',
pass VARCHAR(200) NOT NULL COMMENT 'user pass key',
identity VARCHAR(20) NOT NULL COMMENT 'user identity sign',
mail VARCHAR(250) NOT NULL COMMENT 'user mail address',
gm_modified DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'system modify timestamp',
gm_create DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'system create timestamp',
PRIMARY KEY (id),
UNIQUE KEY (name),
UNIQUE KEY (identity)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'user info table';

DROP TABLE IF EXISTS apps;
CREATE TABLE apps(
id INT UNSIGNED AUTO_INCREMENT COMMENT 'unique auto increment id',
name VARCHAR(50) NOT NULL COMMENT 'app name',
owner INT UNSIGNED NOT NULL COMMENT 'owner user unique id',
secret VARCHAR(50) NOT NULL COMMENT 'app secret key',
gm_modified DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'system modify timestamp',
gm_create DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'system create timestamp',
PRIMARY KEY (id),
UNIQUE KEY (owner, name),
INDEX (owner)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'app info table';

DROP TABLE IF EXISTS members;
CREATE TABLE members(
id INT UNSIGNED AUTO_INCREMENT COMMENT 'unique auto increment id',
app INT UNSIGNED NOT NULL COMMENT 'app unique id',
user INT UNSIGNED NOT NULL COMMENT 'user unique id',
status INT UNSIGNED NOT NULL COMMENT '1: inviting, 2: joined',
gm_modified DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'system modify timestamp',
gm_create DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'system create timestamp',
PRIMARY KEY (id),
UNIQUE KEY (app, user)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'app members info table';

DROP TABLE IF EXISTS files;
CREATE TABLE files(
id INT UNSIGNED AUTO_INCREMENT COMMENT 'unique auto increment id',
app INT NOT NULL COMMENT 'app unique id',
agent VARCHAR(50) NOT NULL COMMENT 'agent name',
type VARCHAR(50) NOT NULL COMMENT 'file type',
file VARCHAR(250) NOT NULL COMMENT 'file path',
storage VARCHAR(250) DEFAULT "" COMMENT 'file storage path with custom',
user INT UNSIGNED NOT NULL COMMENT 'user unique id',
status TINYINT UNSIGNED DEFAULT 0 COMMENT '0:creating, 1:created, 2:transferring, 3:transferred',
favor TINYINT UNSIGNED DEFAULT 0 COMMENT '0:not favor, 1:has favor',
token VARCHAR(50) DEFAULT "" COMMENT 'file token',
gm_modified DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'system modify timestamp',
gm_create DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'system create timestamp',
PRIMARY KEY (id),
UNIQUE KEY (app, agent, file, storage),
INDEX (id, app, type)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'analyse file info table';

DROP TABLE IF EXISTS coredumps;
CREATE TABLE coredumps(
id INT UNSIGNED AUTO_INCREMENT COMMENT 'unique auto increment id',
app INT NOT NULL COMMENT 'app unique id',
agent VARCHAR(50) NOT NULL COMMENT 'agent name',
file VARCHAR(250) NOT NULL COMMENT 'file path',
file_storage VARCHAR(250) DEFAULT "" COMMENT 'file storage with custom',
file_status TINYINT UNSIGNED DEFAULT 0 COMMENT '0:creating, 1:created, 2:transferring, 3:transferred',
node VARCHAR(250) NOT NULL COMMENT 'node path',
node_storage VARCHAR(250) DEFAULT "" COMMENT 'node name',
node_status TINYINT UNSIGNED DEFAULT 0 COMMENT '0:creating, 1:created, 2:transferring, 3:transferred',
user INT UNSIGNED NOT NULL COMMENT 'user unique id',
favor TINYINT UNSIGNED DEFAULT 0 COMMENT '0:not favor, 1:has favor',
token VARCHAR(50) DEFAULT "" COMMENT 'file token',
gm_modified DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'system modify timestamp',
gm_create DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'system create timestamp',
PRIMARY KEY (id),
UNIQUE KEY (app, agent, file, file_storage),
INDEX (id, app)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'coredumps info table';

DROP TABLE IF EXISTS strategies;
CREATE TABLE strategies(
id INT UNSIGNED AUTO_INCREMENT COMMENT 'unique auto increment id',
app INT NOT NULL COMMENT 'app unique id',
context VARCHAR(50) NOT NULL COMMENT 'context type',
push VARCHAR(50) NOT NULL COMMENT 'push level',
webhook TINYINT UNSIGNED DEFAULT 0 COMMENT '0:close, 1:open',
wtype VARCHAR(20) DEFAULT '' COMMENT 'webhook type',
waddress VARCHAR(200) DEFAULT '' COMMENT 'webhook address',
wsign VARCHAR(100) DEFAULT '' COMMENT 'webhook sign',
expression VARCHAR(150) NOT NULL COMMENT 'alarm expression',
content VARCHAR(150) NOT NULL COMMENT 'alarm content',
status TINYINT UNSIGNED DEFAULT 1 COMMENT '0:disable, 1:enable',
gm_modified DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'system modify timestamp',
gm_create DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'system create timestamp',
PRIMARY KEY (id),
INDEX (id, app)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'strategies info table';

DROP TABLE IF EXISTS contacts;
CREATE TABLE contacts(
id INT UNSIGNED AUTO_INCREMENT COMMENT 'unique auto increment id',
strategy INT UNSIGNED NOT NULL COMMENT 'strategy unique id',
user INT UNSIGNED NOT NULL COMMENT 'user unique id',
gm_modified DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'system modify timestamp',
gm_create DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'system create timestamp',
PRIMARY KEY (id),
UNIQUE KEY (strategy, user),
INDEX (strategy)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'strategy contacts info table';

@hyj1991
Copy link
Member

hyj1991 commented Apr 28, 2021

最好再补个 quick start 的步骤,我放到文档里。

@iloveyou11
Copy link
Author

最好再补个 quick start 的步骤,我放到文档里。

按照刚刚提到的,修改下db/init.sql的文件内容,即可按照以下步骤快速启动项目。

  1. npm i(如果安装太慢需要切换源,可执行 npm config set registry https://registry.npm.taobao.org && npm install --prod)
  2. docker-compose up -d(新增)
  3. npm run dev

@hyj1991
Copy link
Member

hyj1991 commented Apr 28, 2021

最好再补个 quick start 的步骤,我放到文档里。

按照刚刚提到的,修改下db/init.sql的文件内容,即可按照以下步骤快速启动项目。

  1. npm i(如果安装太慢需要切换源,可执行 npm config set registry https://registry.npm.taobao.org && npm install --prod)
  2. docker-compose up -d(新增)
  3. npm run dev

我明白了,这个 docker-compose.yml 只是将依赖的 db/redis 做了初始化,那为什么需要多一层 service nodejs,应该只需要 mysqlredis

@iloveyou11

This comment has been minimized.

@hyj1991
Copy link
Member

hyj1991 commented Apr 28, 2021

加上node是考虑了电脑本身没有安装node环境的情况。docker-compose.yml是把项目依赖的环境都考虑进去了。

这个 docker 内的 node 没法直接在宿主机上使用吧?要 exec 到对应的容器内才能用

@hyj1991
Copy link
Member

hyj1991 commented Apr 28, 2021

nodejs.ER_NOT_SUPPORTED_AUTH_MODEError: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

另外,我测试了下会提示 egg-mysql 的版本过低,我看这个 file 里默认会安装 mysql@8,egg-mysql 貌似不支持

@iloveyou11
Copy link
Author

nodejs.ER_NOT_SUPPORTED_AUTH_MODEError: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

另外,我测试了下会提示 egg-mysql 的版本过低,我看这个 file 里默认会安装 mysql@8,egg-mysql 貌似不支持

版本问题是因为mysql8的密码加密方式改了,需要改一下加密方式
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
password是将要设置的root用户的密码

image

可以参考 https://blog.csdn.net/qq_26819733/article/details/80794047

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants