Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
fb00a88d
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 大约 3 年
通知
304
Star
10499
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
152
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
152
Issue
152
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fb00a88d
编写于
6月 15, 2017
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean(code): identify Docker environment by ENV variable. (#84)
上级
b146572b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
46 addition
and
27 deletion
+46
-27
bin/doctor.ts
bin/doctor.ts
+1
-1
bin/entrypoint.sh
bin/entrypoint.sh
+2
-0
src/config.spec.ts
src/config.spec.ts
+4
-4
src/config.ts
src/config.ts
+36
-19
src/puppet-web/browser-driver.ts
src/puppet-web/browser-driver.ts
+1
-1
test/docker.spec.ts
test/docker.spec.ts
+2
-2
未找到文件。
bin/doctor.ts
浏览文件 @
fb00a88d
...
...
@@ -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
}
...
...
bin/entrypoint.sh
浏览文件 @
fb00a88d
...
...
@@ -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 "
...
...
src/config.spec.ts
浏览文件 @
fb00a88d
...
...
@@ -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
}
...
...
src/config.ts
浏览文件 @
fb00a88d
...
...
@@ -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
()
/*
...
...
src/puppet-web/browser-driver.ts
浏览文件 @
fb00a88d
...
...
@@ -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
{
...
...
test/docker.spec.ts
浏览文件 @
fb00a88d
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录