mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-11 02:49:16 +00:00
run sample project with push of a button
This commit is contained in:
parent
bb6df14995
commit
5a51b4b171
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
test/workspace
|
test/workspace
|
||||||
static/js/libs
|
static/js/libs
|
||||||
|
projects/**/workspace
|
||||||
|
15
app.js
15
app.js
@ -5,7 +5,7 @@ var nodeStatic = require('node-static');
|
|||||||
var jade = require('jade');
|
var jade = require('jade');
|
||||||
|
|
||||||
var staticServer = new nodeStatic.Server('./static');
|
var staticServer = new nodeStatic.Server('./static');
|
||||||
var app = http.createServer(function(req, res, next) {
|
var server = http.createServer(function(req, res, next) {
|
||||||
// serve index for all app pages
|
// serve index for all app pages
|
||||||
if (req.url.indexOf('/data.io.js') === -1) {
|
if (req.url.indexOf('/data.io.js') === -1) {
|
||||||
if (req.url.indexOf('/js') === -1) {
|
if (req.url.indexOf('/js') === -1) {
|
||||||
@ -19,9 +19,14 @@ var app = http.createServer(function(req, res, next) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var io = require('socket.io')(app);
|
var socketio = require('socket.io')(server);
|
||||||
var data = require('data.io')(io);
|
var dataio = require('data.io')(socketio);
|
||||||
|
|
||||||
require('./resources')(data);
|
var app = {
|
||||||
|
server: server,
|
||||||
|
dataio: dataio
|
||||||
|
};
|
||||||
|
|
||||||
app.listen(3000);
|
require('./resources')(app);
|
||||||
|
|
||||||
|
app.server.listen(3000);
|
||||||
|
@ -14,8 +14,8 @@ function Distributor(params) {
|
|||||||
// queued projects to build
|
// queued projects to build
|
||||||
self.queue = [];
|
self.queue = [];
|
||||||
|
|
||||||
self.onBuildUpdate = params.onBuildUpdate || function(err, build) {
|
self.onBuildUpdate = params.onBuildUpdate || function(build, callback) {
|
||||||
callback(err, build);
|
callback(null, build);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,11 +53,14 @@ Executor.prototype._getSources = function(params, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Executor.prototype._runStep = function(params, callback) {
|
Executor.prototype._runStep = function(params, callback) {
|
||||||
|
var self = this;
|
||||||
Steppy(
|
Steppy(
|
||||||
function() {
|
function() {
|
||||||
if (params.type !== 'shell') {
|
if (params.type !== 'shell') {
|
||||||
throw new Error('Unknown step type: ' + params.type);
|
throw new Error('Unknown step type: ' + params.type);
|
||||||
}
|
}
|
||||||
|
// set command cwd to executor cwd
|
||||||
|
params.cwd = self.cwd;
|
||||||
var command = createCommand(params);
|
var command = createCommand(params);
|
||||||
command.run(params, this.slot())
|
command.run(params, this.slot())
|
||||||
},
|
},
|
||||||
|
@ -35,6 +35,7 @@ exports.load = function(baseDir, name, callback) {
|
|||||||
exports.validateConfig(config, this.slot());
|
exports.validateConfig(config, this.slot());
|
||||||
},
|
},
|
||||||
function(err, config) {
|
function(err, config) {
|
||||||
|
config.dir = dir;
|
||||||
this.pass(new Project(config));
|
this.pass(new Project(config));
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function(data) {
|
module.exports = function(app) {
|
||||||
var builds = [{
|
var builds = [{
|
||||||
project: {
|
project: {
|
||||||
name: 'foo'
|
name: 'foo'
|
||||||
@ -11,7 +11,7 @@ module.exports = function(data) {
|
|||||||
status: 'inprogress'
|
status: 'inprogress'
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var resource = data.resource('builds');
|
var resource = app.dataio.resource('builds');
|
||||||
|
|
||||||
resource.use('readAll', function(req, res) {
|
resource.use('readAll', function(req, res) {
|
||||||
console.log('readAll');
|
console.log('readAll');
|
||||||
|
@ -1,24 +1,41 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('underscore'),
|
var _ = require('underscore'),
|
||||||
project = require('../lib/project');
|
project = require('../lib/project'),
|
||||||
|
Distributor = require('../lib/distributor').Distributor;
|
||||||
|
|
||||||
var projects,
|
var distributor = new Distributor({
|
||||||
projectConfigs;
|
nodes: [{type: 'local', maxExecutorsCount: 1}]
|
||||||
|
});
|
||||||
|
|
||||||
|
var projects, projectsHash;
|
||||||
|
|
||||||
project.loadAll('projects', function(err, loadedProjects) {
|
project.loadAll('projects', function(err, loadedProjects) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
projects = loadedProjects;
|
projects = loadedProjects;
|
||||||
|
projectsHash = _(projects).indexBy(function(project) {
|
||||||
|
return project.config.name;
|
||||||
|
});
|
||||||
console.log(
|
console.log(
|
||||||
'Loaded projects: ',
|
'Loaded projects: ',
|
||||||
_(projects).chain().pluck('config').pluck('name').value()
|
_(projects).chain().pluck('config').pluck('name').value()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = function(data) {
|
module.exports = function(app) {
|
||||||
var resource = data.resource('projects');
|
var resource = app.dataio.resource('projects');
|
||||||
|
|
||||||
resource.use('read', function(req, res) {
|
resource.use('read', function(req, res) {
|
||||||
res.send(_(projects).pluck('config'));
|
res.send(_(projects).pluck('config'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
resource.use('run', function(req, res) {
|
||||||
|
var projectName = req.data.projectName,
|
||||||
|
project = projectsHash[projectName];
|
||||||
|
console.log('Run the project: %j', project || projectName);
|
||||||
|
distributor.run(project.config, {}, function(err, build) {
|
||||||
|
console.log('>>> err, build = ', err && err.stack || err, build)
|
||||||
|
res.send({err: err, build: build});
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@ -8,10 +8,22 @@ define([
|
|||||||
var connect = dataio(socketio.connect());
|
var connect = dataio(socketio.connect());
|
||||||
|
|
||||||
var projects = connect.resource('projects');
|
var projects = connect.resource('projects');
|
||||||
|
|
||||||
|
var projectsTemplate = _($('#projects-template').html()).template();
|
||||||
|
$('#content').on('click', '.js-projects .js-run', function() {
|
||||||
|
var projectName = $(this).parent('.js-project').data('name');
|
||||||
|
projects.sync('run', {projectName: projectName}, function(err, result) {
|
||||||
|
$('#content').append(
|
||||||
|
(err && err.message) ||
|
||||||
|
JSON.stringify(result)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
projects.sync('read', function(err, projects) {
|
projects.sync('read', function(err, projects) {
|
||||||
$('#content').html(
|
$('#content').html(
|
||||||
(err && err.message) ||
|
(err && err.message) ||
|
||||||
('Loaded projects: ' + _(projects).pluck('name').join(', '))
|
projectsTemplate({projects: projects})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -9,4 +9,16 @@ html
|
|||||||
body
|
body
|
||||||
h1 hello world
|
h1 hello world
|
||||||
|
|
||||||
|
|
||||||
|
script#projects-template(type="text/template")
|
||||||
|
| <div class="js-projects">
|
||||||
|
| <% _(projects).each(function(project) { %>
|
||||||
|
| <div class="js-project" data-name="<%= project.name %>">
|
||||||
|
| <span><%= project.name %></span>
|
||||||
|
| <span class="js-run">→</span>
|
||||||
|
| </div>
|
||||||
|
| <% }); %>
|
||||||
|
| </div>
|
||||||
|
|
||||||
|
|
||||||
#content
|
#content
|
||||||
|
Loading…
Reference in New Issue
Block a user