Skip to content

Commit 086585c

Browse files
committed
Merge pull request #16 from developmentseed/improvements
Making jekyll-hook compatible with Ubuntu 14.0
2 parents ea87493 + 54d4b6c commit 086585c

File tree

6 files changed

+134
-93
lines changed

6 files changed

+134
-93
lines changed

config.sample.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
22
"gh_server": "github.com",
33
"temp": "/home/ubuntu/jekyll-hook",
4+
"public_repo": true,
45
"scripts": {
56
"build": "./scripts/build.sh",
67
"publish": "./scripts/publish.sh"
78
},
89
"email": {
9-
"user": "",
10-
"password": "",
11-
"host": "",
10+
"isActivated": false,
11+
"user": "",
12+
"password": "",
13+
"host": "",
1214
"ssl": true
1315
},
1416
"accounts": [
15-
"developmentseed",
16-
"mapbox"
17+
"developmentseed"
1718
]
18-
}
19+
}

jekyll-hook.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ app.post('/hooks/jekyll/:branch', function(req, res) {
2020

2121
// Queue request handler
2222
tasks.defer(function(req, res, cb) {
23-
var data = JSON.parse(req.body.payload);
23+
var data = req.body;
2424
var branch = req.params.branch;
2525
var params = [];
2626

@@ -47,7 +47,14 @@ app.post('/hooks/jekyll/:branch', function(req, res) {
4747
/* repo */ params.push(data.repo);
4848
/* branch */ params.push(data.branch);
4949
/* owner */ params.push(data.owner);
50-
/* giturl */ params.push('git@' + config.gh_server + ':' + data.owner + '/' + data.repo + '.git');
50+
51+
/* giturl */
52+
if (config.public_repo) {
53+
params.push('https://' + config.gh_server + '/' + data.owner + '/' + data.repo + '.git');
54+
} else {
55+
params.push('git@' + config.gh_server + ':' + data.owner + '/' + data.repo + '.git');
56+
}
57+
5158
/* source */ params.push(config.temp + '/' + data.owner + '/' + data.repo + '/' + data.branch + '/' + 'code');
5259
/* build */ params.push(config.temp + '/' + data.owner + '/' + data.repo + '/' + data.branch + '/' + 'site');
5360

@@ -105,13 +112,15 @@ function run(file, params, cb) {
105112
}
106113

107114
function send(body, subject, data) {
108-
if (config.email && data.pusher.email) {
109-
var message = {
110-
text: body,
111-
from: config.email.user,
112-
to: data.pusher.email,
113-
subject: subject
114-
};
115-
mailer.send(message, function(err) { if (err) console.warn(err); });
115+
if (config.email.isActivated) {
116+
if (config.email && data.pusher.email) {
117+
var message = {
118+
text: body,
119+
from: config.email.user,
120+
to: data.pusher.email,
121+
subject: subject
122+
};
123+
mailer.send(message, function(err) { if (err) console.warn(err); });
124+
}
116125
}
117126
}

readme.md

+104-46
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,130 @@
11
# jekyll-hook
22

3-
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.
3+
A server that listens for webhook posts from GitHub, generates a website with
4+
Jekyll, and moves it somewhere to be published. Use this to run your own GitHub
5+
Pages-style web server. Great for when you need to serve your websites behind a
6+
firewall, need extra server-level features like HTTP basic auth (see below for an
7+
NGINX config with basic auth), or want to host your site directly on a CDN or
8+
file host like S3. It's cutomizable with two user-configurable shell scripts
9+
and a config file.
10+
11+
*This guide is tested on Ubuntu 14.0*
12+
13+
## Dependencies Installation
14+
15+
First install main dependencies
16+
17+
$: sudo apt-get update
18+
$: sudo apt-get install git nodejs ruby ruby1.9.1-dev npm
19+
20+
Symlink nodejs to node
21+
22+
$: sudo ln -s /usr/bin/nodejs /usr/bin/node
23+
24+
To keep server running we use Forever:
25+
26+
$: sudo npm install -g forever
27+
28+
We also need Jekyll and Nginx
29+
30+
$: sudo gem install jekyll rdiscount json
31+
$: sudo apt-get install nginx
432

533
## Installation
634

7-
- run `$ npm install` to install app dependencies
8-
- 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.
35+
Clone the repo
36+
37+
$: git clone https://github.com/developmentseed/jekyll-hook.git
38+
39+
Install dependencies:
940

41+
$: cd jekyll-hook
42+
jekyll-hook $: npm install
43+
44+
If you receive an error similar to this `npm ERR! Error: EACCES, mkdir
45+
'/home/ubuntu/tmp/npm-2223-4myn3niN'` run:
46+
47+
$: sudo chown -R ubuntu:ubuntu /home/ubuntu/tmp
48+
$: npm install
49+
50+
*You should replace `ubuntu` with your username*
1051

1152
## Configuration
1253

13-
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.
54+
Copy `config.sample.json` to `config.json` in the root directory and customize:
1455

15-
Copy `config.sample.json` to `config.json` in the root directory and customize.
56+
$: cp config.sample.json config.json
57+
$: vim config.json
1658

1759
Configuration attributes:
1860

19-
- `gh_server` The GitHub server from which to pull code
61+
- `gh_server` The GitHub server from which to pull code, e.g. github.com
2062
- `temp` A directory to store code and site files
63+
- `public-repo` Whether the repo is public or private (default is public)
2164
- `scripts`
2265
- `build` A script to run to build the site
2366
- `publish` A script to run to publish the site
2467
- `email` Optional. Settings for sending email alerts
68+
- `isActivated` If set to true email will be sent after each trigger
2569
- `user` Sending email account's user name (e.g. `[email protected]`)
2670
- `password` Sending email account's password
27-
- `host` SMTP host for sending email account (e.g. `smtp.gmail.com`)
71+
- `host` SMTP host for sending email account (e.g. `smtp.gmail.com`)
2872
- `ssl` `true` or `false` for SSL
29-
- `accounts` An array of accounts or organizations whose repositories can be used with this server
30-
## Usage
73+
- `accounts` An array of accounts or organizations whose repositories can be used
74+
with this server
75+
76+
You can also adjust `build.sh` and `publish.sh` to suit your workflow. By default,
77+
they generate a site with Jekyll and publish it to an NGINX web directory.
78+
79+
## Webhook Setup on Github
80+
81+
Set a [Web hook](https://developer.github.com/webhooks/) on your GitHub repository
82+
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.
83+
84+
## Configure a webserver (nginx)
85+
86+
The default `publish.sh` is setup for nginx and copies `_site` folder to `/usr/share/nginx/html/rep_name`.
87+
88+
If you would like to copy the website to another location, make sure to update
89+
nginx virtual hosts which is located at `/etc/nginx/nginx/site-available` on Ubuntu 14.
90+
91+
You also need to update `publish.sh`
92+
93+
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):
3194

32-
- run as executable: `$ ./jekyll-hook.js`
95+
## Launch
96+
97+
$: ./jekyll-hook.js
98+
99+
To launch in background run:
100+
101+
$: forever start jekyll-hook.js
102+
103+
To kill or restart the background job:
104+
105+
```
106+
$: forever list
107+
info: Forever processes running
108+
data: uid command script forever pid logfile uptime
109+
data: [0] ZQMF /usr/bin/nodejs jekyll-hook.js 4166 4168 /home/ubuntu/.forever/ZQMF.log 0:0:1:22.176
110+
$: forever stop 0
111+
```
33112

34113
## Publishing content
35114

115+
### S3
116+
117+
To publish the site on Amazon S3, you need to install S3cmd. On Ubuntu run:
118+
119+
$: sudo apt-get install s3cmd
120+
$: s3cmd --configure
121+
122+
For more information [read this](http://xmodulo.com/2013/06/how-to-access-amazon-s3-cloud-storage-from-command-line-in-linux.html).
123+
124+
`scripts/publish-s3.sh` does the rest of the job for you. Just make sure to add your bucket name there.
125+
126+
### More details on build.sh
127+
36128
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:
37129

38130
```
@@ -57,39 +149,5 @@ server {
57149

58150
Replace this script with whatever you need for your particular hosting environment.
59151

60-
You probably want to configure your server to only respond POST requests from GitHub's public IP addresses, found on the webhooks settings page.
61-
62-
## Dependencies
63-
64-
Here's a sample script to install the approriate dependencies on an Ubuntu server:
65-
66-
```sh
67-
#!/bin/sh
68-
69-
# Install node and depencencies
70-
sudo apt-get update -y
71-
sudo apt-get install python-software-properties python g++ make -y
72-
# On Ubuntu 12.10 and greater, add-apt-repository is provided by the software-properties-common package
73-
#sudo apt-get install software-properties-common -y
74-
sudo add-apt-repository ppa:chris-lea/node.js -y
75-
sudo apt-get update -y
76-
sudo apt-get install nodejs -y
77-
78-
# Forever to keep server running
79-
sudo npm install -g forever
80-
81-
# Git
82-
sudo apt-get install git -y
83-
84-
# Ruby
85-
sudo apt-get install ruby1.8 -y
86-
sudo apt-get install rubygems -y
87-
88-
# Jekyll
89-
sudo gem install jekyll --version "0.12.0"
90-
sudo gem install rdiscount -- version "1.6.8"
91-
sudo gem install json --version "1.6.1"
92-
93-
# Nginx for static content
94-
sudo apt-get install nginx -y
95-
```
152+
You probably want to configure your server to only respond POST requests from GitHub's
153+
public IP addresses, found on the webhooks settings page.

scripts/build-v1.sh

-29
This file was deleted.

scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ cd -
2525

2626
# Run jekyll
2727
cd $source
28-
jekyll $source $build --no-server --no-auto
28+
jekyll build -s $source -d $build
2929
cd -

scripts/publish.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ source=$5
1313
build=$6
1414

1515
# Set the path of the hosted site
16-
site="/usr/share/nginx/www/$repo"
16+
site="/usr/share/nginx/html/$repo"
1717

1818
# Remove old site files, move new ones in place
19+
# On amazon EC2 use sudo if nginx html forlder has root ownership
20+
1921
rm -rf $site
2022
mv $build $site

0 commit comments

Comments
 (0)