提交 80ae173d 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

Merge branch 'master' of github.com:wechaty/wechaty

......@@ -97,6 +97,7 @@
"express": "^4.13.4",
"is-ci": "^1.0.9",
"phantomjs-prebuilt": "^2.1.13",
"is-docker": "^1.1.0",
"ps-tree": "^1.0.1",
"retry-promise": "^1.0.0",
"selenium-webdriver": "^3.0.0",
......@@ -119,7 +120,7 @@
"coveralls": "^2.11.14",
"cross-env": "^2.0.0",
"eslint": "^3.4.0",
"eslint-plugin-ava": "^3.0.0",
"eslint-plugin-ava": "^3.1.1",
"nyc": "^8.3.2",
"qrcode-terminal": "^0.10.0",
"shx": "^0.1.4",
......
......@@ -3,8 +3,8 @@
*
* https://github.com/wechaty/wechaty/
*/
import { execSync } from 'child_process'
import * as fs from 'fs'
const isCi = require('is-ci')
const isDocker = require('is-docker')
import { Puppet } from './puppet'
import { log } from './brolog-env'
......@@ -96,7 +96,6 @@ function isWechatyDocker() {
/**
* Continuous Integration System
*/
const isCi = require('is-ci')
if (isCi) {
return false
}
......@@ -111,24 +110,7 @@ function isWechatyDocker() {
return false
}
const cgroup = '/proc/self/cgroup'
try { fs.statSync(cgroup).isFile() }
catch (e) { return false }
// http://stackoverflow.com/a/20624315/1123955
const line = execSync(`grep docker ${cgroup} | sort -n 2>/dev/null | head -1`)
.toString()
.replace(/\n$/, '')
// instead of `/`, docker will end with a container id
// if (/\/$/.test(line)) {
// return false
// }
if (hasDockerContainerId(line)) {
return true
}
return false
return isDocker()
}
/**
......@@ -215,16 +197,4 @@ if (!global['WECHATY_CONFIG_INSTANCE_COUNTER']) {
}
global['WECHATY_CONFIG_INSTANCE_COUNTER']++
/**
* issue #84
*
* http://tuhrig.de/how-to-know-you-are-inside-a-docker-container/
*/
function hasDockerContainerId(line: string) {
// d22ff5ccbf50790c4724e19a30a6a6057d03d684ea3c2b0ddac1bf028e2cf470
const re = /[a-f0-9]{64}$/i
return re.test(line)
}
export { log, hasDockerContainerId }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册