...
|
...
|
@@ -4,13 +4,15 @@ import Router from 'koa-router'; |
|
|
import moment from 'moment';
|
|
|
import Build from '../../ci/build';
|
|
|
import Deploy from '../../ci/deploy';
|
|
|
import Restart from '../../ci/restart';
|
|
|
import Operation from '../../logger/operation';
|
|
|
|
|
|
import {
|
|
|
Building,
|
|
|
Project,
|
|
|
Server,
|
|
|
DeployInfo
|
|
|
DeployInfo,
|
|
|
RestartInfo
|
|
|
} from '../../models';
|
|
|
|
|
|
let r = new Router();
|
...
|
...
|
@@ -132,10 +134,16 @@ const p = { |
|
|
}, {
|
|
|
$set: project
|
|
|
});
|
|
|
await Operation.action(ctx.session.user, 'EDIT_PROJECT_INFO', '修改项目信息', {_id: id, name: project.name});
|
|
|
await Operation.action(ctx.session.user, 'EDIT_PROJECT_INFO', '修改项目信息', {
|
|
|
_id: id,
|
|
|
name: project.name
|
|
|
});
|
|
|
} else {
|
|
|
await Project.insert(project);
|
|
|
await Operation.action(ctx.session.user, 'NEW_PROJECT_INFO', '新增项目信息', {_id: id, name: project.name});
|
|
|
await Operation.action(ctx.session.user, 'NEW_PROJECT_INFO', '新增项目信息', {
|
|
|
_id: id,
|
|
|
name: project.name
|
|
|
});
|
|
|
}
|
|
|
ctx.redirect('/projects');
|
|
|
ctx.status = 301;
|
...
|
...
|
@@ -183,7 +191,12 @@ const p = { |
|
|
|
|
|
build.run(id);
|
|
|
|
|
|
await Operation.action(ctx.session.user, 'NEW_PROJECT_BUILDING', '新增项目构建', {_id: id, project: p.name, branch: branch, env: env});
|
|
|
await Operation.action(ctx.session.user, 'NEW_PROJECT_BUILDING', '新增项目构建', {
|
|
|
_id: id,
|
|
|
project: p.name,
|
|
|
branch: branch,
|
|
|
env: env
|
|
|
});
|
|
|
|
|
|
ctx.body = {
|
|
|
code: 200,
|
...
|
...
|
@@ -225,7 +238,12 @@ const p = { |
|
|
}
|
|
|
});
|
|
|
|
|
|
await Operation.action(ctx.session.user, 'PROJECT_DEPLOY', '项目分发部署', {_id: buildingId, project: project.name, branch: building.branch, env: building.env});
|
|
|
await Operation.action(ctx.session.user, 'PROJECT_DEPLOY', '项目分发部署', {
|
|
|
_id: buildingId,
|
|
|
project: project.name,
|
|
|
branch: building.branch,
|
|
|
env: building.env
|
|
|
});
|
|
|
|
|
|
ctx.body = {
|
|
|
code: 200,
|
...
|
...
|
@@ -237,6 +255,67 @@ const p = { |
|
|
msg: '该版本未构建成功,暂不能分发'
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
project_restart: async(ctx) => {
|
|
|
const projectId = ctx.request.body.id;
|
|
|
const host = ctx.request.body.host;
|
|
|
const env = ctx.request.body.env;
|
|
|
const project = await Project.findById(projectId);
|
|
|
|
|
|
if (!project) {
|
|
|
ctx.body = {
|
|
|
code: 201,
|
|
|
msg: '该项目不存在'
|
|
|
};
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let hosts = [];
|
|
|
if (host === 'all') {
|
|
|
// 全部重启
|
|
|
hosts = project.deploy[env].target;
|
|
|
} else {
|
|
|
// 单台重启
|
|
|
hosts.push(host);
|
|
|
}
|
|
|
|
|
|
hosts.forEach(async(host) => {
|
|
|
let doc = await DeployInfo.findOne({
|
|
|
projectId: projectId,
|
|
|
host: host,
|
|
|
env: env
|
|
|
});
|
|
|
|
|
|
if (!doc) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let info = {
|
|
|
projectId: projectId,
|
|
|
host: host,
|
|
|
env: env,
|
|
|
createdAt: new Date(),
|
|
|
updatedAt: new Date(),
|
|
|
state: 'waiting'
|
|
|
};
|
|
|
|
|
|
let restartDoc = await RestartInfo.insert(info);
|
|
|
let restart = new Restart(project);
|
|
|
|
|
|
info._id = restartDoc[0]._id;
|
|
|
restart.restart(info);
|
|
|
|
|
|
await Operation.action(ctx.session.user, 'PROJECT_RESTART', '项目重启', {
|
|
|
_id: info._id,
|
|
|
project: project.name,
|
|
|
branch: project.deploy[env].branchName,
|
|
|
env: env
|
|
|
});
|
|
|
});
|
|
|
|
|
|
ctx.body = {
|
|
|
code: 200
|
|
|
};
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -248,4 +327,5 @@ r.get('/:id/buildings', p.buildings_table); |
|
|
r.post('/save', p.save);
|
|
|
r.post('/build/:pid', p.project_build);
|
|
|
r.post('/deploy/:building', p.project_deploy);
|
|
|
r.post('/restart', p.project_restart);
|
|
|
export default r; |
|
|
\ No newline at end of file |
...
|
...
|
|