Toggle navigation
Toggle navigation
This project
Loading...
Sign in
OPENTECH
/
yoho-node-ci
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
2
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
姜枫
8 years ago
Commit
b5a918aa3ac8a9231dea5d4ccc838fd3582be370
1 parent
b4412a1d
support node 7.0 & add zip check
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
80 additions
and
35 deletions
app.js
apps/ci/build.js
apps/ci/deploy.js
apps/ci/deploy_pool.js
apps/ci/tar.js
apps/logger/influxdb.js
apps/logger/operation.js
apps/models/building.js
apps/models/index.js
apps/models/product_cache.js
apps/models/project.js
apps/web/actions/projects.js
apps/web/index.js
apps/web/routers.js
middleware/error-handle.js
app.js
View file @
b5a918a
...
...
@@ -41,23 +41,6 @@ app.use(convert(body({
})));
app
.
use
(
mount
(
'/'
,
webApp
));
// app.on('error', function(err, ctx) {
// console.log(err);
// switch (ctx.accepts('json', 'html', 'text')) {
// case 'json':
// ctx.body = {
// code: 400
// };
//
// break;
// case 'html':
// console.log(ctx);
// ctx.redirect('/500');
// break;
// default:
// break;
// }
// });
server
.
listen
(
port
,
()
=>
{
console
.
log
(
`
app
started
in
$
{
port
}
`
);
...
...
apps/ci/build.js
View file @
b5a918a
...
...
@@ -49,7 +49,8 @@ class Build {
}).
then
(()
=>
{
return
self
.
_ignoreFile
();
}).
then
(()
=>
{
self
.
_zipBuild
();
return
self
.
_zipBuild
();
}).
then
(()
=>
{
self
.
_state
(
'success'
);
let
diff
=
(
new
Date
()).
getTime
()
-
self
.
startTime
;
let
costTime
=
moment
.
duration
(
diff
,
'ms'
).
humanize
();
...
...
@@ -185,7 +186,9 @@ class Build {
this
.
_state
(
'gziping'
);
let
target
=
this
.
buildPath
;
let
dist
=
path
.
join
(
this
.
rootPath
,
`
$
{
this
.
project
.
name
}.
tar
.
gz
`
);
return
Tar
.
gzip
(
target
,
dist
);
return
Tar
.
gzip
(
target
,
dist
).
then
(
filecode
=>
{
Building
.
updateMd5
(
this
.
bid
,
filecode
);
});
}
async
_state
(
state
)
{
...
...
apps/ci/deploy.js
View file @
b5a918a
...
...
@@ -91,6 +91,7 @@ class Deploy {
try
{
await
self
.
_preDeploy
(
conn
);
await
self
.
_scp
(
conn
);
await
self
.
_zipCheck
(
conn
);
await
self
.
_unzip
(
conn
);
await
self
.
_startup
(
conn
);
self
.
callback
(
null
,
null
);
...
...
@@ -133,18 +134,21 @@ class Deploy {
return
new
Promise
((
resolve
,
reject
)
=>
{
self
.
_state
(
'uploading'
);
self
.
_log
(
`
>>>>
uploading
$
{
self
.
localFile
}
==>
$
{
self
.
remoteFile
}
`
);
let
t1
=
new
Date
();
conn
.
sftp
((
err
,
sftp
)
=>
{
if
(
err
)
{
reject
(
err
);
}
else
{
sftp
.
fastPut
(
self
.
localFile
,
self
.
remoteFile
,
{
chunkSize
:
10240
//
chunkSize: 10240
},
(
err
)
=>
{
if
(
err
)
{
reject
(
err
);
}
else
{
self
.
_log
(
' uploaded success!'
);
let
t2
=
new
Date
();
self
.
_log
(
' uploaded success!'
);
self
.
_state
(
'uploaded'
);
console
.
log
(
`
upload
package
in
[
$
{
t2
.
getTime
()
-
t1
.
getTime
()}]
ms
`
)
resolve
();
}
});
...
...
@@ -153,6 +157,38 @@ class Deploy {
});
}
_zipCheck
(
conn
)
{
let
self
=
this
;
return
new
Promise
((
resolve
,
reject
)
=>
{
self
.
_state
(
'checking'
);
let
check
=
`
md5sum
$
{
self
.
remoteFile
}
`
;
conn
.
exec
(
check
,
(
err
,
stream
)
=>
{
if
(
err
)
{
reject
(
err
);
}
else
{
let
d
=
''
;
stream
.
on
(
'data'
,
(
data
)
=>
{
console
.
log
(
data
.
toString
());
d
+=
data
.
toString
();
});
stream
.
on
(
'exit'
,
(
code
)
=>
{
if
(
code
===
0
)
{
self
.
_state
(
'checked'
);
if
(
d
.
indexOf
(
self
.
building
.
md5
)
>=
0
)
{
resolve
();
}
else
{
reject
(
'check md5 fail: '
+
d
+
' except: '
+
self
.
building
.
md5
);
}
}
else
{
reject
(
'check fail: '
+
script
);
}
});
}
});
});
}
_unzip
(
conn
)
{
let
self
=
this
;
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
apps/ci/deploy_pool.js
View file @
b5a918a
...
...
@@ -12,7 +12,9 @@ class DeployPool {
deploy
(
de
)
{
de
.
error
=
0
;
this
.
pool
.
push
(
de
);
this
.
run
();
setTimeout
(()
=>
{
this
.
run
();
},
1
);
}
async
run
()
{
...
...
@@ -38,9 +40,6 @@ class DeployPool {
this
.
running
.
set
(
id
,
de
);
}
}
console
.
log
(
'deploy pool size = '
+
this
.
pool
.
length
);
console
.
log
(
'deploy running keys = '
+
this
.
running
.
size
);
}
stop
()
{
...
...
apps/ci/tar.js
View file @
b5a918a
...
...
@@ -12,6 +12,7 @@ const tar = require('tar');
const
fstream
=
require
(
'fstream'
);
const
fsp
=
require
(
'fs-promise'
);
const
fs
=
require
(
'fs'
);
const
md5File
=
require
(
'md5-file'
);
class
Tar
{
...
...
@@ -32,13 +33,22 @@ class Tar {
return
new
Promise
((
reslove
,
reject
)
=>
{
try
{
let
packer
=
tar
.
Pack
();
let
wirte
=
fstream
.
Writer
({
'path'
:
`
$
{
dist
}
`
}).
on
(
'close'
,
()
=>
{
let
filecode
=
md5File
.
sync
(
dist
);
console
.
log
(
filecode
);
reslove
(
filecode
);
});
fstream
.
Reader
(
readCfg
)
/* Read the source directory */
.
pipe
(
tar
.
Pack
()
)
/* Convert the directory to a .tar file */
.
pipe
(
packer
)
/* Convert the directory to a .tar file */
.
pipe
(
zlib
.
Gzip
())
/* Compress the .tar file */
.
pipe
(
fstream
.
Writer
({
'path'
:
`
$
{
dist
}
`
}));
reslove
();
.
pipe
(
wirte
);
}
catch
(
e
)
{
reject
(
e
);
}
...
...
apps/logger/influxdb.js
View file @
b5a918a
...
...
@@ -3,7 +3,7 @@
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 2016/7/29
*/
'use strict'
;
const
influx
=
require
(
'influx'
);
let
client
=
influx
({
...
...
apps/logger/operation.js
View file @
b5a918a
...
...
@@ -3,7 +3,7 @@
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 2016/8/22
*/
'use strict'
;
const
{
OperationLogger
}
=
require
(
'../models'
);
const
OperationLog
=
{
...
...
apps/models/building.js
View file @
b5a918a
...
...
@@ -18,6 +18,15 @@ class Building extends Model {
}
});
}
async
updateMd5
(
id
,
md5
)
{
await
this
.
update
({
_id
:
id
},
{
$set
:
{
md5
:
md5
,
updatedAt
:
new
Date
()
}
});
}
}
module
.
exports
=
Building
;
\ No newline at end of file
...
...
apps/models/index.js
View file @
b5a918a
'use strict'
;
const
shelljs
=
require
(
'shelljs'
);
const
config
=
require
(
'../../config/config'
);
...
...
apps/models/product_cache.js
View file @
b5a918a
...
...
@@ -3,7 +3,7 @@
* @author: chenfeng<feng.chen@yoho.cn>
* @date: 16/10/20
*/
'use strict'
;
const
Model
=
require
(
'./model'
);
const
rp
=
require
(
'request-promise'
);
const
ws
=
require
(
'../../lib/ws'
);
...
...
apps/models/project.js
View file @
b5a918a
'use strict'
;
const
Model
=
require
(
'./model'
);
class
Project
extends
Model
{
...
...
apps/web/actions/projects.js
View file @
b5a918a
...
...
@@ -219,6 +219,7 @@ const p = {
env
:
env
,
distFile
:
distFile
,
state
:
'waiting'
,
md5
:
''
,
createdAt
:
new
Date
(),
updatedAt
:
new
Date
()
});
...
...
apps/web/index.js
View file @
b5a918a
...
...
@@ -3,7 +3,7 @@
*
* @author: jiang
*/
'use strict'
;
const
path
=
require
(
'path'
);
const
Koa
=
require
(
'koa'
);
...
...
apps/web/routers.js
View file @
b5a918a
'use strict'
;
const
Router
=
require
(
'koa-router'
);
const
common
=
require
(
'./actions/common'
);
...
...
middleware/error-handle.js
View file @
b5a918a
...
...
@@ -3,7 +3,7 @@
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/8/3
*/
'use strict'
;
async
function
errorHandle
(
err
,
ctx
)
{
let
code
=
err
?
500
:
ctx
.
response
.
status
;
let
message
=
err
?
err
.
toString
()
:
ctx
.
response
.
message
;
...
...
Please
register
or
login
to post a comment