Comments (10)
贴日志,也可以试着把 npm 源设为国内
from docker-yapi.
日志是这样的:
启动引导服务...
写入配置...
{
"adminAccount": “[email protected]”,
"db": {
"servername": "yapi-mongo",
"port": 27017,
"DATABASE": "yapi"
},
"mail": {
"enable": false,
"auth": {}
},
"ldapLogin": {
"enable": false
},
"closeRegister": true,
"plugins": [
{
"name": "add-user"
}
],
"adminPassword": “admin”,
"npmRegistry": "https://registry.npm.taobao.org",
"port": 3000
}
等待 MongoDB 服务可用...
安装 YApi 插件...
- cd /yapi/vendors
- npm install yapi-plugin-add-user '--registry=https://registry.npm.taobao.org' --no-audit
npm
WARN [email protected] requires a peer of mongoose@^4.1.12 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of webpack@^3.0.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of jquery@>=1.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react@^0.14.0 || ^15.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react-dom@^0.14.0 || ^15.0.1 but none is installed. You must install peer dependencies yourself.
- [email protected]
added 1 package from 1 contributor in 34.96s
1 package is looking for funding
run npm fund
for details
- npm run build-client
[email protected] build-client /yapi/vendors
NODE_ENV=production ykit pack -m
<--- Last few GCs --->
[40:0x557189e180a0] 85843 ms: Mark-sweep 498.9 (509.9) -> 495.7 (510.4) MB, 614.4 / 0.0 ms (average mu = 0.145, current mu = 0.079) allocation failure scavenge might not succeed
[40:0x557189e180a0] 86659 ms: Mark-sweep 499.4 (510.4) -> 496.1 (510.7) MB, 756.5 / 0.0 ms (average mu = 0.109, current mu = 0.074) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x5571856e3739]
Security context: 0x27064e240921
1: _walk [0x2128eb277769] [0x3ede9cf404b9 :~985] [pc=0x25d6692fd45e](this=0x3686f7f7f539 <AST_Dot map = 0x10b3f5b9ab1>,0x3f44ad7a3311 )
2: /* anonymous */ [0xcac8a01c541] [0x3ede9cf404b9 :~896] [pc=0x25d668f91acf](this=0x3686f7f728b9 <AST_Call map = 0x10b3f5b8d41>)
3: _walk [0x2128eb266f71] [...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Writing Node.js report to file: report.20200108.054150.40.0.001.json
Node.js report completed
Aborted (core dumped)
尝试安装 YApi...
- node '--unhandled-rejections=strict' ./vendors/server/install.js
log: mongodb load success...
初始化管理员账号成功,账号名:"[email protected]",密码:”admin”
关闭引导服务...
尝试启动 YApi...
log: -------------------------------------swaggerSyncUtils constructor-----------------------------------------------
log: 服务已启动,请打开下面链接访问:
http://127.0.0.1:3000/
log: mongodb load success...
(node:1) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
之后访问页面,js资源找不到
from docker-yapi.
? 解决了,我这边正在测试解决方法呢
from docker-yapi.
? 解决了,我这边正在测试解决方法呢
我看有一个 Last few GCs,是不是我这边文件编译的时候内存溢出了
from docker-yapi.
是溢出了,但可以解决。
麻烦测试下这个方案,复制以下代码全部替换 start.js
:
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = __importDefault(require("child_process"));
const fs_1 = __importDefault(require("fs"));
const http_1 = __importDefault(require("http"));
const deepmerge_1 = __importDefault(require("deepmerge"));
// ==== 辅助函数 ====
class Helper {
/**
* 简单的 CONSTANT_CASE 实现。
*
* @param str 要转换的字符串
* @returns 返回转换后的字符串
*/
static constCase(str) {
return str
.replace(/(?<=[a-z])(?=[A-Z])/g, '_')
.toUpperCase();
}
/**
* 是否是假值。
*
* @param value 要判断的值
* @returns 返回判断结果
*/
static isFalsy(value) {
return [
'false', 'False', 'FALSE',
'off', 'Off', 'OFF',
'no', 'No', 'NO',
'0',
].includes(value);
}
/**
* 执行命令。
*
* @param cmd 要执行的命令
* @param log 记录执行过程
* @returns 返回执行结果
*/
static async exec(cmd, log) {
return new Promise(resolve => {
const child = child_process_1.default.spawn('sh', ['-c', `set -ex\n${cmd}`], {
stdio: 'pipe',
cwd: process.cwd(),
});
let stdout = '';
let stderr = '';
child.stdout.on('data', data => {
log && log(String(data));
stdout += data;
});
child.stderr.on('data', data => {
log && log(String(data));
stderr += data;
});
child.on('error', error => {
resolve({ error, stdout, stderr, cmd });
});
child.on('close', code => {
resolve({ stdout, stderr, cmd, code });
});
});
}
/**
* 执行 JS 文件。
*
* @param path 文件路径
* @param log 记录执行过程
* @returns 返回执行结果
*/
static async execJsFile(path, log) {
return Helper.exec(`node --unhandled-rejections=strict ${path}`, log);
}
}
// ==== 配置解析 ====
// 配置格式
// ref: https://hellosean1025.github.io/yapi/devops/index.html
const configShape = {
adminAccount: String,
// 管理员密码:
// 由 Docker-YApi 新增,
// 在 Dockerfile 里有对相关文件进行修改以支持该配置的命令
adminPassword: String,
// NPM 源:
// 由 Docker-YApi 新增,
// 目前仅在安装插件时使用
npmRegistry: String,
closeRegister: Boolean,
port: Number,
db: {
servername: String,
port: Number,
DATABASE: String,
user: String,
pass: String,
connectString: String,
authSource: String,
options: JSON,
},
mail: {
enable: Boolean,
host: String,
port: Number,
from: String,
auth: {
user: String,
pass: String,
},
},
ldapLogin: {
enable: Boolean,
server: String,
baseDn: String,
bindPassword: String,
searchDn: String,
searchStandard: String,
emailPostfix: String,
emailKey: String,
usernameKey: String,
},
plugins: [
{
name: String,
options: JSON,
},
],
};
class ConfigParser {
/**
* 从文件获取配置。
*
* @returns 返回获取到的配置
*/
static extractConfigFromFile() {
return fs_1.default.existsSync('./config.js')
? require('./config.js')
: fs_1.default.existsSync('./config.json')
? JSON.parse(fs_1.default.readFileSync('./config.json').toString())
: {};
}
/**
* 从环境变量获取配置。
*
* @param configCtx 配置上下文
* @param shapeCtx 格式上下文
* @param envPath 环境变量路径
* @returns 返回获取到的配置
*/
static extractConfigFromEnv(configCtx = {}, shapeCtx = configShape, envPath = ['YAPI']) {
for (const [key, shape] of Object.entries(shapeCtx)) {
const KEY = Helper.constCase(key);
if (Array.isArray(shape) || shape === JSON || typeof shape === 'function') {
const envKey = envPath.concat(KEY).join('_');
const envValue = process.env[envKey];
if (envValue != null) {
configCtx[key] = shape === Boolean
? !Helper.isFalsy(envValue)
: (Array.isArray(shape) || shape === JSON)
? JSON.parse(envValue.trim())
: shape(envValue);
}
}
else {
if (configCtx[key] == null) {
configCtx[key] = {};
}
ConfigParser.extractConfigFromEnv(configCtx[key], shape, envPath.concat(KEY));
}
}
return configCtx;
}
/**
* 合并配置,配置2覆盖配置1。
*
* @param config1 配置1
* @param config2 配置2
* @returns 返回合并后的配置
*/
static mergeConfig(config1, config2) {
return deepmerge_1.default(config1, config2, { arrayMerge: (_, source) => source });
}
/**
* 获取配置。
*/
static extractConfig() {
const configFromFile = ConfigParser.extractConfigFromFile();
const configFromEnv = ConfigParser.extractConfigFromEnv();
const config = ConfigParser.mergeConfig(configFromFile, configFromEnv);
// 端口固定为 3000,但支持通过环境变量 PORT 改变
// 注: Heroku 必须使用 PORT 环境变量
Object.assign(config, {
port: process.env.PORT || 3000,
});
return config;
}
}
// ==== 引导服务 ====
class BootstrapServer {
constructor(port) {
this.port = port;
this.logs = [];
}
/**
* 日志记录。
*/
log(message) {
this.logs.push(message);
}
/**
* 打开引导服务。
*/
open() {
this.server = http_1.default.createServer((req, res) => {
res.setHeader('Connection', 'close');
if (/\/logs$/.test(req.url || '')) {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.end(JSON.stringify(this.logs));
}
else {
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.end(`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>docker-YApi</title>
<script crossorigin="anonymous" src="https://cdn.staticfile.org/fetch/3.0.0/fetch.min.js"></script>
</head>
<body>
<h1>YApi 正在启动...</h1>
<hr />
<pre id="data"></pre>
<script>
function fetchData() {
var timer = setTimeout(fetchData, 500)
fetch('./logs')
.then(function (res) {
return res.json()
})
.then(function (data) {
document.querySelector('#data').innerHTML = data.join('\\n')
})
.catch(function () {
clearTimeout(timer)
setTimeout(function () { location.reload() }, 2000)
})
}
fetchData()
</script>
</body>
</html>
`);
}
});
this.server.listen(this.port);
}
/**
* 关闭引导服务。
*/
async close() {
return new Promise(resolve => {
this.server.close(resolve);
});
}
}
// ==== 入口 ====
class Main {
constructor() {
this.config = ConfigParser.extractConfig();
this.bootstrapServer = new BootstrapServer(this.config.port);
}
/**
* 日志记录。
*/
log(message) {
console.log(message);
this.bootstrapServer.log(message);
}
/**
* 安装 YApi 插件。
*/
async installPluginsIfNeeded() {
if (Array.isArray(this.config.plugins) && this.config.plugins.length > 0) {
const packages = this.config.plugins
.map(plugin => `yapi-plugin-${plugin.name}`)
.join(' ');
await Helper.exec(`
cd /yapi/vendors
npm install ${packages} ${this.config.npmRegistry ? `--registry=${this.config.npmRegistry}` : ''} --no-audit
NODE_ENV=production
node --max-old-space-size=8192 ./node_modules/ykit/bin/ykit pack -m
`, message => this.log(message));
}
}
/**
* 等待 MongoDB 服务可用。
*/
async waitMongoDBAvailable() {
await Helper.exec(`
until nc -z ${this.config.db.servername} ${this.config.db.port || 27017}
do
sleep 0.5
done
`);
}
async start() {
this.log('启动引导服务...');
this.bootstrapServer.open();
this.log('写入配置...');
this.log(JSON.stringify(this.config, null, 2));
fs_1.default.writeFileSync('./config.json', JSON.stringify(this.config));
this.log('等待 MongoDB 服务可用...');
await this.waitMongoDBAvailable();
this.log('安装 YApi 插件...');
await this.installPluginsIfNeeded();
this.log('尝试安装 YApi...');
await Helper.execJsFile('./vendors/server/install.js', message => this.log(message));
this.log('关闭引导服务...');
await this.bootstrapServer.close();
this.log('尝试启动 YApi...');
require('./vendors/server/app.js');
}
}
new Main()
.start()
.catch(err => {
throw err;
});
然后修改 docker-compose.yml
,在 yapi-web
下添加:
volumes:
- ./start.js:/yapi/start.js
然后重启试试。
from docker-yapi.
还是不行,这次的日志是这样的:
Attaching to yapi-web
yapi-web | 启动引导服务...
yapi-web | 写入配置...
yapi-web | {
yapi-web | "adminAccount": "[email protected]",
yapi-web | "db": {
yapi-web | "servername": "yapi-mongo",
yapi-web | "port": 27017,
yapi-web | "DATABASE": "yapi"
yapi-web | },
yapi-web | "mail": {
yapi-web | "enable": false,
yapi-web | "auth": {}
yapi-web | },
yapi-web | "ldapLogin": {
yapi-web | "enable": false
yapi-web | },
yapi-web | "closeRegister": true,
yapi-web | "plugins": [
yapi-web | {
yapi-web | "name": "add-user"
yapi-web | }
yapi-web | ],
yapi-web | "adminPassword": "admin",
yapi-web | "npmRegistry": "https://registry.npm.taobao.org",
yapi-web | "port": 3000
yapi-web | }
yapi-web | 等待 MongoDB 服务可用...
yapi-web | 安装 YApi 插件...
yapi-web | + cd /yapi/vendors
yapi-web | + npm install yapi-plugin-add-user '--registry=https://registry.npm.taobao.org' --no-audit
yapi-web |
yapi-web | npm WARN [email protected] requires a peer of mongoose@^4.1.12 but none is installed. You must install peer dependencies yourself.
yapi-web | npm WARN [email protected] requires a peer of webpack@^3.0.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.
yapi-web | npm WARN [email protected] requires a peer of jquery@>=1.8.0 but none is installed. You must install peer dependencies yourself.
yapi-web | npm WARN [email protected] requires a peer of react@^0.14.0 || ^15.0.1 but none is installed. You must install peer dependencies yourself.
yapi-web | npm WARN [email protected] requires a peer of react-dom@^0.14.0 || ^15.0.1 but none is installed. You must install peer dependencies yourself.
yapi-web |
yapi-web |
yapi-web | + [email protected]
yapi-web | added 1 package from 1 contributor in 39.005s
yapi-web |
yapi-web |
yapi-web | 1 package is looking for funding
yapi-web | run npm fund
for details
yapi-web |
yapi-web |
yapi-web | + NODE_ENV=production
yapi-web | + node '--max-old-space-size=8192' ./node_modules/ykit/bin/ykit pack -m
yapi-web |
yapi-web | Killed
yapi-web |
yapi-web | 尝试安装 YApi...
yapi-web | + node '--unhandled-rejections=strict' ./vendors/server/install.js
yapi-web |
yapi-web | log: mongodb load success...
yapi-web |
yapi-web | 初始化管理员账号成功,账号名:"[email protected]",密码:"admin"
yapi-web |
yapi-web | 关闭引导服务...
yapi-web | 尝试启动 YApi...
yapi-web | log: -------------------------------------swaggerSyncUtils constructor-----------------------------------------------
yapi-web | log: 服务已启动,请打开下面链接访问:
yapi-web | http://127.0.0.1:3000/
yapi-web | log: mongodb load success...
yapi-web | (node:1) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
from docker-yapi.
你物理机多大内存啊,是不是得升级下下。或者改吧改吧在本地弄个镜像在服务器上避免打包也行。
from docker-yapi.
你物理机多大内存啊,是不是得升级下下。或者改吧改吧在本地弄个镜像在服务器上避免打包也行。
1GB,我升级一下看看
from docker-yapi.
yapi-web | 启动引导服务...
yapi-web | 写入配置...
yapi-web | {
yapi-web | "adminAccount": "[email protected]",
yapi-web | "db": {
yapi-web | "servername": "yapi-mongo",
yapi-web | "port": 27017,
yapi-web | "DATABASE": "yapi"
yapi-web | },
yapi-web | "mail": {
yapi-web | "enable": false,
yapi-web | "auth": {}
yapi-web | },
yapi-web | "ldapLogin": {
yapi-web | "enable": false
yapi-web | },
yapi-web | "closeRegister": true,
yapi-web | "plugins": [],
yapi-web | "adminPassword": "123456",
yapi-web | "port": 3000
yapi-web | }
yapi-web | 等待 MongoDB 服务可用...
yapi-web | 安装 YApi 插件...
yapi-web | 尝试安装 YApi...
yapi-web | + node '--unhandled-rejections=strict' ./vendors/server/install.js
yapi-web |
yapi-web | /yapi/vendors/server/install.js:15
yapi-web | throw new Error(
yapi-web | ^
yapi-web |
yapi-web | Error: init.lock文件已存在,请确认您是否已安装。如果需要重新安装,请删掉init.lock文件
yapi-web | at install (/yapi/vendors/server/install.js:15:11)
yapi-web | at Object. (/yapi/vendors/server/install.js:155:1)
yapi-web | at Module._compile (internal/modules/cjs/loader.js:1185:30)
yapi-web | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
yapi-web | at Module.load (internal/modules/cjs/loader.js:1034:32)
yapi-web | at Function.Module._load (internal/modules/cjs/loader.js:923:14)
yapi-web | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
yapi-web | at internal/main/run_main_module.js:17:47
yapi-web |
yapi-web | 关闭引导服务...
yapi-web | 尝试启动 YApi...
yapi-web | log: -------------------------------------swaggerSyncUtils constructor-----------------------------------------------
yapi-web | log: 服务已启动,请打开下面链接访问:
yapi-web | http://127.0.0.1:3000/
yapi-web | (node:1) Warning: Accessing non-existent property 'count' of module exports inside circular dependency
yapi-web | (Use node --trace-warnings ...
to show where the warning was created)
yapi-web | (node:1) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
yapi-web | (node:1) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
yapi-web | (node:1) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
yapi-web | log: mongodb load success...
from docker-yapi.
同样的问题:
修改docker-compose.yml:文件中YAPI_PLUGINS=[{"name":"add-user"}],然后执行docker-compose restart yapi-web 报上面的错误。
from docker-yapi.
Related Issues (20)
- 不能运行
- 设置YAPI_DB_USER、YAPI_DB_PASS之后,yapi-web运行报错
- 设置YAPI_DB_USER、YAPI_DB_PASS之后,yapi-web运行报错 HOT 2
- yapi-plugin-qsso 登录按钮不显示
- 无法上传postman json数据更新
- yapi-mongo exited HOT 2
- 您的CI挂了,导致dockerhub推送失败 HOT 3
- 更新不了,最新版本是1.10.2而不是1.20,在docker hub查询也是1.10.2 HOT 1
- 1.12.0 漏洞修复,镜像未更新成功 HOT 11
- 数据迁移重新部署后提示 等待 mongodb
- 登陆报504
- 该用户不存在
- 插件安装不了
- 增加内置插件
- yapi-mongo 的数据是一值存在吗
- 高级Mock保存不了
- 能不能给一个配置登录 MongoDB 服务的用户名和密码的docker-compose.yml啊 HOT 1
- 找不到插件 HOT 4
- Error: EROFS: read-only file system, mkdir '/sys/fs/cgroup/cpu/safeify' HOT 1
- 请问脚本怎么写
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docker-yapi.