Authored by 姜枫

change log type

... ... @@ -9,6 +9,7 @@ import sh from 'shelljs';
import moment from 'moment';
import path from 'path';
import fsp from 'fs-promise';
import fs from 'fs';
import config from '../../config/config';
import Tar from './tar';
import ws from '../../lib/ws';
... ... @@ -76,6 +77,8 @@ class Build {
if (!sh.test('-e', this.rootPath)) {
sh.mkdir('-p', this.rootPath);
}
this.logFile = path.join(this.rootPath, 'building.log');
sh.touch(this.logFile);
}
_cloneCode(branch) {
... ... @@ -91,13 +94,17 @@ class Build {
async: true
});
child.stdout.on('data', (data) => {
self._log(data);
});
child.stdout.pipe(fs.createWriteStream(self.logFile, {
flags: 'a'
}));
child.stderr.on('data', (data) => {
self._log(data);
});
child.stderr.pipe(fs.createWriteStream(self.logFile, {
flags: 'a'
}));
// child.stderr.on('data', (data) => {
// self._log(data);
// });
child.on('close', (code) => {
if (code == 0) {
... ... @@ -121,13 +128,19 @@ class Build {
async: true
});
child.stdout.on('data', (data) => {
self._log(data);
});
// child.stdout.on('data', (data) => {
// self._log(data);
// });
child.stderr.on('data', (data) => {
self._log(data);
});
// child.stderr.on('data', (data) => {
// self._log(data);
// });
child.stdout.pipe(fs.createWriteStream(self.logFile, {
flags: 'a'
}));
child.stderr.pipe(fs.createWriteStream(self.logFile, {
flags: 'a'
}));
child.on('close', (code) => {
if (code == 0) {
... ... @@ -157,7 +170,8 @@ class Build {
}
_log(line) {
ws.broadcast(`/building/${this.project._id}/log`, line);
// ws.broadcast(`/building/${this.project._id}/log`, line);
fsp.appendFile(this.logFile, line + '\n');
}
}
... ...
... ... @@ -134,7 +134,7 @@ class Deploy {
self._state('unziped');
reslove();
} else {
reject('unzip fail');
reject('unzip fail: ' + script);
}
});
}
... ... @@ -143,7 +143,7 @@ class Deploy {
}
_startup(conn) {
let self =this;
let self = this;
let startup = this.project.scripts.start;
return new Promise((reslove, reject) => {
self._state('starting');
... ... @@ -172,7 +172,7 @@ class Deploy {
});
}
async _state(state){
async _state(state) {
ws.broadcast(`/deploy/${this.project._id}`, {
host: this.info.host,
state: state
... ... @@ -204,7 +204,7 @@ class Deploy {
}
get localFile() {
return path.join(config.buildDir, this.building.distFile);
return path.join(config.buildDir, this.building.distFile);
}
}
... ...
... ... @@ -45,7 +45,7 @@ const p = {
deploy.name = envs[env];
let targets = [];
deploy.target.forEach(async (host) => {
deploy.target.forEach(async(host) => {
let info = await DeployInfo.findOne({
projectId: project._id,
host: host,
... ... @@ -53,6 +53,7 @@ const p = {
});
targets.push({
host: host,
hostFm: host.replace(/\./g, '-'),
info: info
})
});
... ... @@ -144,7 +145,10 @@ const p = {
let p = await Project.findById(pid);
let build = new Build(p);
let { buildTime, distFile } = build.build(env);
let {
buildTime,
distFile
} = build.build(env);
let buildingDoc = await Building.insert({
buildTime: buildTime,
project: p.name,
... ... @@ -177,7 +181,7 @@ const p = {
let project = await Project.findByName(building.project);
let targets = project.deploy[building.env].target;
targets.forEach(async (host) => {
targets.forEach(async(host) => {
let info = {
projectId: project._id,
host: host,
... ...
... ... @@ -19,7 +19,7 @@
<div class="panel panel-default" data-env='{{deploy.env}}'>
<div class="panel-heading">
<div class="pull-right">
<a class="btn btn-info btn-rounded mr5 log-btn"><i class="fa fa-eye"></i> 查看实时日志</a>
<a class="btn btn-info btn-rounded mr5 log-btn"><i class="fa fa-eye"></i> 查看构建日志</a>
<a class="btn btn-warning btn-rounded mr5 rollback-btn"><i class="fa fa-reply"></i> 回滚</a>
<a class="btn btn-success btn-rounded mr20 build-btn"><i class="glyphicon glyphicon-plus"></i> 新增构建</a>
<a href="" class="tooltips panel-minimize"><i class="fa fa-minus"></i></a>
... ... @@ -49,7 +49,7 @@
<div class="panel-body">
<div class="row">
{{#each targets}}
<div class="col-md-4" id="d-{{host}}">
<div class="col-md-4" id="d-{{hostFm}}">
<div class="panel panel-info noborder">
<div class="panel-heading noborder">
<div class="panel-btns">
... ... @@ -65,6 +65,9 @@
<h5 class="md-title mt10">当前状态</h5>
<span class="label label-success deploy-log-btn" data-host="{{host}}"><i class="fa fa-spinner fa-spin fa-fw margin-bottom"></i> <b>{{#if info}}{{info.state}}{{^}}未知部署{{/if}}</b></span>
</div>
<div class="col-xs-6">
</div>
</div>
</div><!-- panel-body -->
</div><!-- panel -->
... ... @@ -120,9 +123,11 @@
return '<button '+(disabled? 'disabled' : '')+' class="btn btn-success btn-xs deploy-btn" data-id="'+data+'" data-build='+row.buildTime+'>分发</button>';
},
targets: 3
}],
initComplete: function(){
$('.deploy-btn').click(function(){
}]
});
$(this).on( 'draw.dt', function () {
$('.deploy-btn').click(function(){
var id = $(this).data('id');
var build = $(this).data('build');
layer.confirm('确定发布版本<code>' + build + '</code>吗?', {
... ... @@ -131,8 +136,7 @@
doDeploy(id);
});
});
}
});
} );
});
function doDeploy(build){
... ... @@ -211,21 +215,22 @@
}
});
ws.on('/building/{{project._id}}/log', function(data){
if(tag == '') {
cm.replaceRange("> " + data + "\n", {line: Infinity});
}
});
// ws.on('/building/{{project._id}}/log', function(data){
// if(tag == '') {
// cm.replaceRange("> " + data + "\n", {line: Infinity});
// }
// });
ws.on('/deploy/{{project._id}}', function(data){
$('#d-' + data.host).find('b').text(data.state);
console.log(data);
$('#d-' + data.host.replace(/\./g, '-')).find('b').text(data.state);
});
ws.on('/deploy/{{project._id}}/log', function(data){
if(tag == data.host){
cm.replaceRange("> " +data.msg+ "\n", {line: Infinity});
}
});
// ws.on('/deploy/{{project._id}}/log', function(data){
// if(tag == data.host){
// cm.replaceRange("> " +data.msg+ "\n", {line: Infinity});
// }
// });
});
ws.on('error', function(){
console.log('connect fail');
... ...
'use strict';
import _ from 'lodash';
const helpers = {
equals: (a, b, opts) => {
if (a === b) {
... ... @@ -7,6 +9,9 @@ const helpers = {
} else {
return opts.inverse(this);
}
},
replace: (str, pattern, replacement) => {
return _.replace(str, new RegExp(pattern), replacement);
}
};
... ...
... ... @@ -43,6 +43,7 @@
"koa-mount": "^2.0.0",
"koa-router": "^7.0.1",
"koa-static": "^3.0.0",
"lodash": "^4.13.1",
"moment": "^2.13.0",
"nedb": "^1.8.0",
"nedb-promise": "^2.0.0",
... ...