Skip to content

Commit 884d577

Browse files
committed
Merge pull request #478 from CodeNow/notification-github-hooks-tests
Build and deploy notifications
2 parents ba398da + b6b3c09 commit 884d577

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2748
-630
lines changed

configs/.env

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
LOG_ERRORS=true
22
TOKEN_EXPIRES="1 year"
3+
REDIS_PORT="6379"
34
REDIS_KEY_EXPIRES="5 minutes"
45
REDIS_LOCK_EXPIRES="6 minutes"
56
DOCK_PROJECT_LIMIT=100000000
@@ -13,7 +14,7 @@ ROLLBAR_OPTIONS_BRANCH="master"
1314
PRIMUS_TRANSFORMER="websockets"
1415
CONTAINER_STOP_LIMIT=10
1516
GITHUB_HOOK_NAME="web"
16-
GITHUB_DEPLOY_KEYS_POOL_SIZE=100
17+
GITHUB_DEPLOY_KEYS_POOL_SIZE=10
1718
GITHUB_DEPLOY_KEY_BITS=2048
1819
HASHIDS_SALT="VvCCYj8x3xaHs44QiDp9"
1920
HASHIDS_LENGTH=6
@@ -33,3 +34,12 @@ CAYLEY="http://localhost:64210"
3334
REDIS_NAMESPACE="runnable:api:"
3435
DNS_JOB_QUEUE_INTERVAL=200
3536
DNS_JOB_QUEUE_INTERVAL_DELETE=60000
37+
SLACK_BOT_IMAGE="https://avatars0.githubusercontent.com/u/2828361?v=3&s=200"
38+
SLACK_BOT_USERNAME="runnabot"
39+
HIPCHAT_BOT_USERNAME="runnabot"
40+
ENABLE_BUILDS_ON_GIT_PUSH=false
41+
ENABLE_NOTIFICATIONS_ON_GIT_PUSH=false
42+
POLL_MONGO_TIMEOUT="30 minutes"
43+
GITHUB_SCOPE="user:email,repo,repo_deployment,read:repo_hook"
44+
GITHUB_HOOK_SECRET="3V3RYTHINGisAW3S0ME!"
45+
DOCKER_IMAGE_BUILDER_CACHE="/git-cache"

configs/.env.production

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ ROUTE53_HOSTEDZONEID="Z1GZKKG3L9D7DJ"
2828
DNS_IPADDRESS=205.251.193.198
2929
CAYLEY="http://cayley.runnable.io"
3030
DOCKER_IMAGE_BUILDER_CACHE="/git-cache"
31+
ENABLE_BUILDS_ON_GIT_PUSH=true
32+
ENABLE_NOTIFICATIONS_ON_GIT_PUSH=true
33+
GITHUB_DEPLOY_KEYS_POOL_SIZE=100

configs/.env.staging

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
CAYLEY=http://stage-cayley.codenow.runnable.io:64210
2+
MONGO=mongodb://stage-mongo.codenow.runnable.io/alpha
3+
REDIS_IPADDRESS=stage-redis.codenow.runnable.io
4+
NODE_ENV=development
5+
PORT=80
6+
DOMAIN="runnable3.net"
7+
REGISTRY_DOMAIN="registry.runnable3.net"
8+
FULL_API_DOMAIN="http://api.runnable3.net"
9+
KRAIN_PORT=3100
10+
FILIBUSTER_PORT=3112
11+
DNS_IPADDRESS=205.251.194.47
12+
MAVIS_HOST=http://stage-mavis.codenow.runnable.io
13+
14+
DOMAIN=runnable3.net
15+
FULL_API_DOMAIN=http://api.runnable3.net
16+
17+
ROUTE53_HOSTEDZONEID=Z2L43851D1QVP0
18+
REGISTRY_DOMAIN=registry.runnable.com
19+
MONGO_DB=http://stage-mongo.codenow.runnable.io
20+
REDIS_DB=http://stage-redis.codenow.runnable.io
21+
CAYLEY_DB=http://stage-cayley.codenow.runnable.io
22+
DATADOG_HOST=stage-datadog.codenow.runnable.io
23+
24+
S3_CONTEXT_RESOURCE_BUCKET="runnable.context.resources.development"
25+
AWS_ACCESS_KEY_ID="AKIAIG7Y3M347VWVGNUQ"
26+
AWS_SECRET_ACCESS_KEY="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"
27+
28+
GITHUB_CALLBACK_URL="http://api.runnable3.net/auth/github/callback"
29+
GITHUB_HOOK_URL="http://api.runnable3.net/actions/github"
30+
GITHUB_DEPLOY_KEY_TITLE="Runnable-staging"
31+
GITHUB_DEPLOY_KEYS_BUCKET="runnable.deploykeys.development"
32+
GITHUB_CLIENT_ID=1b29938c7fb7f7de03cb
33+
GITHUB_CLIENT_SECRET=e50fc29af5017c4bdee4b70a8816b07dc9431bce
34+
GITHUB_CALLBACK_URL=http://api.runnable3.net/auth/github/callback
35+
GITHUB_HOOK_URL=http://api.runnable3.net/actions/github

lib/express-app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ app.use(require('./routes/contexts/versions/app-code-versions'));
5252
app.use(require('./routes/instances'));
5353
app.use(require('./routes/instances/containers'));
5454
app.use(require('./routes/instances/containers/files'));
55+
app.use(require('./routes/settings'));
5556
/* ERRORS */
5657
app.use(error.mongooseErrorCaster);
5758
app.use(error.errorCaster);

lib/loadenv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ function convertStringToNumeral(key, val) {
4040
} else {
4141
return val;
4242
}
43-
}
43+
}

lib/middlewares/cors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var envIs = require('101/env-is');
55
module.exports = cors({
66
methods: 'GET,PUT,POST,PATCH,DELETE,DEL',
77
origin: function (origin, callback) {
8-
var allow = envIs('development', 'test', 'io', 'local') ?
8+
var allow = envIs('development', 'test', 'io', 'local', 'staging') ?
99
true :
1010
(origin === 'http://'+process.env.DOMAIN);
1111
callback(null, allow);

lib/middlewares/create-class-middleware.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function ClassMiddleware (key, Model) {
5252
model[method].apply(model, args);
5353
};
5454
};
55+
self.model[method].name = Model.name+'.model.'+method;
5556
}
5657
function createStaticMiddleware (method) {
5758
self[method] = function (/* args */) {
@@ -65,6 +66,7 @@ function ClassMiddleware (key, Model) {
6566
Model[method].apply(self, args);
6667
};
6768
};
69+
self[method].name = Model.name+'.'+Model[method].name;
6870
}
6971
}
7072

lib/middlewares/create-mongoose-middleware.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function getModelMiddlewareClass() {
4949
methods.forEach(function (method) {
5050
parentProto[method] = function (/*args*/) {
5151
var args = Array.prototype.slice.call(arguments);
52-
return function (req, res, next) {
52+
var mw = function (req, res, next) {
5353
var localArgs = utils.replacePlaceholders(req, args);
5454
var keyOverride = method === 'update' ? 'numberUpdated' : null;
5555
localArgs.push(self.dbCallback(req, next, keyOverride));
@@ -59,6 +59,8 @@ function getModelMiddlewareClass() {
5959
});
6060
req[self.key+'LastQuery'] = localArgs[0];
6161
};
62+
mw.name = Model.modelName+'.'+method;
63+
return mw;
6264
};
6365
parentProto[method].name = method;
6466
});
@@ -99,7 +101,7 @@ function getModelMiddlewareClass() {
99101
modelMethodNames.forEach(function (method) {
100102
self.model[method] = function (/*args*/) {
101103
var args = Array.prototype.slice.call(arguments);
102-
return function (req, res, next) {
104+
var mw = function (req, res, next) {
103105
var localArgs = utils.replacePlaceholders(req, args);
104106
var keyOverride = method === 'update' ? 'numberUpdated' : null;
105107
localArgs.push(self.dbCallback(req, next, keyOverride));
@@ -115,11 +117,12 @@ function getModelMiddlewareClass() {
115117
});
116118
req[self.key+'LastQuery'] = localArgs[0];
117119
};
120+
mw.name = self.Model.modelName+'.model.'+method;
121+
return mw;
118122
};
119-
self.model[method].name = method;
120123
self.models[method] = function (/*args*/) {
121124
var args = Array.prototype.slice.call(arguments);
122-
return function (req, res, next) {
125+
var mw = function (req, res, next) {
123126
var localArgs = utils.replacePlaceholders(req, args);
124127
var models = req[self.pluralKey];
125128
req.domain.run(function () {
@@ -130,8 +133,9 @@ function getModelMiddlewareClass() {
130133
});
131134
req.lastQuery = localArgs[0];
132135
};
136+
mw.name = self.Model.modelName+'.models.'+method;
137+
return mw;
133138
};
134-
self.models[method].name = method;
135139
});
136140
},
137141
setBoundProto: function () {
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
var mw = require('dat-middleware');
2+
var envIs = require('101/env-is');
23
var Boom = mw.Boom;
3-
var series = require('middleware-flow').series;
4+
var flow = require('middleware-flow');
45

5-
module.exports = series(
6-
mw.req('isInternalRequest').require()
7-
.else(Boom.forbidden('Internal use only'))
8-
);
6+
module.exports =
7+
flow.if(envIs('test')) // allow internal requests to be accessed externally in tests
8+
.else(
9+
mw.req('isInternalRequest').require()
10+
.else(Boom.forbidden('Internal use only'))
11+
);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
var path = require('path');
4+
var fs = require('fs');
5+
var inflect = require('i')();
6+
var createClassMiddleware = require('../create-class-middleware');
7+
8+
var apiMiddlewares = module.exports = {};
9+
10+
// this file automatically generates middlewares from the models/notifications folder
11+
// if they donot exist in the middlewares/notifications folder
12+
13+
14+
var notificationsMiddlewaresDir = path.resolve(__dirname);
15+
var middlewaresIncludes = [];
16+
17+
fs.readdirSync(notificationsMiddlewaresDir).forEach(function (filename) {
18+
if (!~middlewaresIncludes.indexOf(filename)) { return; }
19+
var lower = filename.replace(/\.js$/, '').toLowerCase();
20+
var middleware = require(path.join(notificationsMiddlewaresDir, filename));
21+
var camel = inflect.camelize(inflect.underscore(lower), false);
22+
apiMiddlewares[camel] = middleware;
23+
});
24+
25+
26+
var notificationsModelsDir = path.resolve(__dirname, '../../models/notifications/');
27+
var modelsIncludes = ['index.js'];
28+
29+
fs.readdirSync(notificationsModelsDir).forEach(function (filename) {
30+
if (!~modelsIncludes.indexOf(filename)) { return; }
31+
var lower = filename.replace(/\.js$/, '').toLowerCase();
32+
if (apiMiddlewares[lower]) { return; }
33+
34+
var Model = require(path.join(notificationsModelsDir, filename));
35+
var camel = inflect.camelize(inflect.underscore(lower), false);
36+
apiMiddlewares[camel] = createClassMiddleware(camel, Model);
37+
});

0 commit comments

Comments
 (0)