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

clean(code): identify Docker environment by ENV variable. (#84)

上级 b146572b
......@@ -43,7 +43,7 @@ async function main() {
1. Wechaty version: ${wechaty.version()}
2. ${os.type()} ${os.arch()} version ${os.release()} memory ${Math.floor(os.freemem() / 1024 / 1024)}/${Math.floor(os.totalmem() / 1024 / 1024)} MB
3. Docker: ${Config.isDocker}
3. Docker: ${Config.dockerMode}
4. Node version: ${process.version}
5. Tcp IPC TEST: ${ipcTestResult}
6. Chromedriver: ${chromedriverVersion}
......
......@@ -9,6 +9,8 @@ set -e
HOME=/bot
PATH=$PATH:/wechaty/bin:/wechaty/node_modules/.bin
export WECHATY_DOCKER=1
function wechaty::banner() {
echo
figlet " Wechaty "
......
......@@ -79,13 +79,13 @@ test('puppetInstance()', t => {
})
test('isDocker', t => {
t.true('isDocker' in Config, 'should identify docker env by `isDocker`')
test('dockerMode', t => {
t.true('dockerMode' in Config, 'should identify docker env by `dockerMode`')
if ('C9_PORT' in process.env) {
t.is(Config.isDocker, false, 'should not in docker mode in Cloud9 IDE')
t.is(Config.dockerMode, 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')
t.is(Config.dockerMode, false, 'should not in docker mode in Continuous Integeration System')
} else {
// a custom running envioronment, maybe docker, maybe not
}
......
......@@ -16,8 +16,10 @@
* limitations under the License.
*
*/
const isCi = require('is-ci')
const isDocker = require('is-docker')
import * as os from 'os'
// const isCi = require('is-ci')
// const isDocker = require('is-docker')
import { log } from 'brolog'
......@@ -78,7 +80,7 @@ export interface ConfigSetting {
puppetInstance(instance: Puppet): void
puppetInstance(instance?: Puppet | null): Puppet | void
isDocker: boolean
dockerMode: boolean
}
/* tslint:disable:variable-name */
......@@ -89,9 +91,9 @@ export const Config: ConfigSetting = require('../package.json').wechaty
* 1. ENVIRONMENT VARIABLES + PACKAGES.JSON (default)
*/
Object.assign(Config, {
apihost: process.env['WECHATY_APIHOST'] || Config.DEFAULT_APIHOST,
head: process.env['WECHATY_HEAD'] || Config.DEFAULT_HEAD,
puppet: process.env['WECHATY_PUPPET'] || Config.DEFAULT_PUPPET,
apihost: process.env['WECHATY_APIHOST'] || Config.DEFAULT_APIHOST,
puppet: process.env['WECHATY_PUPPET'] || Config.DEFAULT_PUPPET,
validApiHost,
})
......@@ -125,7 +127,7 @@ Object.assign(Config, {
* 4. Envioronment Identify
*/
Object.assign(Config, {
isDocker: isWechatyDocker(),
dockerMode: !!process.env('WECHATY_DOCKER'),
isGlobal: isWechatyInstalledGlobal(),
})
......@@ -139,29 +141,32 @@ function isWechatyInstalledGlobal() {
return false
}
function isWechatyDocker() {
/**
* @DEPRECATED on Jun 2017 by zixia
*/
// function dockerMode() {
/**
* false for Continuous Integration System
*/
if (isCi) {
return false
}
// if (isCi) {
// return false
// }
/**
* 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 c9 = Object.keys(process.env)
// .filter(k => /^C9_/.test(k))
// .length
// if (c9 > 7 && process.env['C9_PORT']) {
// return false
// }
/**
* return indentify result by NPM module `is-docker`
*/
return isDocker()
}
// return isDocker()
// }
/**
* 5. live setting
......@@ -232,8 +237,20 @@ export interface Sleepable {
}
import * as Raven from 'raven'
Raven.disableConsoleAlerts()
Raven
.config('https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672')
.config(
process.env.NODE_ENV === 'production'
&& 'https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672',
{
release: require('../package.json').version,
tags: {
git_commit: 'c0deb10c4',
platform: os.platform(),
},
},
)
.install()
/*
......
......@@ -113,7 +113,7 @@ export class BrowserDriver {
'--no-sandbox',
], // issue #26 for run inside docker
}
if (Config.isDocker) {
if (Config.dockerMode) {
log.verbose('PuppetWebBrowserDriver', 'getChromeDriver() wechaty in docker confirmed(should not show this in CI)')
options['binary'] = Config.CMD_CHROMIUM
} else {
......
......@@ -25,10 +25,10 @@ import * as fs from 'fs'
import Config from '../src/config'
/**
* need keep this !Config.isDocker because ava need at least one test() inside.
* need keep this !Config.dockerMode because ava need at least one test() inside.
* × No tests found in test\docker.spec.js
*/
if (Config.isDocker) {
if (Config.dockerMode) {
test('Docker smoke testing', function(t) {
// const n = execSync('ps a | grep Xvfb | grep -v grep | wc -l').toString().replace(/\n/, '', 'g')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册