summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.sample.json13
-rwxr-xr-xjekyll-hook.js31
-rw-r--r--package.json5
-rw-r--r--readme.md150
-rwxr-xr-xscripts/build-v1.sh29
-rwxr-xr-xscripts/build.sh2
-rwxr-xr-xscripts/publish.sh4
7 files changed, 138 insertions, 96 deletions
diff --git a/config.sample.json b/config.sample.json
index 40fba54..eba0920 100644
--- a/config.sample.json
+++ b/config.sample.json
@@ -1,19 +1,20 @@
{
"gh_server": "github.com",
"temp": "/home/ubuntu/jekyll-hook",
+ "public_repo": true,
"scripts": {
"build": "./scripts/build.sh",
"publish": "./scripts/publish.sh"
},
"secret": "",
"email": {
- "user": "",
- "password": "",
- "host": "",
+ "isActivated": false,
+ "user": "",
+ "password": "",
+ "host": "",
"ssl": true
},
"accounts": [
- "developmentseed",
- "mapbox"
+ "developmentseed"
]
-} \ No newline at end of file
+}
diff --git a/jekyll-hook.js b/jekyll-hook.js
index dcc1410..72785c7 100755
--- a/jekyll-hook.js
+++ b/jekyll-hook.js
@@ -44,7 +44,7 @@ app.post('/hooks/jekyll/:branch', function(req, res) {
// Queue request handler
tasks.defer(function(req, res, cb) {
- var data = JSON.parse(req.body.payload);
+ var data = req.body;
var branch = req.params.branch;
var params = [];
@@ -71,7 +71,14 @@ app.post('/hooks/jekyll/:branch', function(req, res) {
/* repo */ params.push(data.repo);
/* branch */ params.push(data.branch);
/* owner */ params.push(data.owner);
- /* giturl */ params.push('git@' + config.gh_server + ':' + data.owner + '/' + data.repo + '.git');
+
+ /* giturl */
+ if (config.public_repo) {
+ params.push('https://' + config.gh_server + '/' + data.owner + '/' + data.repo + '.git');
+ } else {
+ params.push('git@' + config.gh_server + ':' + data.owner + '/' + data.repo + '.git');
+ }
+
/* source */ params.push(config.temp + '/' + data.owner + '/' + data.repo + '/' + data.branch + '/' + 'code');
/* build */ params.push(config.temp + '/' + data.owner + '/' + data.repo + '/' + data.branch + '/' + 'site');
@@ -97,7 +104,7 @@ app.post('/hooks/jekyll/:branch', function(req, res) {
// Done running scripts
console.log('Successfully rendered: ' + data.owner + '/' + data.repo);
- send('Your website at ' + data.owner + '/' + data.repo + ' was succesfully published.', 'Succesfully published site', data);
+ send('Your website at ' + data.owner + '/' + data.repo + ' was successfully published.', 'Successfully published site', data);
if (typeof cb === 'function') cb();
return;
@@ -129,13 +136,15 @@ function run(file, params, cb) {
}
function send(body, subject, data) {
- if (config.email && data.pusher.email) {
- var message = {
- text: body,
- from: config.email.user,
- to: data.pusher.email,
- subject: subject
- };
- mailer.send(message, function(err) { if (err) console.warn(err); });
+ if (config.email.isActivated) {
+ if (config.email && data.pusher.email) {
+ var message = {
+ text: body,
+ from: config.email.user,
+ to: data.pusher.email,
+ subject: subject
+ };
+ mailer.send(message, function(err) { if (err) console.warn(err); });
+ }
}
}
diff --git a/package.json b/package.json
index f2cd59d..80d0877 100644
--- a/package.json
+++ b/package.json
@@ -8,13 +8,14 @@
"email": "info@developmentseed.org"
},
"contributors": [
- "Dave Cole <dave@developmentseed.org>"
+ "Dave Cole <dave@developmentseed.org>",
+ "Alireza J <alireza@developmentseed.org>"
],
"repository": {
"type": "git",
"url": "git://github.com/developmentseed/jekyll-hook.git"
},
- "version": "0.1.0",
+ "version": "0.2.0",
"dependencies": {
"express": "3.x",
"emailjs": "0.3.4",
diff --git a/readme.md b/readme.md
index 948f474..44d91e9 100644
--- a/readme.md
+++ b/readme.md
@@ -1,38 +1,130 @@
# jekyll-hook
-A server that listens for webhook posts from GitHub, generates a website with Jekyll, and moves it somewhere to be published. Use this to run your own GitHub Pages-style web server. Great for when you need to serve your websites behind a firewall, need extra server-level features like HTTP basic auth (see below for an NGINX config with basic auth), or want to host your site directly on a CDN or file host like S3. It's cutomizable with two user-configurable shell scripts and a config file.
+A server that listens for webhook posts from GitHub, generates a website with
+Jekyll, and moves it somewhere to be published. Use this to run your own GitHub
+Pages-style web server. Great for when you need to serve your websites behind a
+firewall, need extra server-level features like HTTP basic auth (see below for an
+NGINX config with basic auth), or want to host your site directly on a CDN or
+file host like S3. It's cutomizable with two user-configurable shell scripts
+and a config file.
+
+*This guide is tested on Ubuntu 14.0*
+
+## Dependencies Installation
+
+First install main dependencies
+
+ $: sudo apt-get update
+ $: sudo apt-get install git nodejs ruby ruby1.9.1-dev npm
+
+Symlink nodejs to node
+
+ $: sudo ln -s /usr/bin/nodejs /usr/bin/node
+
+To keep server running we use Forever:
+
+ $: sudo npm install -g forever
+
+We also need Jekyll and Nginx
+
+ $: sudo gem install jekyll rdiscount json
+ $: sudo apt-get install nginx
## Installation
-- run `$ npm install` to install app dependencies
-- Set a [Web hook]() on your GitHub repository that points to your jekyll-hook server `http://example.com:8080/hooks/jekyll/:branch`, where `:branch` is the branch you want to publish. Usually this is `gh-pages` or `master` for `*.github.com` / `*.github.io` repositories.
+Clone the repo
+
+ $: git clone https://github.com/developmentseed/jekyll-hook.git
+
+Install dependencies:
+ $: cd jekyll-hook
+ jekyll-hook $: npm install
+
+If you receive an error similar to this `npm ERR! Error: EACCES, mkdir
+'/home/ubuntu/tmp/npm-2223-4myn3niN'` run:
+
+ $: sudo chown -R ubuntu:ubuntu /home/ubuntu/tmp
+ $: npm install
+
+*You should replace `ubuntu` with your username*
## Configuration
-Adjust `build.sh` and `publish.sh` to suit your workflow. By default, they generate a site with Jekyll and publish it to an NGINX web directory.
+Copy `config.sample.json` to `config.json` in the root directory and customize:
-Copy `config.sample.json` to `config.json` in the root directory and customize.
+ $: cp config.sample.json config.json
+ $: vim config.json
Configuration attributes:
-- `gh_server` The GitHub server from which to pull code
+- `gh_server` The GitHub server from which to pull code, e.g. github.com
- `temp` A directory to store code and site files
+- `public-repo` Whether the repo is public or private (default is public)
- `scripts`
- `build` A script to run to build the site
- `publish` A script to run to publish the site
- `email` Optional. Settings for sending email alerts
+ - `isActivated` If set to true email will be sent after each trigger
- `user` Sending email account's user name (e.g. `example@gmail.com`)
- `password` Sending email account's password
- - `host` SMTP host for sending email account (e.g. `smtp.gmail.com`)
+ - `host` SMTP host for sending email account (e.g. `smtp.gmail.com`)
- `ssl` `true` or `false` for SSL
-- `accounts` An array of accounts or organizations whose repositories can be used with this server
-## Usage
+- `accounts` An array of accounts or organizations whose repositories can be used
+with this server
+
+You can also adjust `build.sh` and `publish.sh` to suit your workflow. By default,
+they generate a site with Jekyll and publish it to an NGINX web directory.
+
+## Webhook Setup on Github
+
+Set a [Web hook](https://developer.github.com/webhooks/) on your GitHub repository
+that points to your jekyll-hook server `http://example.com:8080/hooks/jekyll/:branch`, where `:branch` is the branch you want to publish. Usually this is `gh-pages` or `master` for `*.github.com` / `*.github.io` repositories.
+
+## Configure a webserver (nginx)
+
+The default `publish.sh` is setup for nginx and copies `_site` folder to `/usr/share/nginx/html/rep_name`.
+
+If you would like to copy the website to another location, make sure to update
+nginx virtual hosts which is located at `/etc/nginx/nginx/site-available` on Ubuntu 14.
+
+You also need to update `publish.sh`
+
+For more information Google or [read this](https://www.digitalocean.com/community/tutorials/how-to-configure-the-nginx-web-server-on-a-virtual-private-server):
-- run as executable: `$ ./jekyll-hook.js`
+## Launch
+
+ $: ./jekyll-hook.js
+
+To launch in background run:
+
+ $: forever start jekyll-hook.js
+
+To kill or restart the background job:
+
+```
+ $: forever list
+ info: Forever processes running
+ data: uid command script forever pid logfile uptime
+ data: [0] ZQMF /usr/bin/nodejs jekyll-hook.js 4166 4168 /home/ubuntu/.forever/ZQMF.log 0:0:1:22.176
+ $: forever stop 0
+```
## Publishing content
+### S3
+
+To publish the site on Amazon S3, you need to install S3cmd. On Ubuntu run:
+
+ $: sudo apt-get install s3cmd
+ $: s3cmd --configure
+
+For more information [read this](http://xmodulo.com/2013/06/how-to-access-amazon-s3-cloud-storage-from-command-line-in-linux.html).
+
+`scripts/publish-s3.sh` does the rest of the job for you. Just make sure to add your bucket name there.
+
+### More details on build.sh
+
The stock `build.sh` copies rendered site files to subdirectories under a web server's `www` root directory. For instance, use this script and NGINX with the following configuration file to serve static content behind HTTP basic authentication:
```
@@ -57,39 +149,5 @@ server {
Replace this script with whatever you need for your particular hosting environment.
-You probably want to configure your server to only respond POST requests from GitHub's public IP addresses, found on the webhooks settings page.
-
-## Dependencies
-
-Here's a sample script to install the approriate dependencies on an Ubuntu server:
-
-```sh
-#!/bin/sh
-
-# Install node and depencencies
-sudo apt-get update -y
-sudo apt-get install python-software-properties python g++ make -y
-# On Ubuntu 12.10 and greater, add-apt-repository is provided by the software-properties-common package
-#sudo apt-get install software-properties-common -y
-sudo add-apt-repository ppa:chris-lea/node.js -y
-sudo apt-get update -y
-sudo apt-get install nodejs -y
-
-# Forever to keep server running
-sudo npm install -g forever
-
-# Git
-sudo apt-get install git -y
-
-# Ruby
-sudo apt-get install ruby1.8 -y
-sudo apt-get install rubygems -y
-
-# Jekyll
-sudo gem install jekyll --version "0.12.0"
-sudo gem install rdiscount -- version "1.6.8"
-sudo gem install json --version "1.6.1"
-
-# Nginx for static content
-sudo apt-get install nginx -y
-```
+You probably want to configure your server to only respond POST requests from GitHub's
+public IP addresses, found on the webhooks settings page.
diff --git a/scripts/build-v1.sh b/scripts/build-v1.sh
deleted file mode 100755
index 0e85e39..0000000
--- a/scripts/build-v1.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-set -e
-
-# This script is meant to be run automatically
-# as part of the jekyll-hook application.
-# https://github.com/developmentseed/jekyll-hook
-
-repo=$1
-branch=$2
-owner=$3
-giturl=$4
-source=$5
-build=$6
-
-# Check to see if repo exists. If not, git clone it
-if [ ! -d $source ]; then
- git clone $giturl $source
-fi
-
-# Git checkout appropriate branch, pull latest code
-cd $source
-git checkout $branch
-git pull origin $branch
-cd -
-
-# Run jekyll
-cd $source
-jekyll build --source $source --destination $build
-cd -
diff --git a/scripts/build.sh b/scripts/build.sh
index 4d689db..9eb4fe2 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -25,5 +25,5 @@ cd -
# Run jekyll
cd $source
-jekyll $source $build --no-server --no-auto
+jekyll build -s $source -d $build
cd -
diff --git a/scripts/publish.sh b/scripts/publish.sh
index 82e728b..38b2143 100755
--- a/scripts/publish.sh
+++ b/scripts/publish.sh
@@ -13,8 +13,10 @@ source=$5
build=$6
# Set the path of the hosted site
-site="/usr/share/nginx/www/$repo"
+site="/usr/share/nginx/html/$repo"
# Remove old site files, move new ones in place
+# On amazon EC2 use sudo if nginx html forlder has root ownership
+
rm -rf $site
mv $build $site