-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from A21z/2.0.0
Version 2.0.0
- Loading branch information
Showing
21 changed files
with
550 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": [ | ||
"standard" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,7 @@ results | |
|
||
node_modules | ||
npm-debug.log | ||
node-cd.sh | ||
node-cd.sh | ||
|
||
.idea/ | ||
.nvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- 0.6 | ||
- 0.8 | ||
- 0.10.30 | ||
script: "cd src && npm install" | ||
- 4.2.2 | ||
- 5.0.0 | ||
script: "npm test" | ||
sudo: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
node-cd | ||
======= | ||
|
||
**Featherweight Github/Bitbucket Continuous Deployment** | ||
**Featherweight Github/Bitbucket/Contentful Continuous Deployment** | ||
|
||
Continuously deploy any code from Github to your server. | ||
Continuously deploy any code from Github/Bitbucket/Contentful to your server. | ||
|
||
node-cd is a simple node.js app handling Github's and Bitbucket's post-receive hooks. | ||
It can execute any script you want on your server: deployment, testing, etc. | ||
node-cd is a simple node.js app handling Github's, Bitbucket's and Contentful's post-receive hooks. | ||
It can execute any script you want on your server: deployment, testing, etc. | ||
|
||
## Installation | ||
|
||
git clone https://github.com/A21z/node-cd.git | ||
cd node-cd/src | ||
npm install | ||
|
||
## Usage | ||
|
||
* `cp node-cd.template.sh node-cd.sh` | ||
* Edit the `node-cd.sh` file to execute whatever you like after your commits (ex: stop server, git pull, start server) | ||
* Edit the `bitbucket.sh`, `contentful.sh` or `github.sh` file to execute whatever you like after your commits (ex: stop server, git pull, start server) | ||
* **For GitHub**: Set your post-receive hook as described [here](https://help.github.com/articles/post-receive-hooks) with the url `http://yourserver.com:61440/github` | ||
* **For Bitbucket**: Set your post-receive hook as described [here](https://confluence.atlassian.com/display/BITBUCKET/POST+hook+management) with the url `http://yourserver.com:61440/bitbucket` | ||
* **For Contentful**: Set your webhook in your Settings > Webhooks with the url `http://yourserver.com:61440/contentful` | ||
* Add execution permission on scripts | ||
`chmod +x bitbucket.sh contentful.sh github.sh` | ||
* Run the app | ||
`WWW_PORT=61440 node node-cd.js` | ||
`WWW_PORT=61440 node src/index.js` | ||
|
||
[![Build Status](https://travis-ci.org/A21z/node-cd.svg)](https://travis-ci.org/A21z/node-cd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
echo "Updating Template" | ||
echo "=====================================" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,40 @@ | ||
Private = { | ||
server: {port: "61440"}, // Port is overriden by env var "WWW_PORT" | ||
security: { | ||
authorizedIps:[ | ||
'127.0.0.1', | ||
'localhost', | ||
// Bitbucket IPs | ||
// 131.103.20.165, | ||
// 131.103.20.166 | ||
// Github's IPs | ||
// '207.97.227.253', | ||
// '50.57.128.197', | ||
// '204.232.175.75', | ||
// '108.171.174.178' | ||
], | ||
bitbucketIps: [ | ||
'131.103.20.165', | ||
'131.103.20.166' | ||
], | ||
githubIps: [ | ||
'207.97.227.253', | ||
'50.57.128.197', | ||
'204.232.175.75', | ||
'108.171.174.178' | ||
], | ||
authorizedSubnet:[ | ||
'204.232.175.64/27', | ||
'192.30.252.0/22' | ||
] | ||
}, | ||
repository: { | ||
branch: 'refs/heads/master', | ||
}, | ||
action: {exec: "../node-cd.sh"} | ||
}; | ||
var Private = { | ||
server: {port: '61440'}, // Port is overriden by env var 'WWW_PORT' | ||
security: { | ||
authorizedIps: [ | ||
'127.0.0.1', | ||
'localhost' | ||
], | ||
bitbucketIps: [ | ||
'131.103.20.160', | ||
'131.103.20.27', | ||
'131.103.20.165', | ||
'165.254.145.0', | ||
'165.254.145.26', | ||
'104.192.143.0', | ||
'104.192.143.24' | ||
], | ||
githubIps: [ | ||
'207.97.227.253', | ||
'50.57.128.197', | ||
'204.232.175.75', | ||
'108.171.174.178' | ||
], | ||
githubAuthorizedSubnets: [ | ||
'204.232.175.64/27', | ||
'192.30.252.0/22' | ||
] | ||
}, | ||
repository: { | ||
branch: 'master' | ||
}, | ||
action: { | ||
exec: { | ||
github: './github.sh', | ||
bitbucket: './bitbucket.sh', | ||
contentful: './contentful.sh' | ||
} | ||
} | ||
} | ||
|
||
module.exports = Private; | ||
module.exports = Private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
echo "Updating Content" | ||
echo "=====================================" | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "node-cd", | ||
"version": "2.0.0-rc", | ||
"private": true, | ||
"scripts": { | ||
"start": "node src/index", | ||
"test": "standard && tape test/**/*.js" | ||
}, | ||
"dependencies": { | ||
"express": "4.13.3", | ||
"body-parser": "^1.6.3", | ||
"morgan": "^1.5.0", | ||
"netmask": "0.0.2", | ||
"underscore": "" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^1.10.1", | ||
"eslint-config-standard": "^4.4.0", | ||
"eslint-plugin-standard": "^1.3.1", | ||
"standard": "^3.0.0", | ||
"tape": "^4.2.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var express = require('express') | ||
var path = require('path') | ||
var http = require('http') | ||
var routes = require('./routes.js') | ||
var githubController = require('./routes/github.js') | ||
var bitbucketController = require('./routes/bitbucket.js') | ||
var contentfulController = require('./routes/contentful.js') | ||
var config = require('../config.js') | ||
var app = express() | ||
var morgan = require('morgan') | ||
var bodyParser = require('body-parser') | ||
|
||
app.set('port', process.env.WWW_PORT || config.server.port) | ||
app.use(morgan('combined')) | ||
app.use(bodyParser.json()) | ||
app.use(bodyParser.urlencoded({extended: true})) | ||
app.use(express.static(path.join(__dirname + 'public'))) | ||
|
||
app.get('/', routes.index.index) | ||
app.get('/favicon.ico', routes.index.favicon) | ||
app.post('/github', githubController.create(config).post) | ||
app.post('/bitbucket', bitbucketController.create(config).post) | ||
app.post('/contentful', contentfulController.create(config).post) | ||
|
||
http.createServer(app).listen(app.get('port'), function () { | ||
console.log('Node-cd server listening on port ' + app.get('port')) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
var fs = require('fs') | ||
var _ = require('underscore'); | ||
|
||
var controllers = [] | ||
|
||
var files = fs.readdirSync(__dirname + "/routes") | ||
for (var i = files.length - 1; i >= 0; i--){ | ||
if(files[i].match(/\.js$/i)) { | ||
controllers.push(files[i]); | ||
} | ||
var files = fs.readdirSync(__dirname + '/routes') | ||
for (var i = files.length - 1; i >= 0; i--) { | ||
if (files[i].match(/\.js$/i)) { | ||
controllers.push(files[i]) | ||
} | ||
} | ||
|
||
for (i = controllers.length - 1; i >= 0; i--) { | ||
var name = controllers[i].slice(0,controllers[i].lastIndexOf('.')) | ||
exports[name] = require("./routes/" + controllers[i]) | ||
var name = controllers[i].slice(0, controllers[i].lastIndexOf('.')) | ||
exports[name] = require('./routes/' + controllers[i]) | ||
} | ||
|
||
var that = this; | ||
var that = this | ||
|
||
exports.__allRoutes = function(req, res){ | ||
res.json(that); | ||
}; | ||
exports.__allRoutes = function (req, res) { | ||
res.json(that) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var config | ||
|
||
function Bitbucket (conf) { | ||
config = conf | ||
} | ||
|
||
function create (conf) { | ||
return new Bitbucket(conf) | ||
} | ||
|
||
module.exports.create = create | ||
|
||
Bitbucket.prototype.post = function (req, res) { | ||
var authorizedIps = config.security.authorizedIps | ||
var bitbucketIps = config.security.bitbucketIps | ||
var commits = req.body.push.changes | ||
var ipv4 = req.ip.replace('::ffff:', '') | ||
|
||
if (!(authorizedIps.indexOf(ipv4) >= 0 || bitbucketIps.indexOf(ipv4) >= 0)) { | ||
console.log('Unauthorized IP:', req.ip) | ||
res.writeHead(403) | ||
res.end() | ||
return | ||
} | ||
|
||
if (commits.length <= 0) { | ||
res.writeHead(204) | ||
res.end() | ||
return | ||
} | ||
|
||
var commitsFromBranch = commits.filter(function (commit) { | ||
return commit.new.name === config.repository.branch || | ||
commit.new.name === 'refs/heads/master' || | ||
commit.new.name === 'refs/heads/develop' | ||
}) | ||
|
||
if (commitsFromBranch.length > 0) { | ||
console.log('Executing bash file...') | ||
myExec(config.action.exec.bitbucket) | ||
} | ||
|
||
res.writeHead(200) | ||
res.end() | ||
} | ||
|
||
var myExec = function (line) { | ||
var exec = require('child_process').exec | ||
var execCallback = function (error) { | ||
if (error !== null) { | ||
console.log('exec error: ' + error) | ||
} | ||
} | ||
exec(line, execCallback) | ||
} |
Oops, something went wrong.