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

fix #67 not run in `docker mode` in cloud9 ide

上级 461dc840
......@@ -43,7 +43,6 @@ test('Config methods', t => {
})
}, 'should throw for error apihost')
t.true('isDocker' in Config, 'should identify docker env by `isDocker`')
})
test('Config puppetInstance', t => {
......@@ -65,3 +64,16 @@ test('Config puppetInstance', t => {
}, Error, 'should throw after set to null')
})
test('Config docker mode', t => {
t.true('isDocker' in Config, 'should identify docker env by `isDocker`')
if ('C9_PORT' in process.env) {
t.is(Config.isDocker, false, 'should not in docker mode in Cloud9 IDE')
} else if (require('is-ci')) {
t.is(Config.isDocker, false, 'should not in docker mode in Continuous Integeration System')
} else {
// a custom running envioronment, maybe docker, maybe not
}
})
\ No newline at end of file
......@@ -92,11 +92,24 @@ Object.assign(Config, {
})
function isWechatyDocker() {
/**
* Continuous Integration System
*/
const isCi = require('is-ci')
if (isCi) {
return false
}
/**
* Cloud9 IDE
*/
const c9 = Object.keys(process.env)
.filter(k => /^C9_/.test(k))
.length
if (c9 > 7 && process.env['C9_PORT']) {
return false
}
const cgroup = '/proc/1/cgroup'
try { fs.statSync(cgroup).isFile() }
catch (e) { return false }
......@@ -105,10 +118,11 @@ function isWechatyDocker() {
.toString()
.replace(/\n$/, '')
// instead of `/`, docker will end with a container id
if (/\/$/.test(line)) {
return false
}
// instead of '/', docker will end with container id
return true
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册