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

better isDocker check

上级 3d2e4167
...@@ -13,7 +13,9 @@ echo "Starting Wechaty v$(wechaty-version) ..." ...@@ -13,7 +13,9 @@ echo "Starting Wechaty v$(wechaty-version) ..."
echo echo
# to identify run env (for tests) # to identify run env (for tests)
export WECHATY_DOCKER='docker' # @deprecated 20161001, use cgroup to test
# export WECHATY_DOCKER='docker'
# set CI here, in order to force ava to output use --verbose param, which is fit docker console log # set CI here, in order to force ava to output use --verbose param, which is fit docker console log
export CI="FORCE_AVA_OUTPUT_VERBOSE" export CI="FORCE_AVA_OUTPUT_VERBOSE"
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
* *
* https://github.com/wechaty/wechaty/ * https://github.com/wechaty/wechaty/
*/ */
const { execSync } = require('child_process')
const { accessSync, F_OK } = require('fs')
const Config = require('../package.json').wechaty const Config = require('../package.json').wechaty
/** /**
...@@ -44,7 +47,24 @@ Object.assign(Config, { ...@@ -44,7 +47,24 @@ Object.assign(Config, {
* 4. Envioronment Identify * 4. Envioronment Identify
*/ */
Object.assign(Config, { Object.assign(Config, {
isDocker: !!(process.env.WECHATY_DOCKER) isDocker: isInsideDocker()
}) })
function isInsideDocker() {
const cgroup = '/proc/1/cgroup'
try { accessSync(cgroup, F_OK) }
catch (e) { return false }
const line = execSync(`head -1 ${cgroup}`)
.toString()
.replace(/\n$/, '')
if (/\/$/.test(line)) {
return false
}
// instead of '/', docker will end with container id
return true
}
module.exports = Config.default = Config.Config = Config module.exports = Config.default = Config.Config = Config
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册