This project uses NodeJS to listen to Github Push Events.
Each time something is pushed on bblfr_data, this NodeJS application:
- fetch https://github.com/brownbaglunch/bblfr_data/blob/gh-pages/baggers.js
- split
data
inbaggers
andcities
- enrich
baggers.cities
with geo location point and image of the associated city - index
baggers
andcities
in elasticsearch. The index name is timestamped. - move or create alias
bblfr
on the index name - remove the old index
Data are available in elasticsearch:
To run it, you need to have Node JS installed.
git clone https://github.com/brownbaglunch/webhook.git
cd webhook
npm install
node app.js
It should says:
Brownbaglunch webhook app listening at http://:::5000
elasticsearch cluster is running!
Then just POST to http://localhost:5000:
curl -XPOST localhost:5000
If you want to push to another cluster, you need to create a local .env
file as follow:
SOURCE=https://raw.githubusercontent.com/brownbaglunch/bblfr_data/gh-pages/baggers.js
TARGET=https://username:password@yourcluster.found.io:9243/
ALIAS=bblfr
TOKEN=hhdquiHdsuqiudshqhiudhuebefbbcbzbczib
PORT=5000
TOKEN
value is the one you defined in Github Hooks.
It can be null
(default) in development mode.
If you want to change network settings, change PORT
system variables or change it in .env
file:
PORT=9000 node app.js
By default, it will listen on 0.0.0.0
, port 5000
.
NodeMon is recommended when you want to code:
npm install nodemon -g
To monitor and restart your application automatically, run:
nodemon app.js
Connect to your Clever-cloud console. Create your NodeJS application and define your variables:
SOURCE=https://raw.githubusercontent.com/brownbaglunch/bblfr_data/gh-pages/baggers.js
TARGET=http://bblfr:password@localhost:9200
ALIAS=bblfr
TOKEN=12345678
PORT=8080
Note that PORT
must be 8080
.
Add clever as a git remote repository (change ID
below):
git remote add clever git+ssh://git@push.par.clever-cloud.com/app_ID.git
Deploy!
git push -u clever master
Et voilà!
You need to use the Heroku CLI:
brew install heroku
Log in to Heroku:
heroku login
To deploy on Heroku, create the Heroku application. It will basically create an Heroku application and add an "heroku" remote to your local git repository:
heroku create brownbaglunch-webhook
To deploy, run:
git add .
git push heroku master
Make sure you define needed system properties:
heroku config:set SOURCE=https://raw.githubusercontent.com/brownbaglunch/bblfr_data/gh-pages/baggers.js
heroku config:set TARGET=http://bblfr:password@localhost:9200
heroku config:set ALIAS=bblfr
heroku config:set TOKEN=12345678
heroku config:set PORT=5000
When running in production, you can use forever to run it as a service.
sudo npm -g install forever
sudo npm install -g forever-service
git clone https://github.com/brownbaglunch/webhook.git
cd webhook
npm install
# This will install webhook as a service
sudo forever-service install -e "PORT=5000" webhook
And start it:
sudo service webhook start
Or stop it:
sudo service webhook stop
To check if it's running:
sudo service webhook status
You can also check logs:
tail -f /var/log/webhook.log