add server config

This commit is contained in:
oleg 2015-05-18 21:25:08 +03:00
parent 7b2fe328a7
commit bf97e2c7c5
4 changed files with 43 additions and 13 deletions

46
app.js
View File

@ -4,7 +4,10 @@ var http = require('http'),
nodeStatic = require('node-static'),
jade = require('jade'),
path = require('path'),
fs = require('fs');
fs = require('fs'),
Steppy = require('twostep').Steppy,
_ = require('underscore'),
reader = require('./lib/reader');
var staticServer = new nodeStatic.Server('./static');
var server = http.createServer(function(req, res, next) {
@ -29,17 +32,38 @@ var app = {
dataio: dataio
};
app.config = {};
app.config.paths = {};
// path to root dir (with projects, builds etc)
app.config.paths.data = path.join(process.cwd(), 'data');
app.config.paths.projects = path.join(app.config.paths.data, 'projects');
app.config.paths.builds = path.join(app.config.paths.data, 'builds');
fs.exists(app.config.paths.builds, function(exists) {
if (!exists) fs.mkdir(app.config.paths.builds);
});
Steppy(
function() {
app.config = {};
app.config.paths = {};
require('./resources')(app);
// path to root dir (with projects, builds etc)
app.config.paths.data = path.join(process.cwd(), 'data');
app.config.paths.projects = path.join(app.config.paths.data, 'projects');
app.config.paths.builds = path.join(app.config.paths.data, 'builds');
var stepCallback = this.slot();
fs.exists(app.config.paths.builds, function(isExists) {
stepCallback(null, isExists);
});
reader.load(app.config.paths.data, 'config', this.slot());
},
function(err, isBuildsDirExists, config) {
if (!isBuildsDirExists) {
fs.mkdir(app.config.paths.builds, this.slot());
}
_(app.config).defaults(config);
console.log('Server config:', JSON.stringify(app.config.nodes, null, 4));
require('./resources')(app);
},
function(err) {
if (err) throw err;
}
);
app.server.listen(3000);

6
data/config.json Normal file
View File

@ -0,0 +1,6 @@
{
"nodes": [{
"type": "local",
"maxExecutorsCount": 1
}]
}

View File

@ -30,7 +30,7 @@ gulp.task('develop', function() {
return nodemon({
ignore: ['static/**/*.js', 'app/**/*.js', 'node_modules/**'],
script: 'app.js',
ext: 'js'
ext: 'js,json'
});
});

View File

@ -27,7 +27,7 @@ module.exports = function(app) {
});
var distributor = new Distributor({
nodes: [{type: 'local', maxExecutorsCount: 1}],
nodes: app.config.nodes,
saveBuild: function(build, callback) {
Steppy(
function() {